Skip to content

Instantly share code, notes, and snippets.

@bgloh
Created June 8, 2017 04:14
Show Gist options
  • Save bgloh/3c7dd0c754a0b596e8ef6225199adc1e to your computer and use it in GitHub Desktop.
Save bgloh/3c7dd0c754a0b596e8ef6225199adc1e to your computer and use it in GitHub Desktop.
ble scan example using bluepy, bluez, and raspberry pi
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 %s (%s), RSSI=%d dB" % (dev.addr, dev.addrType, dev.rssi)
for (adtype, desc, value) in dev.getScanData():
print " %s = %s" % (desc, value)
@bgloh
Copy link
Author

bgloh commented Jun 8, 2017

to run
sudo python ble_scan_example.py

@eighta
Copy link

eighta commented Aug 12, 2020

Thank you for the example (I started to learn BLE) :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment