-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-gatt-client.py
More file actions
48 lines (37 loc) · 840 Bytes
/
test-gatt-client.py
File metadata and controls
48 lines (37 loc) · 840 Bytes
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
#!/usr/bin/python
import sys
import pprint
import dbus.mainloop.glib
from gi.repository import GObject
from bpb import BPB
bpb = None
def cb(evt):
print(evt['id'])
if (evt['id'] == 'device'):
pprint.pprint(evt['data'])
def main():
global bpb
device_list = []
if len(sys.argv) <= 1:
print('put target addr')
sys.exit()
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bpb = BPB(cb)
device_list = bpb.get_device_list()
if not device_list:
print('unkwon device')
sys.exit()
for d in device_list:
if (sys.argv[1] == d['Address']):
bpb.connect(sys.argv[1])
else:
print('unkown device')
sys.exit()
mainloop = GObject.MainLoop()
mainloop.run()
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
bpb.disconnect(sys.argv[1])
pass