-
Notifications
You must be signed in to change notification settings - Fork 0
/
BlueTracker.py
75 lines (60 loc) · 2.36 KB
/
BlueTracker.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
__author__ = 'rodtoll'
from BluetoothAdapter import BluetoothAdapter
import gobject as GObject
from dbus.mainloop.glib import DBusGMainLoop
import ISY
import sys
from BluetoothFactory import BluetoothFactory
device_id = "hci0"
station_id = "station"
device_map = {}
def read_config(file_name):
global device_id
global station_id
config_file = open(file_name, "r")
# Header specifying device id is next
config_file.readline()
device_id = config_file.readline()
device_id = device_id.rstrip('\n')
# Header specifying station id is next
config_file.readline()
station_id = config_file.readline()
station_id = station_id.rstrip('\n')
# Header before the individual device entries
config_file.readline()
# read the entries
for config_line in config_file:
config_elements = config_line.split(",")
print("key: "+config_elements[0])
print("value: "+config_elements[1])
device_map[config_elements[0]] = config_elements[1]
config_file.close()
myisy = ISY.Isy(addr="10.0.1.19", userl="admin", userp="ErgoFlat91")
def handle_device_update(device):
action = "=> No change"
if device.address is not None:
if device.address in device_map:
variable_id = device_map[device.address]
action = "=> Updated :"+variable_id
if device.get_is_present():
myisy.var_set_value(variable_id, 1)
else:
myisy.var_set_value(variable_id, 0)
print(station_id+"-[DEVP] Name: ["+device.name+"] Device Update: ["+device.address+"] Present: ["+str(device.get_is_present())+"] RSSI: ["+str(device.rssi)+"] "+action)
def handle_device_property_changed(device):
print(station_id+"-[PROP] Name: ["+device.name+"] Device Update: ["+device.address+"] Present: ["+str(device.get_is_present())+"] RSSI: ["+str(device.rssi)+"]")
if __name__ == "__main__":
DBusGMainLoop(set_as_default=True)
if len(sys.argv) > 1:
config_file_name = sys.argv[1]
else:
config_file_name = "./devices.macbook.cfg"
read_config(config_file_name)
factory = BluetoothFactory()
adapter = factory.get_adapter(device_id)
adapter.set_device_callbacks(handle_device_update,handle_device_property_changed)
adapter.start_discovery()
mainloop = GObject.MainLoop()
mainloop.run()
adapter.stop_discovery()
print "Done!"