IanHarvey / bluepy

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

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

Open saeidfallah1132 opened 2 years ago

saeidfallah1132 commented 2 years 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 2 years 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 2 years 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.

dheerajluffy commented 4 months ago

having the same issue here with pi4 trying to connect to nrf51822 , found any solution?

dieser-niko commented 4 months ago

@dheerajluffy please provide a code snippet, maybe I can help