MQTT-SN Protocol

MQTT-SN stands for “MQTT for Sensor Networks” which is aimed at embedded devices on non-TCP/IP networks, such as Zigbee. Its offical site says:

MQTT-SN is a publish/subscribe messaging protocol for wireless sensor networks (WSN), with the aim of extending the MQTT protocol beyond the reach of TCP/IP infrastructure for Sensor and Actuator solutions.

MQTT-SN specification can be downloaded from


MQTT-SN looks similar to MQTT in most part, such as WILL message, such as Connect/Subscribe/Publish command.

The very difference between MQTT-SN and MQTT is the TopicId which replaces topic name in MQTT. TopicId is a 16 bits integer which stands for a topic name. Device and broker use REGISTER command to negotiate the mapping bewteen TopicId and topic name.

MQTT-SN is able to update Will message, even delete it. But MQTT is not allowed to change Will which is set in Connect command only.

MQTT-SN introduce gateways in its network. Gateway translate between MQTT-SN and MQTT, exchange messages between device and mqtt broker. And there is a mechanism that called gateway discovery, which enables device to find gateways automatically.

MQTT-SN support sleeping client feature which allows device to shutdown itself to save power for a while. Gateway need to buffer downlink publish message for sleeping devices, and push these message to devices once they are awake.

EMQ-SN Plugin

EMQ-SN is a EMQ plugin which implement most features of MQTT-SN. It serve as a MQTT-SN gateway on cloud, neighbor of EMQ broker.

Plugin config

File: etc/plugins/emq_sn.conf: = 1884 = 900 = 1 = mqtt_sn_user = abc The UDP port which emq-sn is listening on. The duration(seconds) that emq-sn broadcast ADVERTISE message through. Gateway id in ADVERTISE message. This parameter is optional. If specified, emq-sn will connect EMQTTD core with this username. It is useful if any auth plug-in is enabled. This parameter is optional. Pair with username above.

Load Plugin

./bin/emqttd_ctl plugins load emq_sn