MQTT SN is exclusively designed for sensor networks and the specification for the same is available at MQTT.org. MQTT & MQTT SN are both IoT Protocol used most widely for developing IoT devices. This blog is for developers to understand when to use MQTT-SN and the advantages of the same.
MQTT SN Auto Discovery
In the MQTT set up, agents need to be informed where the broker runs. This increases the configuration overhead at the end user. But for MQTT-SN, the sensors and the gateway can propagate messages which is understood by its counterpart and can establish connection to communicate with each other. This makes it much simpler to configure.
The size of the every packet that is transferred in the MQTT-SN has been redesigned. For example in the CONNECT, only the required parameter is sent. The WILL and WILL Message has been split into separate packets and sent only when required. The overall data transferred over the network is reduced to a greater extent to reduce the bandwidth used.
Predefined Topic IDs & Topics Names
The topic names can be predefined in the Gateway with a predefined topic IDs. The client can directly send packets using the ID and no need to use the topic names. The topic IDs occupies a max of two bytes. If the client wants to use a new topic, then can send a register command for the new topic.
Lower Processing Power
The packet size reduction highly reduces the amount of power required to create and communicate data. Further there are provisions like Sleep of the clients which will stop the gateway from further sending the messages to this client . The client can send a resume message to get all the packets received during the sleep period. This highly make this protocol highly suitable for battery powered sensors.
MQTT is over TCP/IP Protocol. TCP has a lot of connection over head which is not required in the MQTT-SN which is over UDP. This again reduces the amount of data transfer and the power required.
It can be propagated over Zigbee, Z-Wave , bluetooth in addition to the wired and wireless networks.