fryderykchopin
Posts: 9
Joined: Wed Feb 20, 2019 10:16 am

MQTT-SN over Bluetooth

Mon Jul 08, 2019 6:29 pm

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.

Andyroo
Posts: 4124
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: MQTT-SN over Bluetooth

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...
Need Pi spray - these things are breeding in my house...

User avatar
Douglas6
Posts: 4736
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: MQTT-SN over Bluetooth

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.

fryderykchopin
Posts: 9
Joined: Wed Feb 20, 2019 10:16 am

Re: MQTT-SN over Bluetooth

Tue Jul 09, 2019 9:24 am

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

fryderykchopin
Posts: 9
Joined: Wed Feb 20, 2019 10:16 am

Re: MQTT-SN over Bluetooth

Tue Jul 09, 2019 9:28 am

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.

User avatar
Douglas6
Posts: 4736
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: MQTT-SN over Bluetooth

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.

User avatar
DougieLawson
Posts: 35766
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: MQTT-SN over Bluetooth

Tue Jul 09, 2019 11:21 am

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
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
Douglas6
Posts: 4736
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: MQTT-SN over Bluetooth

Tue Jul 09, 2019 11:45 am

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.

User avatar
DougieLawson
Posts: 35766
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: MQTT-SN over Bluetooth

Tue Jul 09, 2019 11:55 am

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).
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
Douglas6
Posts: 4736
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: MQTT-SN over Bluetooth

Tue Jul 09, 2019 12:31 pm

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.

User avatar
DougieLawson
Posts: 35766
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: MQTT-SN over Bluetooth

Tue Jul 09, 2019 12:55 pm

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>
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Return to “Networking and servers”