-
Notifications
You must be signed in to change notification settings - Fork 0
/
scanble.py
53 lines (37 loc) · 1.21 KB
/
scanble.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
# import requests
# requests.post("http://server:1337/beacons/touch", data=data_payload)
import sys
import queue
import send
import blescan
import bluetooth._bluetooth as bluez
import keepalive
import diagnostics
def start_scanner():
dev_id = 0
try:
sock = bluez.hci_open_dev(dev_id)
print("ble thread started")
except:
print("error accessing bluetooth device...")
sys.exit(1)
blescan.hci_le_set_scan_parameters(sock)
blescan.hci_enable_le_scan(sock)
return sock
def scan_loop(sock):
while True:
returned_list = blescan.parse_events(sock, 10)
if len(returned_list) > 0:
keepalive.set_last_run()
for beacon in returned_list:
queue.queue_beacon(beacon)
keepalive_message = keepalive.check_keepalive()
if keepalive_message is not None:
send.send(1, "KA:%s", keepalive_message)
if __name__ == "__main__":
send.send(1, "Starting BLE watcher")
device, size, used, available, percent, mountpoint = diagnostics.disk_space()
send.send(1, "m:%s a:%s s:%s p:%s" % (mountpoint, available, size, percent))
keepalive.initialise()
sock = start_scanner()
scan_loop(sock)