IanHarvey / bluepy

Python interface to Bluetooth LE on Linux
Other
1.58k stars 490 forks source link

Failed to connect to peripheral <my mac address>, addr type: random #495

Open saeidfallah1132 opened 1 year ago

saeidfallah1132 commented 1 year ago

Hi, I am using a python script that is running on Raspberry Pi4 as a scanner and NRF52840-DONGLE as a peripheral. I am not able to connect to the peripheral, I got this error : raise BTLEDisconnectError("Failed to connect to peripheral %s, addr type: %s" % (addr, addrType), rsp) bluepy.btle.BTLEDisconnectError: Failed to connect to peripheral EF:9C:18:21:C7:9C, addr type: random

Could you please help me to fix the issue?

dieser-niko commented 1 year ago

Not an expert but have you tried to use public address type? peripheral = btle.Peripheral(mac_addr, addrType=btle.ADDR_TYPE_PUBLIC

Also if possible, could you share a code snippet?

doug-holtsinger commented 1 year ago

I have code that works with a Pi3B as the Scanner and the nRF52840 Dongle as the Peripheral. Scanner Connect: https://github.com/doug-holtsinger/WirelessSensor/blob/master/Compute/src/AHRS-VISUAL/ahrs-console.py#L703 Peripheral: https://github.com/doug-holtsinger/WirelessSensor/blob/master/Sensor/src/BLE/ble_svcs.cpp#L771 I had to workaround a connect problem by limiting the MTU size on the nRF52840 to 23 bytes, otherwise it would not connect. The Pi3B was sending out garbled packets during the connect phase. Do you have a Bluetooth sniffer? It helps a lot for diagnosing connection issues.