MQTT-SN Client

This page contains documentation of the MQTT-SN Client service and its C API library.

Introduction

MQTT-SN, or Message Queuing Telemetry Transport for Sensor Networks, is a lightweight and efficient messaging protocol designed for constrained environments, particularly suited for low-power, low-bandwidth, and high-latency networks. It is an extension of the widely adopted MQTT protocol, optimized to meet the specific requirements of sensor networks and other resource-constrained devices.

Introduced as an open standard by IBM in 1999, MQTT originally targeted machine-to-machine communication in the context of industrial automation. As the Internet of Things (IoT) ecosystem expanded, the need for a more tailored protocol for highly constrained environments became evident. This led to the development of MQTT-SN, which addresses the challenges posed by devices with limited processing capabilities, memory, and power resources.

One of the primary advantages of MQTT-SN is its ability to facilitate seamless communication between sensor nodes and gateway devices, making it well-suited for scenarios where a hierarchical network structure is employed. It achieves this by employing a broker-based publish-subscribe model, similar to its predecessor MQTT, allowing devices to exchange information without direct point-to-point connections.

One of the most important technical aspects of MQTT-SN is that it uses the UDP transport protocol instead of TCP used in MQTT. It also uses topic IDs instead of topic strings allowing for shorter UDP datagrams, at the expense of necessity to first register the topic in the gateway prior any usage.

Architecture

The diagram below presents the architecture of a system using MQTT-SN over UDP:

The MQTT-SN enabled devices run MQTT-SN Client service on top of the embeNET Node library, which provides UDP networking. These clients connect to a MQTT-SN Gateway which typically runs on the embeNET Border Router. It may however also run on any other server reachable by networked clients. The gateway translates the UDP-based MQTT-SN protocol to a standard TCP-based MQTT protocol and talks to a standard MQTT brokers, that are commonly found in IoT Platoforms such as Losant, MS Azure IoT Hub, AWS IoT and many other.

MQTT-SN Gateways

There are couple of options when it comes to selecting MQTT-SN gateway. The one we recommend is: MQTT For Small Things (SN) written in Java.

Go to MQTT-SN Gateway setup for a quick tutorial on how to set up such Gateway.

Other options include Paho MQTT-SN Transparent / Aggregating Gateway in C++.

When developing and testing the MQTT-SN Client for embeNET it is best to first set up the connection between a MQTT broker and MQTT-SN Gateway.

The MQTT-SN Client for embeNET

This MQTT-SN Client service is a UDP based service running over the embeNET wireless communication protocol. The MQTT-SN protocol is a version of the popular Message Queuing Telemetry Transport (MQTT) protocol but made suitable for Sensor Networks that utilize UDP transport protocol instead of TCP. This implementation is based on the MQTT-SN specification version 1.2.

This client supports the following functions:

  • connecting and disconnecting to the gateway
  • registering topics
  • subscribing to topics and receiving messages on that topic
  • publishing messages on topics

We invite you to the following next sections describing the client:

Go to Top