Using The Paho MQTT-SN Gateway

Paho MQTT-SN Gateway can act as a transparent gateway or aggregating gateway depending on settings in the configuration file.

The Gateway enables MQTT-SN clients to send messages to other MQTT-SN clients and to MQTT clients.

Unlike the RSMB broker the gateway requires an external MQTT broker to work and does not function as a MQTT-SN broker.

The MQTT broker can run on the same machines as the Gateway.

Installing the Gateway

The install instructions are on the GitHUb page and I will not repeat them here in case they are changed. Install instructions here

The Github page also as a sample configuration file which I recommend you use.

Note: I did have to create the make file using the command

cmake -G"Unix Makefiles"

Starting The Gateway

You can start using ./MQTT-SNGateway and it will use the default gateway.conf file.

Alternatively specify the conf file using the -f switch ./MQTT-SNGateway -f mygateway.conf


The Configuration File (gateway.conf)

The default configuration file that comes with the install gateway.conf will work as is but you may want to edit it to use a local broker as shown below:


The default configuration is for a transparent gateway.

Use as a Transparent Gateway

This is the easiest setup and the default configuration file is set with this configuration.

In this configuration a MQTT-SN client connects to the gateway and the gateway creates a connection to the MQTT Broker.

If there is no MQTT broker available the connection is refused.

Connection Process

MQTT-SN client–>Gateway–>MQTT Broker–>Gateway–>MQTT-SN client

A packet from an MQTT-SN client to another MQTT-SN client goes from the client to the gateway, and then to the MQTT broker and then back to the gateway and then to the MQTT-SN destination client.


If we take an example of a MQTT-SN client subscribing and then publishing to the same topic (QOS=0) then the process is.

  1. MQTT-SN client connects to Gateway
  2. Gateway Connects to MQTT Broker
  3. CONNACK from Broker to Gateway
  4. CONNACK from  Gateway to Broker
  5. MQTT-SN sends subscribe to Gateway
  6. Gateway sends subscribe to MQTT Broker
  7. SUBACK from Broker to Gateway
  8. SUBACK from  Gateway to Broker
  9. MQTT-SN client sends publish to Gateway
  10. Gateway sends publish to MQTT Broker
  11. Publish from Broker to Gateway
  12. Publish from  Gateway to Broker

The screen shot below shows the MQTT-SN Gateway and MQTT broker consoles side by side with a MQTT-SN connecting and subscribing:


You should notice that the client ID of the MQTT-SN client GatewayTester is used also for connecting to the MQTT broker.

Using SSL and Client Certificates On The MQTT Broker Connection

If the MQTT broker requires SSL and authentication  then there is quite a lot of configuration involved.

You need to first edit the clients.conf file. Here is a sample of my test configuration.


The format is:

clientId,client IP:client Port,connection type

The client port is interesting and caused me a lot of confusion as you need to set the client source port when it connects.

Normally the client will use a random port.

So in my test the client GatewayTester will connect using a source port of 10001 which is set manually on the client.

This is how I set it in my Python client:


The MQTT-SN client tools also support this option using –cport switch.set-source-port-tools
Example publish:

The gateway.conf also needs editing  here is a screen shot of the main parts.


Aggregating Gateway

In this mode a single connection to the MQTT broker carries the data for all of the MQTT-SN clients.

This would be my preferred working mode but I wasn’t able to get this to work as it kept crashing.


I had quite a few problems with the gateway and would be interested to hear from anyone using this in a live environment as an aggregating gateway as I may be that I made some simple errors in the config file.

Overall I prefer the RSMB as it is much simpler to configure and doesn’t require an external MQTT broker.



Please rate? And use Comments to let me know more


  1. I tried this with IPv6. I am also using the Gateway Tester and the Gateway itself. Every time i run them i only receive the GWSEARCH message from the client on the multicastIPv6 channel. Weird is that the client itself only receives its own GWSEARCH message. The gateway itself responds on the multicastIPv6 address with its GWINFO but the client never receives it? They are both using the same interface for multicast IPv6 exchange.

    1. Andreas
      Sorry but I haven’t tried it using ipv6 it is something that is on my todo list. Let me know if you find out why.
      As an aside are you using MQTT-SN on a real project? I’m interested in more info on real projects involving MQTT-SN

  2. Hi, how the GATEWAY convert the MQTT-SN message into MQTT? And after this conversion the message are MQTT but carryout via UDP ?

    Do we need MQTT-SN Gateway only when use Zigbee, Bluetooth? If we use WIFI, can we use only MQTT-SN Client ?

    Which is the IP, belong to ?

    1. You will need the gateway any time you want to convert MQTT-SN to MQTT the link technology i.e. Wi-Fi ,Zigbee isn’t relevant.
      Tge address is the multicast address used for gateway discovery. It is optional as you can just hard code the gateway address in the client like you do with MQTT.

Leave a Reply

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