Skip to main content

MQTTCLIENT

This driver acts as an MQTT client (publisher/subscriber) for Hsyco, it fully supports MQTT version 3.1.1.

HSYCO Configuration

Add the MQTTCLIENT I/O Server in the I/O Servers section of the Settings and set its parameters:

Communication

  • IP Address: host name or IP address of the MQTT broker
  • IP Port: TCP/IP port of the MQTT broker

Authentication

  • User: username for authentication with MQTT broker
  • Password: password for authentication with MQTT broker

Options

IDDefaultValuesDescription
startupeventsfalsetruegenerate IO events also during the driver’s start-up phase
falsestart generating events only after HSYCO is aligned with the current status of the system
cleansessionfalsetruecleans eventually existing previous session held by the MQTT broker. This will remove any previous subscription and unacknowledged messages
falserestores eventually existing previous session held by the MQTT broker. This will restore all existing subscriptions and resend any unacknowledged message
messageretainfalsetruewith this option true the MQTT broker will save publish messages for future subscribers
falsewith this option false the MQTT broker will not save publish messages for future subscribers
keepalive60n >= 0this value, measured in seconds, defines the maximum time interval between messages sent or received. It enables this driver to detect if the MQTT broker is no longer available. In the absence of a data-related message during this time period, the client sends a very small "ping" message, which the server will acknowledge. A value of 0 disables keepalive processing in the client.
connecttimeout30n >= 0this value, measured in seconds, defines the maximum time interval this driver will wait for the network connection to the MQTT broker to be established. A value of 0 disables timeout processing meaning the driver will wait until the network connection is made successfully or fails.
messageqos00every publish message is sent at most one time, so it doesn't receive acknowledge message from the MQTT broker
1every publish message is sent at least one time, so it waits acknowledge message from the MQTT broker
2every publish message is sent exactly one time, so there will be a series of acknowledge messages between the MQTT client and broker

Subscriptions file

Under the hsyco root directory there could be a file named "mqttsubscriptions-<IOServerId>.ini" (e.g "mqttsubscriptions-myclientid.ini") which can contain a series of line, each line represents a topic to subscribe and the topic's quality-of-service (qos). On each line topic and relative qos are separated by a white space:

E.g.

/mqtt/test 2

home/bathroom 1

/outdoor 0

Datapoints

IDValueR/WDescription
connectiononlineRthe client is connected to the MQTT broker
offlineRinitialization of the driver failed or loop cycle failed
received.<topicName><message>Rthe client received a message on topicName
publish.<topicName><message>R/Wthe client published a message on topicName
subscribe.<topicName>0R/Wthe client subscribes to topicName with qos=0
1R/Wthe client subscribes to topicName with qos=1
2R/Wthe client subscribes to topicName with qos=2
unsubscribeR/Wthe client unsubscribes from topicName

<topicName> field is case insensitive and will be reported in lower case, furthermore the MQTT client will replace every whitespace present in the topic name with '_'. E.g. if this driver publishes a message or subscribes to "Topic Test", the MQTT client will convert this value in "topic_test" and this change will be reflected in <topicName> field present in datapoints

note

All the subscriptions and unsubscriptions made at run-time are not persistent so they will be lost in case of driver restart.

All publish messages with QoS > 0 are temporarily stored in the directory "qos2store" waiting for the acknowledge by the MQTT broker. Once they are acknowledged they are deleted.

Release Notes

3.8.0

  • improved UTF-8 characters support

3.7.0

  • initial release