Help with Bluetooth

I set up Node Red with BLE and serial communication. Currently I am not near my home and can’t look it up in detail.

For BLE I used the HID of NDIS for serial communication because BLE has no serial communication like Bluetooth. And I used an adapted palette node-red-controb-ignoble that points to a noble repo form abandonware repo.

This sounds very interesting. If I get time this weekend I will look into what you mentioned. It would be great if you could share more details when you get a chance. Thank you.

I altered the node-red-ignoble node to get ignoble from Abandon Ware. I've uploaded the package to a temporary githu repo.

Install the module with npm npm install <location>/node-red-contrib-ignoble-0.0.12.tgz --no-save

BLE does not support Serial communication. Nordic UAR Service does support it.

Example to send "hello, world" over NUS to a BLE device. Link to Adafruits great tutorial. They also have an app for iOS and Android to test BLE.

Example of a node sending over TX.

[{"id":"e9cc9f512dd79f4e","type":"comment","z":"02da6eb12ee847ca","name":"BLE NUS TX","info":"","x":510,"y":220,"wires":[]},{"id":"02073d826363b4c4","type":"scanner","z":"02da6eb12ee847ca","name":"","timeout":"5000","x":295.60716465541304,"y":285.3214242117747,"wires":[["d8e2310f9a545cba"]]},{"id":"d8e2310f9a545cba","type":"peripheral","z":"02da6eb12ee847ca","name":"Enter MAC of BLE device","mac":"xx:xx:xx:xx:xx:xx","timeout":"10000","x":515.857164655413,"y":285.1713997977122,"wires":[["cf3b4455d484b9b3"],[]]},{"id":"cf3b4455d484b9b3","type":"service","z":"02da6eb12ee847ca","name":"","x":740,"y":280,"wires":[["6735b4f3f0d1b152"]]},{"id":"6735b4f3f0d1b152","type":"switch","z":"02da6eb12ee847ca","name":"Detect NUS Service","property":"_service","propertyType":"msg","rules":[{"t":"eq","v":"6e400001b5a3f393e0a9e50e24dcca9e","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":960,"y":280,"wires":[["52655fe83bfdfb21"]]},{"id":"242210e75083c12e","type":"characteristic out","z":"02da6eb12ee847ca","name":"TX NUS","uuid":"6e400002b5a3f393e0a9e50e24dcca9e","x":680,"y":380,"wires":[]},{"id":"52655fe83bfdfb21","type":"change","z":"02da6eb12ee847ca","name":"jsonESB -> payload","rules":[{"t":"set","p":"payload","pt":"msg","to":"hello, world","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":890,"y":360,"wires":[[]]}]

Link to Adafruits great tutorial. They also have an app for iOS and Android to test BLE.

I hope this helps. Perhaps one day I have time to make a BLE module for Node RED. When security enforces me for instance. Because, there are many open in Noble. :S

2 Likes

I have been busier than expected with a couple of projects at work and have not had time to try this. But before the post closes I wanted to thank everyone for their input and suggestions. I am excited to try a couple of things and I will post any success or failure I have.

1 Like

OK, i my push it totally off-topic.... but I'm using ESP32 and other arduino devices around my home using MQTT to communicate with Node-Red.

MQTT library is available for lots of devices ... even if you want to go with Tasmota devices!

I can highy recommend going with MQTT

I realize this post has been dormant for a while but I have circled back around to trying to get BLE working again.

@Joris6 If I understand the link you provided, do I need a "bluefruit" device to plug into the Raspberry Pi? Other posts in the forum have mentioned using a usb ble dongle plugged into the Pi. Is it a similar concept?

No, I use the Bluetooth on the Pi itself. The Adafruit it my end device the Pi communicates with via the BLE protocol.

I'm assuming the answer is no, but this wouldn't work with non Nordic devices?

Since Arduino Nano 33 BLE has a nrf Nordic chip would it work?

Yes. I don´t own a Arduino Nano 33 BLE, I can´t tell if a library is in use that supports it.
Adafruit has implented the Nordic protocol in their library.

It appears after doing a little research that ESP32 has a library that can utilize the BLE UART protocol. I'm not exactly sure if this is the same as what you mentioned through Nordic but it sounds similar. I have not found a compatible library for Arduino. Even for the Nano 33 BLE which has a nrf Nordic chip.

Either way this is exciting as I might be able to take advantage of this protocol. Do you know if you can still pair the Pi to multiple ESP32's using this BLE UART?

To do that, you need multiple serial interfaces on the Pi. This is possible in a variety of ways from using the Pi's GPIO to multiple serial-to-usb interfaces.

There is a big change the ESP32 uses the Nordic BLE UART protocol. The raspberry Pi has a Bluetooth module built in that support BLE. BLE has no native support voor UART.

You can test BLE UART from Nordic with the app from Nordic.

https://apps.apple.com/us/app/nrf-uart/id614594903

Or with the app from Adafruit called Bluefruit Connect. This is awesome app to quickly scan for BLE devices.

You can pair with multiple devices, but commonly pair with one for one active connection. Especially the very small devices like small microcontrollers and PI.
Just like a BT headset can be paired with multiple devices like laptop and phone, but commonly communicate with one. Except the fancy bigger ones, which can handle 2 or 3 devices.

This will work for some applications, but most of the scenarios I will be dealing with will involve at least two peripheral devices.

I have another thread on this forum about bluetooth but it was supposed to be for help with a specific node-RED package. It has gone cold despite my efforts to keep it alive. So I figured I would pose the question here. If we find an answer that applies to the other thread I will post a link here.

I have had some success with node-red-contrib-generic-ble, I can scan, connect, read, and write properly with no issues. However, I ran a few tests and even with reading and writing every minute or so, the device disconnects after about 6 hours and won't reconnect without re-deploying Node-RED. The node seems to have automatic reconnect, as if I turn off the peripheral device it throws an error, but then attempts to reconnect every time I send a read or write command. So adding my own "reconnect" routine doesn't seem to be of any benefit. I'm not seeing any errors on the Arduino or Pi side.

I also have tried node-red-contrib-noble-ble and node-red-contrib-ble-sense which have both performed worse.

The former scans, connects, and reads fine, but I can't write to the device. The latter scans and connects fine, but I'm having trouble deciphering the output from the "connect" node. I also haven't figured out a way to write a value.

For anyone interested here is a link to that forum page if you want more details and to troubleshoot my code.

Also in addition to trying to figure out all of the above I thought of another idea.

If I were to summarize my experience with BLE so far I would state the following:

  1. I can scan and read data easily in most cases
  2. Scanning and reading advertised data doesn't require a connection
  3. There appear to be a lot of Node-RED packages dealing with scanning and reading data
  4. The main trouble I run into involve staying connected and writing data

With those points in mind I thought, what if I don't treat the Pi like a central device but rather a peripheral? It can advertise data that I want to "write" and then hopefully also still read data back. Then the Arduino/ESP32 can just scan for that advertised data. This way I don't need a connection to complete my tasks. Are there any Node-RED peripheral packages that advertise data rather than write it to a connected device? Up to this point I've assumed it is best to only use one BLE package at a time, but could using more than one be beneficial?

I found the node-red-contrib-epi-bluetooth package which is exactly what I mention in my previous post. It allows you to set up the Pi as a server and allow clients to connect. I have both notify and ble-in nodes working with the Lightblue app on my android phone. I'm going to try now to get an Arduino to talk to these nodes.

Any guidance, thoughts, or explanations about any of the topics/packages in my last few posts will be appreciated.

I was able to communicate to the nodes listed above with an Arduino Nano 33 IoT, but upon reading a little into BLE peripherals I realized this will not work for the specific setup where I need the Pi to be able to write and read to multiple Arduinos. It appears a peripheral can "advertise" to multiple centrals, but only connect to one central at a time.

I also read that it is normal for BLE connections to drop out after a long period of time (>5-8 hours). For my case it might be acceptable to execute a "disconnect/reconnect" every hour to keep a permanent disconnect from happening.

I'm slowly building a better understanding of BLE and specifically BLE with Node-RED and the Pi. Which is the point of this post. I will continue to post my findings in hopes that it might help someone else in the future.

3 Likes

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.