|MQTT_CONNECT URL_string, Cust_Fn
|| (only available on Wx PLC firmware >= F94.2)
||Connect to the MQTT Broker and define the callback custom function name/number.
MQTT_CONNECT "192.168.1.123:1883", 10
URL_string can be either the domain name or the IP address of the MQTT broker.
Note: if you use SSL, then the domain name is also the common name contained in the CA cert. If the broker does not
have a domain name and only has an IP address then you should not enable broker's common name verify
(see MQTT_CONFIG 10,"0") or else it may fail the verification of the CA cert.
- Use the MQTT_STATUS() function to check
if the connection is sucessful and to check if the PLC is still connected to the MQTT broker.
MQTT_STATUS(1) will return a '1' indicating that the operation is successful.
MQTT_STATUS(2) will return a '1' when the PLC is connected to the broker.
- The callback Cust_Fn
is the interrupt service routine that the operating system will invoke when a new MQTT
message arrives. The callback Cust_Fn can then identify the topic and process the data using the
MQTT_TOPIC() and MQTT_DATA() functions.
- This command can be used for both non-encrypted and encrypted (SSL) connection
to the MQTT broker. By default the MQTT broker listens on port #1883 for non-encrypted connection and on port
#8883 for encrypted connection. If SSL connection is used then you must define the CA cert filename using
the command: MQTT_CONFIG 9, "ca_cert_filename". The PLC will check and if CA cert filename is
an empty string it defaults to non-SSL connection, otherwise it will attempt to connect using SSL encryption
- SSL connection (default port #8883) with both server and client certificates verification takes the longest (up to several seconds)
to complete the connection due to the need to exchange certificates, encrypt and decrypt messages during
the connection negotiation.
- SSL connection with only server side verification takes slightly shorter time to complete the connection.
But non-SSL communication (default port # 1883) is both the fastest and much less complicated to get a successful
connection. Hence, If your MQTT broker and PLCs are all residing on a private local area network it may be
unnecessary to enable SSL encryption
- By default, the PLC will connect to the MQTT broker using a "clean session" -
what it means is that each time the PLC connects to the broker it is treated as a new connection and none of
its previous connection preferences (such as subscribed topics, LWT messages etc) are remember. You can change
the connection session to "persistent" by running the MQTT_CONFIG 1,"1" command before
the PLC connects to the broker and the broker will remember the session even after the PLC disconnects and then
reconnects to the broker.
- i-TRiLOGI 7.5 simulator is now able to actually connect to a MQTT broker like
the real PLC. So you can fully test the MQTT operation using just the simulator without the need to transfer the
program to the PLC first.
Basic to TBASIC Reference Manual