-
Notifications
You must be signed in to change notification settings - Fork 0
/
anova_scanner.py
57 lines (45 loc) · 1.52 KB
/
anova_scanner.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
from bluepy import btle
import binascii
def dump_services(dev):
services = sorted(dev.services, key=lambda s: s.hndStart)
for s in services:
if s.hndStart == s.hndEnd:
continue
chars = s.getCharacteristics()
for i, c in enumerate(chars):
props = c.propertiesToString()
if 'READ' in props:
val = c.read()
if c.uuid == btle.AssignedNumbers.device_name:
string = '\'' + \
val.decode('utf-8') + '\''
elif c.uuid == btle.AssignedNumbers.device_information:
string = repr(val)
else:
string = '<s' + binascii.b2a_hex(val).decode('utf-8') + '>'
else:
string = ''
if 'Anova' in string:
print ("%s, MAC: %s" % (string, dev.addr))
class ScanAnova(btle.DefaultDelegate):
def __init__(self):
btle.DefaultDelegate.__init__(self)
def handleDiscovery(self, dev, isNewDev, isNewData):
if dev.rssi < -128:
return
def main():
btle.Debugging = False
scanner = btle.Scanner(0).withDelegate(ScanAnova())
devices = scanner.scan(4)
for d in devices:
if not d.connectable or d.rssi < -128:
continue
try:
dev = btle.Peripheral(d)
dump_services(dev)
dev.disconnect()
except btle.BTLEException:
continue
if __name__ == "__main__":
main()