Skip to content

Not consistently recognizing ibeacons #415

@furgerf

Description

@furgerf

Hi, I'd like to detect ibeacons with a raspi and ideally range with them. For testing, I'm using two identical beacons, but I'm encountering some issues. Maybe you can help me understand what I'm doing wrong 🙂

Maybe first off - ranging doesn't seem to be implemented here, is there some limitation or is it just a matter of time/priority?

Regardless, I thought I'd start with just reading out some rssi values, to at least get a broad feeling for beacon proximity: using Scanner.start_beacon_scan(on_ibeacon=...) normally works, but I only get an initial callback invocation, presumably because it's only called on new devices. By the looks of it, that's what Scanner.clean_beacons is intended for, so I'm calling that every 10s, expecting to get a new rssi every 10s. (The beacons are configured to advertise every 1s.)

Now, my main issue is that I'm not consistently seeing the beacons. It seems they start disappearing (not re-appearing after cleaning) after running for a while. I verified that the same device still receives advertisements from the beacons (visible in bluetoothctl devices) and I also see them on my smartphone with nRF connect. I'm not quite sure when/why the beacons disappear, but I'm seeing two errors in the logs.

The first seems to be a race condition in the observer (an advertisement is received while determining devices to remove) - if you want I can submit a patch with some locking:

2024-09-06T09:27:53Z: Traceback (most recent call last):
2024-09-06T09:27:53Z:   File "x/app/bluetooth/bluetooth_server.py", line 102, in reset_beacons
2024-09-06T09:27:53Z:     Scanner.clean_beacons()
2024-09-06T09:27:53Z:   File "x/lib/python3.11/site-packages/bluezero/observer.py", line 62, in clean_beacons
2024-09-06T09:27:53Z:     for rm_dev in cls.remove_list:
2024-09-06T09:27:53Z: RuntimeError: Set changed size during iteration

I "feel like" I've been getting that one more frequently a few days ago (but not so much anymore), so I had also experimented with Scanner.stop_scan and adapter.quit.

The other error still pops up frequently, though not regularly - sometimes it appears several times a few seconds apart, sometimes not for a while. Not sure if it's related to beacons not showing up, since it doesn't necessarily seem to correlate.

2024-09-06T09:28:16Z: 2024-09-06 09:28:16,799 ERROR dbus.connection maybe_handle_message:222: Exception in handler for D-Bus signal:
2024-09-06T09:28:16Z: Traceback (most recent call last):
2024-09-06T09:28:16Z:   File "x/lib/python3.11/site-packages/dbus/connection.py", line 218, in maybe_handle_message
2024-09-06T09:28:16Z:     self._handler(*args, **kwargs)
2024-09-06T09:28:16Z:   File "x/lib/python3.11/site-packages/bluezero/adapter.py", line 314, in _interfaces_added
2024-09-06T09:28:16Z:     new_dev = device.Device(
2024-09-06T09:28:16Z:               ^^^^^^^^^^^^^^
2024-09-06T09:28:16Z:   File "x/lib/python3.11/site-packages/bluezero/device.py", line 53, in __init__
2024-09-06T09:28:16Z:     raise ValueError("Cannot find a device: " + device_addr +
2024-09-06T09:28:16Z: ValueError: Cannot find a device: XX:XX:XX:XX:XX:XX using adapter: YY:YY:YY:YY:YY:YY

Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions