Description
From the guide by John Park at https://learn.adafruit.com/bluetooth-le-broadcastnet-sensor-node-raspberry-pi-wifi-bridge/overview ......
Following through the guide and executing on an upto date Pi OS on Zero W everything goes fine until you actually execute python3 ble_broadcastnet_blinka_bridge.py
After this , instead of finding the Clue (which has the prescribed basic broadcast script running and is tested with both CP5.3 and CP5.4BETA), the output is stuck at
This is BroadcastNet bridge: b827eb2d289a
Fetching existing feeds.
{}
scanning
until after about 15 minutes an error (memory error) stops python 3.7 running on the Pi Zero W and the following extra output is given :
Traceback (most recent call last):
File "ble_broadcastnet_blinka_bridge.py", line 113, in <module>
adafruit_ble_broadcastnet.AdafruitSensorMeasurement, interval=0.5
File "/home/pi/.local/lib/python3.7/site-packages/adafruit_ble/__init__.py", line 243, in start_scan
active=active,
File "/home/pi/.local/lib/python3.7/site-packages/_bleio/adapter_.py", line 201, in start_scan
prefixes, timeout=timeout, minimum_rssi=minimum_rssi, active=active,
File "/home/pi/.local/lib/python3.7/site-packages/_bleio/adapter_.py", line 299, in _start_scan_hcitool
buffered, prefixes, minimum_rssi, active
File "/home/pi/.local/lib/python3.7/site-packages/_bleio/adapter_.py", line 261, in _parse_hcidump_data
if scan_entry.matches(prefixes, all=False):
File "/home/pi/.local/lib/python3.7/site-packages/_bleio/scan_entry.py", line 79, in matches
fields = self._advertisement_fields
File "/home/pi/.local/lib/python3.7/site-packages/_bleio/scan_entry.py", line 138, in _advertisement_fields
fields.append(self._advertisement_bytes[idx + 1 : idx + field_length])
MemoryError
This same fault was raised by another use in Adafruit Customer forums in MArch at https://forums.adafruit.com/viewtopic.php?f=50&t=163964 and by myself earlier today at https://forums.adafruit.com/viewtopic.php?f=65&t=166701
Would like to get this to work, and given I can see the CLUE in a bluetooth scan from Bluefruit Connect iOS app I'm at a loss as to whether this is down to Adafruit_CircuitPython_BLE_BroadcastNet or the CP library adafruit_ble_broadcastnet.mpy
Activity
tannewt commentedon Jun 25, 2020
Hi hi, I'm using this at my house and wrote it originally. Sorry I didn't see those posts, I only look in the CircuitPython forum.
Does
hcidump
show anything if you run it at the same time as the bridge Python is going?wildestpixel commentedon Jun 25, 2020
Hi,
The output seems to mirror that of the python script as in seeing nothing in a scan
and nothing else unfortunately
Conversely - to know Bluetooth is working on the device, albeit not through the tools used for this CP example , I checked
bluetoothctl
and got a working scanDoesn't see the Clue in this scan although I'd imagine its broadcasting in a non-pairable state.
kevinjwalters commentedon Jun 25, 2020
Does the python process bloat over time? Watching it in
top
or similar might be interesting to see if it's gradual growth or some werid spurt.dhalbert commentedon Jun 25, 2020
EDIT: SEE BELOW re
hcitool lescan --duplicates
I reproduced the essence of this problem, also on a freshly installed Pi Zero W. I installed the latest
bluez-hcidump
, and also gavehcitool
andhcidump
the proper permissions.RPi Zero W, v5.50: If I run
hcitool lescan
in one terminal andhcidump
in another, both will print a small number of advertisements and then stop. Tens of seconds can go by before another small batch of advertisements is printed. I repeated this with both running undersudo
, just to make sure, and the problem still exists. Both are version 5.50.If I initiate the scan with
bluetoothctl ... scan on
I see more advertisements, though they are still sporadic.RPi 4: Same problem; I thought it might be the weak processor on the RPi zero.
x64 Ubuntu 20.04, v5.53: By comparison, running the same commands on an adjacent x64 Ubuntu 20.04 machine prints advertisements continuously, in my rich Bluetooth environment. On this machine, the commands are version 5.53.
I will try an Ubuntu build on an RPi, since I can get up to v5.53.
EDIT: bluetooth on RPi under ubuntu is a rathole. You need to install
pi-bluetooth
, but then you lose the serial console.wildestpixel commentedon Jun 25, 2020
Htop sees the python process running over 95% cpu on the zero w and hcitool lescan forms many duplicates
tannewt commentedon Jun 25, 2020
Does
dmesg
give any errors? On some versions of Pi3 I know the UART to the BLE modules is clocked too fast and causes dmesg errors.dhalbert commentedon Jun 25, 2020
No errors in dmesg or syslog, but I realize that I forgot to do
hcitool lescan --duplicates
. Once I do that on the RPi Zero W, I see plenty of traffic.I'm a little confused as to why I didn't have to do that on the Ubuntu x64 box. When I was testing
hcitool
for another reason last week, I was doing that.dhalbert commentedon Jun 25, 2020
For
bluetoothctl
this will present duplicate advertisements:dhalbert commentedon Jun 25, 2020
@wildestpixel did you follow the instructions in the guide here about adding your user to the
bluetooth
group, and then running some other commands to makehcitool
andhcidump
privileged? If you don't do that, then duplicate advertisements will be suppressed, and you will see little traffic.wildestpixel commentedon Jun 25, 2020
Yes - all of the following
and user
pi
is present in thebluetooth
user groupRef my dmesg , no bluetooth errors
However some errors elsewhere , look wlan related
And this is a very clean install of latest PI OS, just apt updated and upgraded and the guide followed.
tennesteve commentedon Jul 29, 2020
Hi - I've been attempting the same project with a new CLUE and fresh install on Raspberry Pi 4 and get a similar response...
`
pi@YobiSenseAlpha:~/Adafruit_CircuitPython_BLE_BroadcastNet/examples $ python3 ble_broadcastnet_blinka_bridge.py
This is BroadcastNet bridge: dca63251a708
Fetching existing feeds.
{}
scanning
Traceback (most recent call last):
File "ble_broadcastnet_blinka_bridge.py", line 113, in
adafruit_ble_broadcastnet.AdafruitSensorMeasurement, interval=0.5
File "/home/pi/.local/lib/python3.7/site-packages/adafruit_ble/init.py", line 249, in start_scan
active=active,
File "/home/pi/.local/lib/python3.7/site-packages/bleio/adapter.py", line 201, in start_scan
prefixes, timeout=timeout, minimum_rssi=minimum_rssi, active=active,
File "/home/pi/.local/lib/python3.7/site-packages/bleio/adapter.py", line 299, in _start_scan_hcitool
buffered, prefixes, minimum_rssi, active
File "/home/pi/.local/lib/python3.7/site-packages/bleio/adapter.py", line 261, in _parse_hcidump_data
if scan_entry.matches(prefixes, all=False):
File "/home/pi/.local/lib/python3.7/site-packages/_bleio/scan_entry.py", line 92, in matches
fields = self._advertisement_fields
File "/home/pi/.local/lib/python3.7/site-packages/_bleio/scan_entry.py", line 151, in _advertisement_fields
fields.append(self._advertisement_bytes[idx + 1 : idx + field_length])
MemoryError
`
I'm relatively new so don't have the expertise of the author, but was curious to know if there has been a resolution yet?
wildestpixel commentedon Jul 30, 2020
As this is tagged as a bug, once fixed it will be referenced here. Maybe days, maybe months, it maybe it’s dependant on the actions of other individuals or packages that Adafruit have no direct control over.
leadmocha commentedon Jul 30, 2020
So looking at _bleio/scan_entry.py around line 151, I printed out the list of bytes that it receives from the Clue and see what causes it to enter an infinite loop inside a while loop that looks at index idx.
So, here is an example:
self._advertisement_bytes has 30 bytes: 0x1d 0xff 0x22 0x8 0x6 0x4 0xa 0x30 0x35 0xf6 0x41 0xe 0x1 0xa 0xf4 0x24 0x3a 0x41 0x24 0x3a 0xa3 0xc0 0x34 0x87 0x85 0x41 0x3 0x3 0x0 0x0
First one should be the length, but sice 0x1d == 29, it only increments idx by 29. Then it looks at the last byte, which is 0, so it sits there incrementing the index by zero. All the while it is appending 0 to a list until it runs out of memory and crashes.
That's as far as I got. I don't know enough about the libraries to understand if it's the Clue sending the wrong number of bytes, or the raspberry pi reading the last byte wrong.