Need Help with Bluetooth Connection Issues on Raspberry Pi

January 3, 2024, 10:44

sanderzw

Hi everyone, I'm working on a project with a Raspberry Pi where I'm using Python to connect to cycling speed and cadence sensors via Bluetooth. The program uses asyncio and bleak for handling the Bluetooth connections. My script successfully connects to the sensors and reads data on the first attempt, but I encounter connection problems on subsequent tries. Here's a brief overview of what my code does: Connects to two cycling sensors using their Bluetooth addresses. Reads cycling speed and cadence data for 30 seconds. Disconnects from the sensors. On the first run, everything works as expected. However, when I try to run the program again, it fails to connect to the sensors. The error I receive is not very detailed, making it hard to diagnose the problem. I suspect the issue might be related to how the Bluetooth connection is being handled, or perhaps the sensors are not properly resetting after the first connection. I'm not sure if it's a problem with the Raspberry Pi's Bluetooth interface, an issue with the bleak library, or something else. Has anyone experienced similar issues or have any insights into what might be going wrong? Any help or suggestions would be greatly appreciated!

k9t33n

could you share your code, error and sensors?

sanderzw

Sander@raspberrypi:~/Desktop/magene $ python ConnectDevices.py Executing <Task pending name='Task-1' coro=<run() running at /home/Sander/Desktop/magene/ConnectDevices.py:40> wait_for=<Future pending cb=[Task.task_wakeup()] created at /usr/lib/python3.11/asyncio/base_events.py:427> cb=[_run_until_complete_cb() at /usr/lib/python3.11/asyncio/base_events.py:180] created at /usr/lib/python3.11/asyncio/tasks.py:670> took 0.127 seconds Error connecting to FB:5D:42:68:A8:44: Failed to connect to FB:5D:42:68:A8:44. Exiting.

sanderzw

and im using the magene S3+ Cadense sensor