哈啦圈 計數
執行須使用 sudo
$ sudo ~/envs/esp32/bin/python scan.pyscan.py
# execute this by
# (microbit) nano@nano-desktop:~/Data/Esp32/bluepy$ sudo ~/envs/microbit/bin/python scan.py
from bluepy.btle import Scanner, DefaultDelegate
class ScanDelegate(DefaultDelegate):
def __init__(self):
DefaultDelegate.__init__(self)
def handleDiscovery(self, dev, isNewDev, isNewData):
if isNewDev:
print("Discovered device {}", dev.addr)
elif isNewData:
print("Received new data from {}", dev.addr)
scanner = Scanner().withDelegate(ScanDelegate())
devices = scanner.scan(10.0)
for dev in devices:
print("Device {} ({}), RSSI={} dB", dev.addr, dev.addrType, dev.rssi)
for (adtype, desc, value) in dev.getScanData():
print(" {} = {}", desc, value)
notify.py