You can publish to your MQTT topics by coding a script that will run from an Analysis. When the analysis runs, your script can publish a topic that can be received by any device that has subscribed to that specific topic. There are different ways to start an analysis; it may be by timer, an Action, or called by another analysis. The figure below shows the data flow from the analysis to the MQTT network.
This section describes how to Publish and Subscribe to a topic in the MQTT Broker. We are assuming that you already know how to connect to MQTT; if you do not, please read our article MQTT on how this is done.
You can create an Action and attach it to any specific topic or wildcard topics, and take actions from there.
You can send the payload directly to your bucket, to trigger an Analysis, or through SMS or E-mail.
If you are sending a payload in a JSON format, the TagoIO backend will add a new field called metadata with a child field called topic. However, if you are sending a raw payload, you must transform your format into the TagoIO JSON format with a variable called payload and your raw data as value. This will also add a metadata with a topic name (identically to what would happen with a payload already in a JSON format).
QoS and Retained Message SupportThe Quality of Service (QoS) level is an agreement between the sender of a message and the receiver of a message. It defines the guarantee of delivery for a specific message
TagoIO officially supports QoS 0 and 1.
TagoIO also supports retained messages.
Legacy Support
Before version 5.7.0 of TagoIO Core, we had reserved topics, tago/data/post and tago/analysis/:analysisID, those topics have since been deprecated, but they will still work for couple more years. If you use those topics, we recommend that you change to a mechanism using Action MQTT Topic. TagoIO will send an email for clients still using those topics three months priors to their deletion.
You can similarly create them (topic tago/data/post) on MQTT Trigger, and it will work just as it had before.
You can see all your connections directly on the Live Inspector, and you are able to check any connection, payload, QOS, Last Will messages, and more.
The messages are triggered with the following actions.
The single level is represented by the +
sign, which is then added to the topic.
Example:
If the client subscribes to the topic home/+/temperature
, the following topics will match:
home/kitchen/temperature
home/office/temperature
home/livingroom/temperature
This means that if any client publishes data to these topics above, the subscribed client will receive it.
The following topics WILL NOT match:
home/kitchen
home/kitchen/humidity
home/office/ac/temperature
The multi level is represented by the #
sign. By adding a #
sign to the topic, the client will subscribe to all the following levels of that topic.
Example:
If the client subscribes to the topic home/#
, the following topics will match:
home/kitchen
home/kitchen/temperature
home/office/ac/temperature
home/upstairs/bedroom/ac/temperature