What would be the MQTT protocol?

how it works

The protocol MQTT(MQ Telemetry Transport) is a focused protocol for communicating machine-to-machine (M2M) and Internet of Things(IoT), with a focus on being a light, simple protocol. It is designed to be a protocol that lets you work with messaging, therefore, allows to work with the publish and subscribe (receiving) the messages. The main focus of the Protocol is to allow you can send data, for example, with satellite link or dial-up connection, another point is the low power consumption and the size of the packet sent.

The MQTT uses port 1883, protocol TCP.

Among the positive points you can perform data collection, and add other devices to "listen" to such information, and perform some sort of decision-making.

To create a constraint model the list (signature and publication), it is necessary to pass some values based on the design follows a standard table with the information to be obtained from the project:

Parameter Value
User The same project creator login.
Password The Api project Key number.
List It should be the chosen prefix for the project.

Message Signing

Another important factor is that you can subscribe to a list through wildcards. For example, if the project prefix is IOTWBS, and the project has data collection, trigger and actuator:

Subscription subscription
IOTWBS/# Accompany any data that is published to the list IOTWBS, even being collected, trigger and actuators.
IOTWBS/collect/# Monitor any data that is being collected, on any device.
IOTWBS/trigger/# Monitor any data that is being changed while trigger.
IOTWBS/actuator/# Monitor any data that is being changed while the actuator.

How to test?

One of the applications that can be used for testing is used MQTT Mosquitto, which is an open-source application that allows such communication, both accomplished the publication as signature of outgoing messages.

For installation follow the tutorial: Download Mosquitto.

To accomplish publishing the command data is used mosquitto_pub and to sign the list command mosquitto_sub.

Collecting device

How to perform the publication of the collection

To perform the data collection should be used to list collect, fixed the acronym of the project and the suffixed serial number the device.

The data should be sent in JSON format, with all the values that you want to store for realization the collection.

$ mosquitto_pub -h guardiao.cl -u "suporte@webonesystem.com.br" -P "497aa991-d8e6-4bb6-ad17-f01a13648333" -t "IOTWBS/collect/IOTWBS0001" -m '{"data":{"temperature":10,"humidity":30,"luminosity":15}}'
Parameter Meaning Value in Example
-h Connecting host. guardiao.cl
-u User login. suporte@webonesystem.com.br
-P The password, in case the Api Key number of the project. 497aa991-d8e6-4bb6-ad17-f01a13648333
-t Prefix + List Project(collect) + Num. Series. IOTWBS/collect/IOTWBS0001
-m Date for sending in JSON format with the key data. {"data":{"temperature":10,"humidity":30,"luminosity":15}}

Signing the data being collected

To accompany the data collection can be signed the list, in case the collected data publishing list.

Both can be signed as the example here, and used the list subscription mode through wildcard characters.

$ mosquitto_sub -h guardiao.cl -u "suporte@webonesystem.com.br" -P "497aa991-d8e6-4bb6-ad17-f01a13648333" -t 'IOTWBS/collect/IOTWBS0001' -v
Parameter Meaning Value in Example
-h Connecting host. guardiao.cl
-u User login. suporte@webonesystem.com.br
-P The password, in case the Api project Key number. 497aa991-d8e6-4bb6-ad17-f01a13648333
-t Prefixo do Projeto + Lista(collect) + Núm. de Série. IOTWBS/collect/IOTWBS0001
-v Used to maintain the console following the messages. -

Triggers

How to make the change Trigger

Using the same premise of what has been exemplified above, you can change the state of a trigger through the list trigger.

The data format is fixed, and only allows you to enable (state: on) or disable the device (state:off).

To enable the trigger, sending following example:

$ mosquitto_pub -h guardiao.cl -u "suporte@webonesystem.com.br" -P "497aa991-d8e6-4bb6-ad17-f01a13648333" -t “IOTWBS/trigger/IOTWBS0002" -m '{"data":{“state”:”on"}}'
Parameter Meaning Value in Example
-h Connecting host guardiao.cl
-u User login. suporte@webonesystem.com.br
-P The password, in case the Api project Key number. 497aa991-d8e6-4bb6-ad17-f01a13648333
-t Prefix + List Project(trigger) + Num. Series. IOTWBS/trigger/IOTWBS0002
-m Date to activate the device using the data. {"data":{“state”:”on"}}

To disable the trigger, sending following example:

$ mosquitto_pub -h guardiao.cl -u "suporte@webonesystem.com.br" -P "497aa991-d8e6-4bb6-ad17-f01a13648333" -t “IOTWBS/trigger/IOTWBS0002" -m '{"data":{“state”:”off"}}'
Parameter meaning Value in example
-h Connecting host. guardiao.cl
-u User login. suporte@webonesystem.com.br
-P The password, in case the Api Key number of the project. 497aa991-d8e6-4bb6-ad17-f01a13648333
-t Prefix + Project List (trigger) + Number. Series. IOTWBS/trigger/IOTWBS0002
-m Date to inactivate the device using the date. {"data":{“state”:”off"}}

Performing the

You can track the status changes of the triggers. In the next example is being followed all the device changes IOTWBS0002.

$ mosquitto_sub -h guardiao.cl -u "suporte@webonesystem.com.br" -P "497aa991-d8e6-4bb6-ad17-f01a13648333" -t “IOTWBS/trigger/IOTWBS0002" -v
Parameter Meaning Value in Example
-h Connecting host. guardiao.cl
-u User login. suporte@webonesystem.com.br
-P The password, in case the Api project Key number. 497aa991-d8e6-4bb6-ad17-f01a13648333
-t Prefix + Project List (trigger) + Number. Series. IOTWBS/trigger/IOTWBS0002
-v Used to keep the console following messages. -

Triggers

Only to sign Collected data

If the actuator is only possible to follow the state change data. To track is used to list actuator.

$ mosquitto_sub -h guardiao.cl -u "suporte@webonesystem.com.br" -P "497aa991-d8e6-4bb6-ad17-f01a13648333" -t ‘IOTWBS/actuator/IOTWBS0003' -v
Parameter Meaning Value in Example
-h Host de conexão. guardiao.cl
-u User login. suporte@webonesystem.com.br
-P The password, in case the Api project Key number. 497aa991-d8e6-4bb6-ad17-f01a13648333
-t Prefix + Project List (actuator) + Number. Series. IOTWBS/actuator/IOTWBS0003
-v Used to keep the island following the messages. -