Page 1 of 1

MQTT-SN over Bluetooth

Posted: Mon Jul 08, 2019 6:29 pm
by fryderykchopin
So far I have been running some experiments with MQTT over WiFi using 3 Raspberry Pi's:

MQTT publisher --> WiFi link --> MQTT Broker (mosquitto) --> Ethernet link --> MQTT subscriber

I have been using mosquitto as the MQTT broker and the clients (publisher and subscriber) that come with it. Everything has been running over TCP/IP and it has been pretty easy to setup.

Now I would like to replace the WiFi link with a Bluetooth link, however I am having problems to do this. Since MQTT requires TCP/IP, which Bluetooth does not provide, I need to switch to MQTT-SN which can be run over any technology.

I have found the way to implement the middle node (the broker). I would keep the mosquitto (MQTT) broker and use the MQTT-SN gateway from Eclipse Paho (https://www.eclipse.org/paho/components ... nt-gateway) to convert the MQTT-SN packets into MQTT packets that the mosquitto broker could process. Moreover, since the packets would be received through a serial port (Bluetooth), I need a bridge like this one https://github.com/njh/mqtt-sn-tools/bl ... l-bridge.c. All this would sort out the broker.

The problem is on the publisher's side. All the MQTT-SN publishers that I have found are implemented to run over UDP, which assumes an underlying IP connection. I have not found any code for an MQTT-SN publisher that I can run on a Raspberry Pi to send the packets through a Bluetooth link. There is some code for micro-controllers but not something that I could run on RBPi to do the same. I was wondering if there is any implementation of an MQTT-SN client that I could run in a Raspberry Pi to send the data through Bluetooth to the MQTT-SN gateway. If not, how could I achieve what I need? Any help would be much appreciated.

Re: MQTT-SN over Bluetooth

Posted: Mon Jul 08, 2019 9:25 pm
by Andyroo
The only thing I have ever seen on MQTT-SN is at http://www.steves-internet-guide.com/mqtt-sn/

Not sure if the Python code is of any use or not...

Re: MQTT-SN over Bluetooth

Posted: Mon Jul 08, 2019 10:33 pm
by Douglas6
Technically, TCP/IP is possible over Bluetooth using BNEP (Bluetooth Network Encapsulation Protocol.) I haven't played with it in years and years, but I assume you could use the Network Access Profile (NAP) to create a small Personal Area Network (PAN), and run MQTT over that.

Again, I can't help, but there are some keywords for you.

Re: MQTT-SN over Bluetooth

Posted: Tue Jul 09, 2019 9:24 am
by fryderykchopin
Andyroo wrote:
Mon Jul 08, 2019 9:25 pm
The only thing I have ever seen on MQTT-SN is at http://www.steves-internet-guide.com/mqtt-sn/

Not sure if the Python code is of any use or not...
I think RSMB is designed to support UDP as well but I will double check. Thanks

Re: MQTT-SN over Bluetooth

Posted: Tue Jul 09, 2019 9:28 am
by fryderykchopin
Douglas6 wrote:
Mon Jul 08, 2019 10:33 pm
Technically, TCP/IP is possible over Bluetooth using BNEP (Bluetooth Network Encapsulation Protocol.) I haven't played with it in years and years, but I assume you could use the Network Access Profile (NAP) to create a small Personal Area Network (PAN), and run MQTT over that.

Again, I can't help, but there are some keywords for you.
Thank you that option is probably what I will do, I have seen some tutorials on how to configure the bridges to have a Bluetooth PAN with IP in each node.

I was trying to avoid to use IP over Bluetooth as I wanted to try to communicate the client and the gateway directly over Bluetooth (rfcomm or l2cap), which I think is possible but I would need to do the coding myself since I haven't found any sample code and I don't have time for that. I assume that the reason why such code does not exist is probably because everybody simply builds a PAN as you pointed out and that gets everything working much more easily.

Re: MQTT-SN over Bluetooth

Posted: Tue Jul 09, 2019 11:12 am
by Douglas6
Make sure you are using up-to-date examples. Anything mentioning 'pand', for example, is too old. Also, please post your results. I think MQTT over Bluetooth would be of some interest.

Re: MQTT-SN over Bluetooth

Posted: Tue Jul 09, 2019 11:21 am
by DougieLawson
Douglas6 wrote:
Tue Jul 09, 2019 11:12 am
Make sure you are using up-to-date examples. Anything mentioning 'pand', for example, is too old. Also, please post your results. I think MQTT over Bluetooth would be of some interest.
You need to draw the strong distinction between MQTT which uses TCP/IP and MQTT-SN (MQTT for sensor networks) which can use things like UDP/IP, ZigBee, Zwave and BLE.

http://mqtt.org/new/wp-content/uploads/ ... c_v1.2.pdf

Re: MQTT-SN over Bluetooth

Posted: Tue Jul 09, 2019 11:45 am
by Douglas6
DougieLawson wrote:
Tue Jul 09, 2019 11:21 am
You need to draw the strong distinction between MQTT which uses TCP/IP and MQTT-SN (MQTT for sensor networks) which can use things like UDP/IP, ZigBee, Zwave and BLE.
Sorry, I thought I was, by referencing MQTT, and not MQTT-SN. I believe the OP understands that as well.

This thread is the first I've heard of MQTT-SN. I'm off to research that and BLE.

Re: MQTT-SN over Bluetooth

Posted: Tue Jul 09, 2019 11:55 am
by DougieLawson
Douglas6 wrote:
Tue Jul 09, 2019 11:45 am
This thread is the first I've heard of MQTT-SN. I'm off to research that and BLE.
How did I know the BLE stuff would spark your interest?

I was having a proper struggle with Google. All things seem to point to IBM's Really Small Message Broker (RSMB).

Re: MQTT-SN over Bluetooth

Posted: Tue Jul 09, 2019 12:31 pm
by Douglas6
I found a few things, a lot of it built on micro:bits. I'm not sure I see the point in stretching MQTT(-SN) all the way out to the edge (sensors), vs. using good ole GATT services and some translation at the gateway. But my understanding is very low at this point.

Re: MQTT-SN over Bluetooth

Posted: Tue Jul 09, 2019 12:55 pm
by DougieLawson
I think the MQTT-SN piece is there to work with intermittent, unreliable connections without needing the heavyweight last-will pieces in (full fat) MQTT.

I guess we could ask IBM's Distinguished Engineer Andy Stanford-Clark or ask on the MQTT mailing list.
List-Subscribe: <https://groups.google.com/group/mqtt/subscribe>, <mailto:mqtt+subscribe@googlegroups.com>