BLE Intermittent Crashing

I have another post on the forum called "Help with Bluetooth" where I discuss general tips for getting a Bluetooth project to work. I hope I'm not violating the forum rules by creating another post as this is also about Bluetooth but this post involves trying to solve an error.

I am using a Raspberry Pi (RPI OS Bullseye) running Node-RED (v3.0.0) to communicate to an Arduino Nano 33 IOT microcontroller over BLE. I am using node-red-contrib-generic-ble v4.0.3, and the ArduinoBLE library (specifically the LEDCallback example).

I can connect, read, and write successfully with no issues, for a while. I will post the flow if it is helpful but I have one characteristic that turns off and on an LED on the Arduino. I read the state of the characteristic once every two seconds.

This will run with no problems for about 5 minutes or so, then node-RED crashes and reboots and I lose connection to my Arduino and I have to manually stop and restart node-RED to re-establish a connection. I have tried lowering the frequency of the read to once every 30 seconds but for my case I can't lower it any further. I will post the log I see in the command window with the error below.

If there is another node package or a better way to achieve BLE communication from the Pi to Arduino I would be interested.

Thank you!

Starting as a systemd service.
11 Aug 13:22:54 - [info]
Welcome to Node-RED
11 Aug 13:22:54 - [info] Node-RED version: v3.0.0
11 Aug 13:22:54 - [info] Node.js  version: v16.16.0
11 Aug 13:22:54 - [info] Linux 5.15.32-v7l+ arm LE
11 Aug 13:22:55 - [info] Loading palette nodes
11 Aug 13:22:58 - [info] Dashboard version 3.1.7 started at /ui
11 Aug 13:22:58 - [info] Settings file  : /home/mtg/.node-red/settings.js
11 Aug 13:22:58 - [info] Context store  : 'default' [module=memory]
11 Aug 13:22:58 - [info] User directory : /home/mtg/.node-red
11 Aug 13:22:58 - [info] Projects directory: /home/mtg/.node-red/projects
11 Aug 13:22:58 - [info] Server now running at
11 Aug 13:22:58 - [info] Active project : Auto_Test_Panel
11 Aug 13:22:58 - [info] Flows file     : /home/mtg/.node-red/projects/Auto_Test_Panel/flow.json
11 Aug 13:22:58 - [warn] Using unencrypted credentials
11 Aug 13:22:58 - [info] Starting flows
11 Aug 13:22:58 - [info] Started flows
11 Aug 13:22:58 - [info] [GenericBLE] Start BLE scanning
11 Aug 13:33:49 - [red] Uncaught Exception:
11 Aug 13:33:49 - [error] DBusError: Connection ":1.70" is not allowed to add more match rules (increase limits in configuration file if required; max_match_rules_per_connection=512)
    at _methodReturnHandlers.<computed> (/home/mtg/.node-red/node_modules/dbus-next/lib/bus.js:339:27)
    at handleMessage (/home/mtg/.node-red/node_modules/dbus-next/lib/bus.js:98:11)
    at EventEmitter.<anonymous> (/home/mtg/.node-red/node_modules/dbus-next/lib/bus.js:147:9)
    at EventEmitter.emit (node:events:527:28)
    at /home/mtg/.node-red/node_modules/dbus-next/lib/connection.js:112:14
    at Socket.<anonymous> (/home/mtg/.node-red/node_modules/dbus-next/lib/message.js:63:9)
    at Socket.emit (node:events:527:28)
    at emitReadable_ (node:internal/streams/readable:578:12)
    at processTicksAndRejections (node:internal/process/task_queues:82:21)
nodered.service: Main process exited, code=exited, status=1/FAILURE
nodered.service: Failed with result 'exit-code'.
nodered.service: Consumed 38.421s CPU time.
nodered.service: Scheduled restart job, restart counter is at 1.
Stopped Node-RED graphical event wiring tool.
nodered.service: Consumed 38.421s CPU time.

This appears not to be a BT problem at all but rather a modbus one.

I think this is DBus rather than Modbus. I believe that DBus may be involved when using bluetooth hardware.

Oops, yes my bad. Too used to seeing modbus in the comments these days :slight_smile:

So what does this mean? And is there a way to keep the DBus from crashing?

I was going to suggest asking on the node's github page, but since the author has not responded to any issues raised there since January 2021 I think that may be pointless. It appears the node is no longer supported. I don't know if there is a better one.

Maybe this can be used, I only use the scanner part.

@Colin Thank you for the information. It is frustrating that none of the BLE modules appear to be maintained. I know in my other post a debate broke out on whether BLE is even worth pursuing, but in my case I would like to try to make it work. This is the farthest I've gotten with any of the BLE packages.

@Frida While waiting for a response to this thread I tried the package you mentioned and I had no trouble scanning and connecting to my device. But I found the response to be rather bulky and I haven't been able to write a value to the characteristic. I can read it, but not write. Also in a past project I remember having issues with the connect node randomly disconnecting from the Arduino, and only a shutdown and restart of Node-RED would allow it to connect again.

I realize that BLE is a pain to develop and interface with but I wish there was a straightforward way to comminicate. I'm also going to try node-red-contrib-noble-bluetooth in hopes that it will work.

If I'm out of luck with any of the built in functions of Node-RED would any of the following be possible?

  1. Use an external npm package/module with a function node

  2. Interface with a Linux/Python script using an exec node

  3. Tie a BLE device to a serial port and use the Serial nodes

I may be somewhat bias but none of my experiments with BT over the years have gone well. Also, I note from many years of enterprise IT experience that even vendors with very deep pockets can struggle to deal with the bizarre thing that is BT.

I've heard many echo your sentiment, here and elsewhere.

The part that frustates me specifically is that I haven't had issues with BLE between Arduinos or ESP32s. I only started experiencing issues when I involve the Pi. But I've only tried Node-RED specific solutions. It also seems that what I am trying to do seems very basic, but even that won't work reliably.

I guess I'm just in denial. I don't really have a reason not to use an Arduino or ESP32 as a gateway between BLE to Serial, other than stubborness. And with the ESP32 I can just use ESP-NOW instead of BLE altogether.

I just wanted to see if there was an approach using the Pi's builtin BLE capabilities. Whether through Node-RED or something I can expose to Node-RED.

Have certainly had some issues. I think that (at least for early models), trying to have both BT and wifi active together tended to make the device unstable I believe.

You could maybe see if anyone in the Python world has had better success? You could then either call to Python directly or create a small BT server and interface to Node-RED.

If that's the case then I at the very least can have a Serial connection.

Where would you recommend reaching out for Python help?

Might be better now, I've not tried for a long time.

Hmm, not sure really, I stopped using Python regularly (and PHP completely!) when I started using Node.js. I've done a bit more with it recently for a variety of reasons but only really basic stuff I'm afraid. Do let us know if you find a good and helpful Python forum though, always useful :smiley:

I'm going to assuming chasing the Python route will be better than chasing Node.js or Linux?

Would it be inappropriate if I opened a new thread on this forum but specifically asked about Python handling bluetooth and calling from Node-Red?

Sorry , I can't really say. Too many unknowns.

Not so much about the Python but interfacing to NR is fine.

Ok thank you all for your help.

I think my plan of attack is

  1. Try the node-red-contrib-noble-bluetooth and node-red-contrib-ble-sense packages

  2. Try to find a Python route to handle the bluetooth and then find a way to expose it to Node-RED

  3. Give up

I will post any success I find.

I have an important update.

I have not been able to work on the project today but while away from my computer I've been working in some reading and re-visited the page for node-red-contrib-generic-ble. I read the section "Installation Note (Linux)" and it jogged my memory.

I glanced over this initially because when I worked on a Bluetooth project back in March I had done this. But I since had to wipe my Pi and had not done this on the new install. Upon doing this I have not had the error...SO FAR. Previously I was getting the error within 15-30 minutes. It has been almost 2 hours as of now and the error has not happened.

I am going to let this run over night and see if the error stays away. If so, I will rejoice and mark a solution.

What was it in there that you had not done the first time?

sudo usermod -G bluetooth -a pi

I was doing a lot of different things trying to make BLE work for a project back in March and was using the same Pi for development. I had tried to get this package working and had ran this command when i first installed the package. I decided to go a different direction for that project and halted any BLE work.

Around June I wrapped up that project and wiped my Pi and did a fresh OS install. I had not executed the above command on the new install.