AzureMQTTClient (FB)¶
FUNCTION_BLOCK AzureMQTTClient
Function block to connect to Azure IoT Hub via MQTT.
- InOut:
Scope
Name
Type
Initial
Comment
Input
xEnableBOOLTRUE: Opens a connection, FALSE: Close connection
uiKeepAliveUINT10
Keep alive interval in seconds (default: 10s)
tPingIntervalTIMETIME#2s0ms
Ping interval (default: 2s)
udiTimeOutUDINT0
Defines the time (µs) after which the connection setup aborts with xError.
tReconnectTimeTIMETIME#0ms
Time for an automatically reconnection, default is T#0s and reconnection is not acitve.
sHubDomainNameSTRING(255)Domain name of the IoT Hub
sDeviceIdSTRING(255)Device ID
wsSaSWSTRING(255)Shared Access Signature (SAS Token)
pbWillMessagePOINTER TO BYTE
0
Pointer to the ‚Last Will‘ message (optional)
uiWillMessageSizeUINT0
Size of ‚Last Will‘ message (optional)
itfTLSContextNBS.ITLSContext0
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
itfAsyncPropertyNBS.IAsyncProperty0
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)
eCommunicationModeCOMMUNICATION_MODE.TCP
Communication mode: TCP or WEB_SOCKET, default: TCP
httpProxySettingsREFERENCE TO HttpProxySettings
Optional http proxy settings. Only relevant for COMMUNICATION_MODE.WEB_SOCKET.
Output
xErrorBOOLTRUE, if an error occurred
xBusyBOOLTRUE, while the function block is active
eErrorMQTT.MQTT_ERRORThe error id
xConnectedToBrokerBOOLFALSE
FALSE when there is no connection to Azure IoT Hub, otherwise TRUE