'Bluetooth LE Scan in Python on Raspberry Pi

I am now writing Python scripts to collect BLE advertising packets near my Raspberry Pi 3 B+. Currently, I am using bluepy for BLE scan, but the scanner sporadically hangs. I tried to restart the scanner periodically, but as long as the hang occurs, the following restart throws BTLEDisconnectError. According to related discussions, this issue seems specific to Raspberry Pi.

I wonder if there is a more robust way to perform BLE scan in Python on Raspberry Pi. PyBluez says its BLE functionality remains experimental. I am unsure if socket(AF_BLUETOOTH, ...) is a way out. Scapy seems more for interactive hacking.

It would be great if any workarounds against the "bluepy on RPi" problem (other than updating the RPi's OS) are provided. Great thanks.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source