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.
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.
- MQTT-SN client connects to Gateway
- Gateway Connects to MQTT Broker
- CONNACK from Broker to Gateway
- CONNACK from Gateway to Broker
- MQTT-SN sends subscribe to Gateway
- Gateway sends subscribe to MQTT Broker
- SUBACK from Broker to Gateway
- SUBACK from Gateway to Broker
- MQTT-SN client sends publish to Gateway
- Gateway sends publish to MQTT Broker
- Publish from Broker to Gateway
- 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.
The gateway.conf also needs editing here is a screen shot of the main parts.
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 get 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.
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 255.1.1.1, belong to ?
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 255.1.1.1 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.