-
Notifications
You must be signed in to change notification settings - Fork 3
/
discover.py
executable file
·41 lines (32 loc) · 1.22 KB
/
discover.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# -*- coding: utf-8 -*-
#
#
from bluepy import btle
class ScanDelegate(btle.DefaultDelegate):
def __init__(self):
btle.DefaultDelegate.__init__(self)
def handleDiscovery(self, dev, isNewDev, isNewData):
if not dev.addr == 'f1:05:a5:9c:2e:9b':
return
if isNewDev:
print "Discovered device", dev.addr
print "Device %s (%s), RSSI=%d dB" % (dev.addr, dev.addrType, dev.rssi)
print dev.getScanData()
for (adtype, desc, value) in dev.getScanData():
print " %s = %s" % (desc, value)
elif isNewData:
print "Received new data from", dev.addr
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)
# else:
# print "Discovered device", dev.addr
scanner = btle.Scanner(0).withDelegate(ScanDelegate())
scanner.start()
while True:
scanner.process(30)
scanner.stop()
# 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)