Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
80 lines (51 sloc) 3.56 KB

MQTT-SN Protocol

MQTT-SN stands for "MQTT for Sensor Networks" which aims 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 parts, 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 introduces gateways in its network. Gateway translates between MQTT-SN and MQTT, exchanges messages between device and MQTT broker. And there is a mechanism that called gateway discovery, which enables device to find gateways automatically.

MQTT-SN supports sleeping client feature which allows device to shutdown itself to save power for a while. Gateway needs to buffer downlink publish messages for sleeping devices, and pushes these messages to devices once they are awake.

EMQX-SN Plugin

EMQX-SN is an EMQ X plugin which implements most features of MQTT-SN. It serves as an MQTT-SN gateway on cloud, who is the neighbor of EMQ X Broker.

Plugin config

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

Load Plugin

./bin/emqx_ctl plugins load emqx_sn

MQTT-SN Client Library