MQTT-SN is considered the version of the MQTT protocol, which is mainly designed for wireless sensor networks (WSNs). The recent advancements in engineering, communication, and networking have led to new sensor designs, information technologies, and wireless systems. Such advanced sensors can serve as a link between the physical and digital worlds. These WSNs can help measure, detect and automate processes and they have applications in IT, government, military, civil, or industrial domains.
What are Wireless Sensor Networks ?
The wireless sensor network is a sensor network that consists of sensors, a controller, and a communication system. The kind of communication system defines the type of network. For example, wireless sensor networks or WSNs uses wireless network protocol such as MQTT-SN, which we are going to cover later in this blog.
The WSNs has two elements,
- Sensor Node
- Network Architecture
1. Sensor Node
The sensor node has further 4 elements,
- Power unit
- Processing unit
- communication unit
The power unit is responsible for powering up the whole sensor node. Since these sensors measure the physical environment at remote locations, they are very power efficient. The sensing unit is responsible for measuring or detecting real-world physical values and converting them to digital values using the Analog to digital converter (ADC). The processing unit is responsible for manipulating data and is responsible for connecting with the communication unit to send data. These sensor nodes uses the short range radio transmission and reception, since these are nodes are low power devices.
2. Network Architecture
The network Architecture of the WSNs consist of multiple sensor nodes which are deployed in an environement to detect the physical environment. These sensor nodes are connected to other sensor nodes and Internet using the Base station, and the communication between them is wireless.
Then the Base station orders the sensing region to perform a task, and all the sensor nodes collaborate to sense the region and sends back the data to base station. The BS after processing the data sends the information to the user using the internet.
Now you know what are the wirless sensor networks and how do they work, we can talk about the MQTT-SN.
MQTT-SN stands for MQTT for sensor networks and the its design is very close to MQTT protcol. Since sensor nodes have limited power, storage and processing resources, MQTT-SN is an optimized protocol. Since I have already explained MQTT protcol in details, and we already know that MQTT itself is really lightweight and optimized protocol and consumes very low power and bandwidth, then why do we need MQTT-SN at all ?
Why do we need MQTT-SN ?
One of the main reason for the existence of MQTT-SN is the cost of operation of large wireless IoT networks that runs on MQTT. The MQTT in theory is a very simple protocol, but in reality there are thousand or million of IoT clients interacting with the MQTT broker. This results in failure of IoT projects due to operation costs in managing unpredictable amount of data transmitted and recieved. Therefore, the scaling of the project is under question mark after a point.
Therefore, MQTT protocol was further optimized by reducing power consumption, payload size and addition of standby feature to create MQTT-SN protocol. The communication approach of it is very similar to MQTT but it is more scalable.
Differences between MQTT-SN and MQTT
|TCP connection.||UDP connection.|
|topic names for subscription and publishing.||topic Ids for subscription and publishing.|
|payload size limit of 256MB.||payload size limit of 60 octets (60 bytes).|
The above table mentions the major differences between the MQTT for sensor network and MQTT. The use of UDP connection mean there is no need of permanent connection with the broker. The other differences are as following,
- The connect message has been divided into three messages. The first two are optional and are used for the will message.
- Topic names are replaced by topic identifiers.
- Concise topic names.
- Predefined topics.
- The discovery process allows clients to discover the Gateway.
- During the session, the topic and messages can be changed.
The MQTT for sensor networks has the following four components, which builds its architecture.
- MQTT-SN Gateway
- MQTT-SN Forwarder
We already know what is MQTT broker but in short the broker is the central part of the network and receives all messages, filtering them and decide who is interested in them and publishing the message to all the subscribed devices.
2. MQTT-SN Clients
Clients are the devices or sensors that connects to MQTT broker to publish or recieve messages.
3. MQTT-SN Gateway
Gateway acts as a translation layer to convert the MQTT packets to MQTT-SN packets and vice versa.
There are two types of Gateways, Transparent and Aggregating Gateways.
The transparent gateway just translates the MQTT-SN packets toMQTT packets and vice versa and it has to keep concurrent connections with the MQTT broker. It is complicated to keep concurrent connections at an enterprise level as it is waste of resources.
Whereas, on the other hand, Aggregating MQTT-SN gateway not only translates the packets but also it collects, filters and process the client messages. Also, it requires only one connection between the MQTT broker and gateway. However, this is more difficult to implement.
4. MQTT-SN Forwarder
MQTT-SN Forwardar is used between the client and the gateway in the absence of direct communication between them. Forwardar is also helpful when the client and gateway are in different networks. The forwardar simply encapsulates the MQTT-SN frames it receive on the wireless network side and without changing forward it to the gateway. It works in the both direction i.e. it also forwards the packets from gateway to the client.
MQTT for sensor networks is a communication protocol specifically designed for devices that are limited in power, storage or processing. It is faster and more scalable than typical MQTT protocol. The applications and benefits of MQTT protocol are numerous, but addition of sensor networks makes it more robust.