Benefits of MQTT-SN over MQTT
MQTT SN is exclusively designed for sensor networks and the specification for the same (MQTT SN specification) is available at MQTT.org. MQTT protocol & MQTT SN (MQTT for sensor networks) are both IoT Protocol used most widely for developing IoT devices. This blog is for developers to understand when to use MQTT-SN (SN MQTT for sensor) and the advantages of the same over MQTT.
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 protocol, 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. Moreover MQTT SN supports four types of MQTT QoS (Quality of service) QoS 0,1,2,-1 or 3.
Predefined Topic IDs & Topics Names
The topic names can be predefined in the MQTT SN Gateway with a pre defined 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. The short topic names less than 2 bytes can also be used without topic IDs. 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 or publishing messages to this client . The client can send a resume message to get all the packets received during the sleep period. This make this publish subscribe messaging 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. And it does not depend on TCP/IP networks. 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 sensor networks. MQTT SN is mainly targeted at embedded devices, on non TCP/IP networks such as zigbee.
You can have a look at the detailed document on how to develop MQTT-SN Clients and how to develop MQTT Clients.