AWSIoTClient (FB)¶
FUNCTION_BLOCK AWSIoTClient
Function block to connect to the AWS IoT Core Service.
- InOut:
Scope
Name
Type
Initial
Comment
Input
xEnableBOOLTRUE: Opens a connection, FALSE: Close connection
uiKeepAliveUINT30
Keep alive interval in seconds (default: 30s)
sClientIdSTRING(255)The clientId (Name of the thing in AWS IoT Core)
sHostnameSTRING(1024)API Endpoint (e.g. xxxxxxyyyyyyy.iot.eu- central-1.amazonaws.com)
uiPortUINT8883
MQTT port (default: 8883)
wsWillTopicWSTRING(1024)„“
Last will topic (optional)
pbWillMessagePOINTER TO BYTE
0
Pointer to the ‚Last Will‘ message (optional)
uiWillMessageSizeUINT0
Size of ‚Last Will‘ message (optional)
eLastWillQoSQuality of Service of the last will message
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)
sCertCNPrefixSTRING‚‘
Prefix for the Common Name (CN) of the certificate.
The prefix should be used if the ClientId is identical to the host name. This prevents loading of a wrong certificate (e.g. from the WebServer).
Example: sCertCNPr := ‚AWSClient‘, sClientId := ‚MyHostname‘
=> The Common Name (CN) of the certificate will be AWSClient@MyHostname
xCleanSessionBOOLTRUE
TRUE: Creates a new session, FALSE: Uses already existing session if available
eMQTTVersionMQTT_VERSION.V3_1_1
MQTT protocol version, default: 3.1.1
mQTTConnectPropertiesREFERENCE TO MQTTConnectProperties
Connection properties for MQTT V5
mQTTWillPropertiesREFERENCE TO MQTTWillProperties
Will properties for MQTT V5
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 MQTT Broker Server, otherwise TRUE
eReaonCodeReason code of the last operation (MQTT V5 only)
mQTTConnackPropertiesConnection response properties (MQTT V5 only)