Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Sensor Series
      • 3D Printing
      • AI
      • ARDUINO Compatible Coding
      • Audio Electronics
      • Battery Management
      • Beginners Electronics Series
      • Brainwave
      • Digital electronics (DE)
      • Electric Vehicles
      • EMI/EMC/RFI
      • EVs
      • Hardware Filters
      • IoT tutorials
      • LoRa/LoRaWAN
      • Power Tutorials
      • Protocol
      • Python
      • RPI Python Programming
      • Sensors
      • USB
      • Thermal management
      • Verilog
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
  • Guest Post Guidelines
  • Advertise
  • Subscribe

MQTT for Sensor Networks (MQTT-SN) : IoT Part 39

By Priya April 7, 2024

The Internet of Things have specific network requirements. The traditional TCP/IP protocols usually do not fit to these requirements. That is why there are many protocols designed especially to cater the requirements of IoT applications. Within the IoT domain, sensor networks are one of the applications which are designed using constraint devices and are characterized by limited network bandwidth. A variant of MQTT protocol has been designed for these networks which is called MQTT-SN (MQTT for Sensor Networks). 
MQTT and MQTT-SN are different from each other. MQTT is a protocol which is designed to be light weight for M2M, but it needs TCP/IP stack to operate. But if the sensor nodes cannot hold the TCP/IP stack then here comes MQTT-SN which does not depend on TCP/IP for it to operate.
Due to sudden increase of interest in Wireless Sensor Network (because of simplicity, low cost and easy deployment), a light weight pub-sub protocol has been developed called MQTT-SN. The SN or Sensor Network in the protocol name indicates that it is specifically designed for sensor networks. As sensor nodes are specifically made with limited processing capabilities and limited amount of storage, so these sensor nodes cannot have TCP/IP stack with themselves because TCP/IP protocol stack is too heavy to be handled by such tiny sensor nodes due to big payload, retry mechanism, time to live for the packets etc.
MQTT-SN was originally designed for running on top of the Zigbee APS layer. Any network which provides a bi-directional data transfer service between any node and a particular one (gateway) should be able to support MQTT-SN.
How MQTT-SN is different from MQTT?
First thing, MQTT-SN is designed to be as close as possible to MQTT, but is adapted to the particular behavior of wireless communication network such as low bandwidth, high link failures, short message length etc. Second, MQTT-SN is optimized for the implementation on low cost, battery-operated devices with limited processing and storage resources. Third, MQTT-SN needs a bridge to translate MQTT-SN messages into MQTT messages.
Compared to MQTT, MQTT-SN is characterized by following differences –
1) MQTT-SN supports topic ID instead of topic name. First client sends a registration request with topic name and topic ID (2 octets) to the 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 names like home/livingroom/socket2/meter in memory for each publish message.
2) The Topic name to topic ID can be preconfigured in MQTT-SN gateway, so that even registration message can be skipped before publish.
3) A discovery procedure helps clients without a pre-configured server/gateway’s address to discover the actual network address of an operating server/gateway. Multiple gateways may be present at the same time within a single wireless network and can co-operate in a load-sharing or stand-by mode.
4) The Clients connect to the broker through a gateway device, which resides within the sensor network and connects to the broker.
MQTT-SN Architecture 
The architecture of MQTT-SN can be represented by the following figure –
Image Showing MQTT-SN Architecture
Fig. 1: Image showing MQTT-SN Architecture
There are three kinds of MQTT-SN components – MQTT-SN clients, MQTT-SN gateways (GW) and MQTT-SN forwarders. MQTT-SN clients connect themselves to a MQTT server via a MQTT-SN GW using the MQTT-SN protocol. A MQTT-SN GW may or may not be integrated with a MQTT server. In case of a stand-alone GW, the MQTT protocol is used between the MQTT server and the MQTT-SN GW. Its main function is the translation between MQTT and MQTT-SN. MQTT-SN clients can also access a GW via a forwarder in case the GW is not directly attached to their network. The forwarder simply encapsulates the MQTT-SN frames it receives on the wireless side and forwards them unchanged to the GW. In the opposite direction, it releases the frames it receives from the gateway and sends them to the clients, unchanged too.
There are two types of Gateways depending on how a Gateway performs the protocol translation between MQTT and MQTT-SN:
1) Transparent Gateway – For each MQTT-SN client, transparent gateway will form an individual MQTT connection to the MQTT broker.
2) Aggregating Gateway – In this, for all MQTT-SN clients, the Aggregating gateway will form only one MQTT connection to the MQTT broker. The advantage of using aggregating gateway is shown where WSN network has large number of sensor nodes because it helps in reducing the number of MQTT connections that broker has to create with individual client.
Message Formats –
When client and broker communicate with each other, they follow some set of rules in the message like what are the things will be included in topic, payload etc. The following tree represents the message format in MQTT-SN –
Image Showing MQTT-SN Message Format
Fig. 2: Image showing MQTT-SN Message Format
Table Listing Message Format of MQTT-SN
Fig. 3: Table listing Message Format of MQTT-SN
Table Listing Message Format of MQTT-SN
Fig. 4: Table listing Message Format of MQTT-SN
Table Listing Flags in MQTT-SN Message
Fig. 5: Table listing Flags in MQTT-SN message
                                                                              Table Listing Flags in MQTT-SN Message
Fig. 6: Table listing Flags in MQTT-SN message
MQTT-SN Features 
The MQTT-SN protocol has the following distinct features –
1) Gateway Advertisement and Discovery – A gateway continuously advertises itself by sending an ADVERTISE & GWINFO message to all devices that are part of the network. The client discovers the gateway by the Gateway unique ID. A client maintains the list of all active gateways with the network address & UID.
2) Client’s Connection Setup –  An MQTT-SN client needs to setup a connection to a GW before it can exchange information with that GW.
Image Showing MQTT-SN Client Connection Procedure
Fig. 7: Image showing MQTT-SN Client Connection Procedure
Check out the MQTT-SN specification for more details on Client connection procedure.
3) Procedure for updating the will data – The client can update the previously registered Will topic and Will message at any time by sending the WILLTOPICUPD or WILLMSGUPD message.
4) Topic Name Registration Procedure – Because of the limited bandwidth and small payload, a registration procedure is involved. The client first sends the REGISTER message with the topic name to the gateway then if GW accepts the registration, it assigns the topic ID on that topic name and acknowledge it with the REGACK message. In that way, if client sends any message to that topic, it will not use the long topic name again, it will use only the assigned 2 bytes topic ID.
5) Client Disconnect – A client sends a DISCONNECT message to the GW to indicate that it is about to close its connection. After this point, the client is then required to establish a new connection with the GW before it can exchange information with that GW again.
6) Support of Sleeping Client – The broker or server remains aware of the sleeping clients and buffer the message 0020 to deliver them when they wake up.
In the next tutorial, learn about RSMB Broker for implementing MQTT-SN protocol.

Filed Under: IoT tutorials, Tutorials

 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

Submit a Guest Post

submit a guest post

EE TECH TOOLBOX

“ee
Tech Toolbox: Power Efficiency
Discover proven strategies for power conversion, wide bandgap devices, and motor control — balancing performance, cost, and sustainability across industrial, automotive, and IoT systems.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions.

  • Cloning a HDD
  • PDKs setup for Virtuoso
  • Synchronous rectifier chips nil stocked everywhere?
  • improving in delivering a signal from source to load
  • delete my account

RSS Electro-Tech-Online.com Discussions

  • Help please! BLDC driver circuit using the IR2136s and the STP80NF06 MOSFETS
  • need two ICs
  • MLT-8530 Buzzer on ESP32: Why Is the Sound Output Lower Than Expected?
  • Scope Clock CRT Z-Axis - Grid bias positive?
  • Measuring controller current output with a meter

Featured – Real Time Hardware Filter Design

  • Practical implementation of bandpass and band reject filters
  • Practical application of hardware filters with real-life examples
  • A filter design example
  • Types of filter responses
  • What are the two types of hardware filters?
  • What are hardware filters and their types?

Recent Articles

  • GigaDevices introduces 32-bit MCUs with integrated DSP and FPU support
  • Grinn introduces 8-core SBC supporting AI-ready embedded development
  • EPC’s 100 kHz BLDC inverter supports high-efficiency motion control
  • Melexis announces 5 W smart driver to supports sensorless FOC operation
  • STMicroelectronics’ motion sensor simplifies industrial IoT system design

EE ENGINEERING TRAINING DAYS

engineering
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Sensor Series
      • 3D Printing
      • AI
      • ARDUINO Compatible Coding
      • Audio Electronics
      • Battery Management
      • Beginners Electronics Series
      • Brainwave
      • Digital electronics (DE)
      • Electric Vehicles
      • EMI/EMC/RFI
      • EVs
      • Hardware Filters
      • IoT tutorials
      • LoRa/LoRaWAN
      • Power Tutorials
      • Protocol
      • Python
      • RPI Python Programming
      • Sensors
      • USB
      • Thermal management
      • Verilog
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
  • Guest Post Guidelines
  • Advertise
  • Subscribe