AzureMQTTClient (FB)¶
FUNCTION_BLOCK AzureMQTTClient
Function block to connect to Azure IoT Hub via MQTT.
- InOut:
- Scope - Name - Type - Initial - Comment - Input - xEnable- BOOL- TRUE: Opens a connection, FALSE: Close connection - uiKeepAlive- UINT- 10 - Keep alive interval in seconds (default: 10s) - tPingInterval- TIME- TIME#2s0ms - Ping interval (default: 2s) - udiTimeOut- UDINT- 0 - Defines the time (µs) after which the connection setup aborts with xError. - tReconnectTime- TIME- TIME#0ms - Time for an automatically reconnection, default is T#0s and reconnection is not acitve. - sHubDomainName- STRING(255)- Domain name of the IoT Hub - sDeviceId- STRING(255)- Device ID - wsSaS- WSTRING(255)- Shared Access Signature (SAS Token) - pbWillMessage- POINTER TO BYTE - 0 - Pointer to the ‚Last Will‘ message (optional) - uiWillMessageSize- UINT- 0 - Size of ‚Last Will‘ message (optional) - itfTLSContext- NBS.ITLSContext- 0 - Encapsulates all the data neccecray to handle encrypted tcp connections - Static initialization, as shown in the following code snippet. - VAR commonName : STRING := 'MyRrasPi'; ciCertInfo : NBS.CERT_INFO := (psInfo:=ADR(commonName), udiSize:=LEN(commonName)); myTLSContext : NBS.TLSContext := ( ePurpose:=NBS.PURPOSE.CLIENT_SIDE, sUseCaseName:='NBSTest', sTLSVersion:='1.3', ciCertInfo:=ciCertInfo, udiVerificationMode:=2 ); END_VAR - itfAsyncProperty- NBS.IAsyncProperty- 0 - Runs the connect process in a own background task. Use this property if the connection setup takes longer than one task cycle (e.g. TLS connections) - Output - xError- BOOL- TRUE, if an error occurred - xBusy- BOOL- TRUE, while the function block is active - eError- MQTT.MQTT_ERROR- The error id - xConnectedToBroker- BOOL- FALSE - FALSE when there is no connection to Azure IoT Hub, otherwise TRUE 
