Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError on BLERadio.start_scan() and ble_detailed_scan.py #141

Open
bradjc opened this issue Nov 4, 2021 · 5 comments
Open

ValueError on BLERadio.start_scan() and ble_detailed_scan.py #141

bradjc opened this issue Nov 4, 2021 · 5 comments
Assignees

Comments

@bradjc
Copy link

bradjc commented Nov 4, 2021

I tried running ble_detailed_scan.py and get the following error:

scanning
Traceback (most recent call last):
  File "code.py", line 14, in <module>
  File "adafruit_ble/__init__.py", line 250, in start_scan
ValueError: Prefix buffer must be on the heap

I think the error happens because the example scans for both services advertisements and any advertisement:

for advertisement in ble.start_scan(ProvideServicesAdvertisement, Advertisement):

which the causes the prefixes buffer to be empty:

all_prefix_bytes = tuple(adv.get_prefix_bytes() for adv in advertisement_types)
# If one of the advertisement_types has no prefix restrictions, then
# no prefixes should be specified at all, so we match everything.
prefixes = b"" if b"" in all_prefix_bytes else b"".join(all_prefix_bytes)

That seems to trigger the error here:

https://github.com/adafruit/circuitpython/blob/0dfb7a9a2da1444ebca4b8fff0b88795afede895/shared-bindings/_bleio/Adapter.c#L348-L355

I managed to get the example to work by either removing Advertisement from the scan_start() call, or commenting out the prefix check in _bleio/Adapter.c.

What I'm not sure about is the relevant code doesn't seem to have changed in the last 1.5 years. I'm using CircuitPython from the latest git commit on the micro:bit v2, so perhaps something weird is happening with my setup. But I thought I would open this issue just in case either something is wrong,.

@tannewt tannewt self-assigned this Feb 14, 2022
@kyril96
Copy link

kyril96 commented Nov 16, 2023

I'm seeing this just now on CircuitPython 9.0.4 alpha on an ESP32-S3 QTPY -- with the non-detailed scan example, it just uses ble.start_scan() with no parameters. Going back to CircuitPython 8 I no longer see that message. I'm not sure if this is a known issue or "you're doing it wrong" or if something got re-introduced.

@tannewt
Copy link
Member

tannewt commented Nov 17, 2023

I'm seeing this just now on CircuitPython 9.0.4 alpha on an ESP32-S3 QTPY -- with the non-detailed scan example, it just uses ble.start_scan() with no parameters. Going back to CircuitPython 8 I no longer see that message. I'm not sure if this is a known issue or "you're doing it wrong" or if something got re-introduced.

Please file an issue on CircuitPython if something breaks between versions. Its issues get more investigation than this library usually. https://github.com/adafruit/circuitpython/issues/

@dhalbert
Copy link
Collaborator

I have a fix for this bug as a side effect of some other BLE debuggin I am doing, but I have seen more problems with ESP32-S3 BLE. I cannot get it to connect to anything as a central, and I tried many versions

@kyril96 Were you successfully connecting to a BLE peripheral, or just scanning advertisements?

@kyril96
Copy link

kyril96 commented Nov 20, 2023

@dhalbert With CP 8, I was able to get the advertisement and the "connection" object but getting the HIDService out of it choked. I think the best I was able to do is get a non crash-to-safemode error if I stopped scanning before I tried to get the connection from the advertisement, or with some side fumbling was able to get it to cough up that HIDService wasn't implemented.

@tannewt I popped the CP9 issue up there, we'll see if anyone gets to it. CircuitPython issue 8631.

It seems like what I really want to do (homebrew the thing that the doomscroller or whatever feeds input to) is for now only doable with an nRF that doesn't come any smaller than an ItsyBitsy, or with Arduino or Espressif's own environment.

@dhalbert
Copy link
Collaborator

It appears that service discovery, which happens after connection, never worked. I tested back to 7.3.3 and tested various 8.x.x versions as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants