MQTT-SN works in a similar manor to MQTT and requires a connection to a broker/gateway before it can exchange messages.
MQTT-SN uses UDP which is a connectionless protocol the connection is actually a virtual connection.
However because MQTT-SN uses UDP , MQTT-SN also provides the ability to publish message without requiring a connection to a broker or gateway using a message with a QOS of 3 or -1.
However without a connection an MQTT-SN client cannot receive messages from a broker/gateway as it cannot subscribe to topics.
This in many cases is not a problem as many sensors like temperature sensors,motion sensors, smoke alarms etc only send data and don’t need to receive data.
Publishing with QOS -1 or QOS 3
The reason it is also known as QOS 3 is because the QOS field uses 2 bits so:
00=qos 0
01=qos 1
10=qos 2
11=qos -1 or 3
When publishing with QOS of 3 or -1 no connection message is sent.
You can see this in the broker trace below where I use MQTT_SN_PUB to publish without a connection using QOS of -1.
Using an MQTT-SN Broker or Gateway
Unfortunately there is only one MQTT-SN Broker (RSMB) which hasn’t been developed for many years.
Therefore a common option is to use a Gateway to convert MQTT-SN messages into MQTT messages.
Current Gateways implement the full MQTT-SN protocol and although they work, they introduce an extra layer of complexity.
For this reason I created a simple node-red flow that functions as an MQTT-SN Gateway for MQTT-SN QOS 3 messages only.
Although it is currently only available for node-red the idea could be easily transported to python, c, nodejs etc.
Using this type of gateway simple MQTT-SN sensors could publish messages to MQTT.
The MQTT-SN sensor would not need to implement the full MQTT-SN Protocol stack.
With a bit of extra coding topic and messages filtering and message combining could also be added.
Video
Demo Flow
Related tutorials and resources
- MQTT-SN Gateway Advertisement and Discovery
- MQTT-SN Topic Names and Identifiers
- MQTT-SN RSMB Broker Overview,Install and Configuration
- Using The Python MQTT-SN Client
- MQTT-SN Publish and Subscribe Test Tools