When MQTT-SN should be used? How is it different from MQTT?

MQTT-SN (wher SN means Sensors Network) is different from MQTT. MQTT goes over TCP/IP and it can used for LAN communication or over Internet and the Cloud (if you have a client inside your network but the broker is outside on Internet). MQTT-SN can be used on more protocols suited for sensors network like ZigBee, Z-Wave and so on. The specification is different from MQTT ... so it isn't MQTT not over TCP/IP. It's more lightweight and needs a bridge to translate MQTT-SN messages into MQTT messages.

Paolo.


There are few advantages in MQTT-SN (SN for Sensors Network) over MQTT, especially for embedded devices.

Advantages

  1. MQTT-SN uses topic ID instead of topic name. First client sends a registration request with topic name and topic ID (2 octets) to a broker. After the registration is accepted, client uses topic ID to refer the topic name. This saves media bandwidth and device memory - it is quite expensive to keep and send topic name e.g: home/livingroom/socket2/meter in memory for each publish message.
  2. Topic name to topic ID can be configured in MQTT-SN gateway, so that topic registration message can be skipped before publish.
  3. MQTT-SN does not require TCP/IP stack. It can be used over a serial link (preferred way), where with simple link protocol (to distinguish different devices on the line) overhead is really small. Alternatively it can be used over UDP, which is less hungry than TCP.

Disadvantages

  1. You need some sort of gateway, which is nothing else than a TCP or UDP stack moved to a different device. This can also be a simple device (e.g.: Arduino Uno) just serving multiple MQTT-SN devices without doing other job.
  2. MQTT-SN is not well supported.

If you are running out of resources, or you do not have Ethernet/Wifi in your device, use MQTT-SN.

Tags:

Mqtt