MQTT-SN to MQTT Using QOS 3 and Node-Red

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.

mqtt-sn-qos-1-publish

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

download

 

Related tutorials and resources

 

 

Please rate? And use Comments to let me know more

Leave a Reply

Your email address will not be published. Required fields are marked *