Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

mqtt

If MQTT is already a lightweight protocol and it uses small amount of power and bandwidth, then why do we have MQTT-SN? When is it appropriate to use MQTT and when MQTT-SN?

like image 915
Sasikumar Avatar asked Dec 19 '14 06:12

Sasikumar


People also ask

What is MQTT-Sn and in which conditions it is better to use MQTT SN?

MQTT-SN (MQTT for sensor networks) is an optimized version of the IoT communications protocol, MQTT (Message Queuing Telemetry Transport), designed specifically for efficient operation in large low-power IoT sensor networks.

What is the difference between MQTT server and MQTT broker?

An MQTT broker is a server that receives all messages from the clients and then routes the messages to the appropriate destination clients. An MQTT client is any device (from a micro controller up to a fully-fledged server) that runs an MQTT library and connects to an MQTT broker over a network.

When should I use MQTT?

MQTT is used for data exchange between constrained devices and server applications. It keeps bandwidth requirements to an absolute minimum, handles unreliable networks, requires little implementation effort for developers, and is, therefore, ideal for machine-to-machine (M2M) communication.


2 Answers

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.

like image 158
Michal Foksa Avatar answered Oct 17 '22 02:10

Michal Foksa


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.

like image 24
ppatierno Avatar answered Oct 17 '22 00:10

ppatierno