Created
June 8, 2017 04:14
-
-
Save bgloh/3c7dd0c754a0b596e8ef6225199adc1e to your computer and use it in GitHub Desktop.
ble scan example using bluepy, bluez, and raspberry pi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for the example (I started to learn BLE) :-)