AWSIoTClient (FB)¶
FUNCTION_BLOCK AWSIoTClient
Function block to connect to the AWS IoT Core Service.
- InOut:
- Scope - Name - Type - Initial - Comment - Input - xEnable- BOOL- TRUE: Opens a connection, FALSE: Close connection - uiKeepAlive- UINT- 30 - Keep alive interval in seconds (default: 30s) - sClientId- STRING(255)- The clientId (Name of the thing in AWS IoT Core) - sHostname- STRING(1024)- API Endpoint (e.g. xxxxxxyyyyyyy.iot.eu- central-1.amazonaws.com) - uiPort- UINT- 8883 - MQTT port (default: 8883) - wsWillTopic- WSTRING(1024)- “” - Last will topic (optional) - pbWillMessage- POINTER TO BYTE - 0 - Pointer to the ‘Last Will’ message (optional) - uiWillMessageSize- UINT- 0 - Size of ‘Last Will’ message (optional) - eLastWillQoS- Quality of Service of the last will message - 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) - sCertCNPrefix- STRING- ‘’ - 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 - xCleanSession- BOOL- TRUE - TRUE: Creates a new session, FALSE: Uses already existing session if available - eMQTTVersion- MQTT_VERSION.V3_1_1 - MQTT protocol version, default: 3.1.1 - mQTTConnectProperties- REFERENCE TO MQTTConnectProperties - Connection properties for MQTT V5 - mQTTWillProperties- REFERENCE TO MQTTWillProperties - Will properties for MQTT V5 - 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 MQTT Broker Server, otherwise TRUE - eReaonCode- Reason code of the last operation (MQTT V5 only) - mQTTConnackProperties- Connection response properties (MQTT V5 only)