|
@@ -9,6 +9,17 @@ from scan import ble_scan
|
9
|
9
|
serviceUuidVolcano3 = bluetooth.UUID("10100000-5354-4f52-5a26-4249434b454c")
|
10
|
10
|
serviceUuidVolcano4 = bluetooth.UUID("10110000-5354-4f52-5a26-4249434b454c")
|
11
|
11
|
|
|
12
|
+service3 = None
|
|
13
|
+service4 = None
|
|
14
|
+characteristic1 = None
|
|
15
|
+characteristic3 = None
|
|
16
|
+characteristicd = None
|
|
17
|
+characteristicc = None
|
|
18
|
+characteristicf = None
|
|
19
|
+characteristic10 = None
|
|
20
|
+characteristic13 = None
|
|
21
|
+characteristic14 = None
|
|
22
|
+
|
12
|
23
|
async def ble_conn(address):
|
13
|
24
|
dev = await ble_scan(address)
|
14
|
25
|
|
|
@@ -16,23 +27,52 @@ async def ble_conn(address):
|
16
|
27
|
address = dev.device.addr_hex()
|
17
|
28
|
print("Connecting to '{}'...".format(address))
|
18
|
29
|
connection = await dev.device.connect()
|
|
30
|
+ await cache_services_characteristics(connection)
|
19
|
31
|
return connection
|
20
|
32
|
|
21
|
33
|
return None
|
22
|
34
|
|
|
35
|
+async def cache_services_characteristics(device):
|
|
36
|
+ global service3, service4
|
|
37
|
+ global characteristic1, characteristic3
|
|
38
|
+ global characteristicd, characteristicc
|
|
39
|
+ global characteristicf, characteristic10
|
|
40
|
+ global characteristic13, characteristic14
|
|
41
|
+
|
|
42
|
+ service3 = await device.service(serviceUuidVolcano3)
|
|
43
|
+ service4 = await device.service(serviceUuidVolcano4)
|
|
44
|
+
|
|
45
|
+ uuid1 = bluetooth.UUID("10110001-5354-4f52-5a26-4249434b454c")
|
|
46
|
+ characteristic1 = await service4.characteristic(uuid1)
|
|
47
|
+
|
|
48
|
+ uuid3 = bluetooth.UUID("10110003-5354-4f52-5a26-4249434b454c")
|
|
49
|
+ characteristic3 = await service4.characteristic(uuid3)
|
|
50
|
+
|
|
51
|
+ uuidd = bluetooth.UUID("1010000d-5354-4f52-5a26-4249434b454c")
|
|
52
|
+ characteristicd = await service3.characteristic(uuidd)
|
|
53
|
+
|
|
54
|
+ uuidc = bluetooth.UUID("1010000c-5354-4f52-5a26-4249434b454c")
|
|
55
|
+ characteristicc = await service3.characteristic(uuidc)
|
|
56
|
+
|
|
57
|
+ uuidf = bluetooth.UUID("1011000f-5354-4f52-5a26-4249434b454c")
|
|
58
|
+ characteristicf = await service4.characteristic(uuidf)
|
|
59
|
+
|
|
60
|
+ uuid10 = bluetooth.UUID("10110010-5354-4f52-5a26-4249434b454c")
|
|
61
|
+ characteristic10 = await service4.characteristic(uuid10)
|
|
62
|
+
|
|
63
|
+ uuid13 = bluetooth.UUID("10110013-5354-4f52-5a26-4249434b454c")
|
|
64
|
+ characteristic13 = await service4.characteristic(uuid13)
|
|
65
|
+
|
|
66
|
+ uuid14 = bluetooth.UUID("10110014-5354-4f52-5a26-4249434b454c")
|
|
67
|
+ characteristic14 = await service4.characteristic(uuid14)
|
|
68
|
+
|
23
|
69
|
async def get_current_temp(device):
|
24
|
|
- service = await device.service(serviceUuidVolcano4)
|
25
|
|
- uuid = bluetooth.UUID("10110001-5354-4f52-5a26-4249434b454c")
|
26
|
|
- characteristic = await service.characteristic(uuid)
|
27
|
|
- val = await characteristic.read()
|
|
70
|
+ val = await characteristic1.read()
|
28
|
71
|
num = int.from_bytes(val, "little")
|
29
|
72
|
return num / 10.0
|
30
|
73
|
|
31
|
74
|
async def get_target_temp(device):
|
32
|
|
- service = await device.service(serviceUuidVolcano4)
|
33
|
|
- uuid = bluetooth.UUID("10110003-5354-4f52-5a26-4249434b454c")
|
34
|
|
- characteristic = await service.characteristic(uuid)
|
35
|
|
- val = await characteristic.read()
|
|
75
|
+ val = await characteristic3.read()
|
36
|
76
|
num = int.from_bytes(val, "little")
|
37
|
77
|
return num / 10.0
|
38
|
78
|
|
|
@@ -41,10 +81,7 @@ async def set_target_temp(device, temp):
|
41
|
81
|
while attempts > 0:
|
42
|
82
|
val = int(temp * 10.0)
|
43
|
83
|
d = val.to_bytes(4, "little")
|
44
|
|
- service = await device.service(serviceUuidVolcano4)
|
45
|
|
- uuid = bluetooth.UUID("10110003-5354-4f52-5a26-4249434b454c")
|
46
|
|
- characteristic = await service.characteristic(uuid)
|
47
|
|
- await characteristic.write(d)
|
|
84
|
+ await characteristic3.write(d)
|
48
|
85
|
|
49
|
86
|
attempts -= 1
|
50
|
87
|
|
|
@@ -54,18 +91,12 @@ async def set_target_temp(device, temp):
|
54
|
91
|
raise RuntimeError("Could not set target temperature")
|
55
|
92
|
|
56
|
93
|
async def get_unit_is_fahrenheit(device):
|
57
|
|
- service = await device.service(serviceUuidVolcano3)
|
58
|
|
- uuid = bluetooth.UUID("1010000d-5354-4f52-5a26-4249434b454c")
|
59
|
|
- characteristic = await service.characteristic(uuid)
|
60
|
|
- val = await characteristic.read()
|
|
94
|
+ val = await characteristicd.read()
|
61
|
95
|
num = int.from_bytes(val, "little")
|
62
|
96
|
return (num & 0x200) != 0
|
63
|
97
|
|
64
|
98
|
async def get_state(device):
|
65
|
|
- service = await device.service(serviceUuidVolcano3)
|
66
|
|
- uuid = bluetooth.UUID("1010000c-5354-4f52-5a26-4249434b454c")
|
67
|
|
- characteristic = await service.characteristic(uuid)
|
68
|
|
- val = await characteristic.read()
|
|
99
|
+ val = await characteristicc.read()
|
69
|
100
|
num = int.from_bytes(val, "little")
|
70
|
101
|
heater = (num & 0x0020) != 0
|
71
|
102
|
pump = (num & 0x2000) != 0
|
|
@@ -74,26 +105,14 @@ async def get_state(device):
|
74
|
105
|
async def set_state(device, state):
|
75
|
106
|
heater, pump = state
|
76
|
107
|
if heater == True:
|
77
|
|
- service = await device.service(serviceUuidVolcano4)
|
78
|
|
- uuid = bluetooth.UUID("1011000f-5354-4f52-5a26-4249434b454c")
|
79
|
|
- characteristic = await service.characteristic(uuid)
|
80
|
|
- await characteristic.write(int(0).to_bytes(1, "little"))
|
|
108
|
+ await characteristicf.write(int(0).to_bytes(1, "little"))
|
81
|
109
|
elif heater == False:
|
82
|
|
- service = await device.service(serviceUuidVolcano4)
|
83
|
|
- uuid = bluetooth.UUID("10110010-5354-4f52-5a26-4249434b454c")
|
84
|
|
- characteristic = await service.characteristic(uuid)
|
85
|
|
- await characteristic.write(int(0).to_bytes(1, "little"))
|
|
110
|
+ await characteristic10.write(int(0).to_bytes(1, "little"))
|
86
|
111
|
|
87
|
112
|
if pump == True:
|
88
|
|
- service = await device.service(serviceUuidVolcano4)
|
89
|
|
- uuid = bluetooth.UUID("10110013-5354-4f52-5a26-4249434b454c")
|
90
|
|
- characteristic = await service.characteristic(uuid)
|
91
|
|
- await characteristic.write(int(0).to_bytes(1, "little"))
|
|
113
|
+ await characteristic13.write(int(0).to_bytes(1, "little"))
|
92
|
114
|
elif pump == False:
|
93
|
|
- service = await device.service(serviceUuidVolcano4)
|
94
|
|
- uuid = bluetooth.UUID("10110014-5354-4f52-5a26-4249434b454c")
|
95
|
|
- characteristic = await service.characteristic(uuid)
|
96
|
|
- await characteristic.write(int(0).to_bytes(1, "little"))
|
|
115
|
+ await characteristic14.write(int(0).to_bytes(1, "little"))
|
97
|
116
|
|
98
|
117
|
if __name__ == "__main__":
|
99
|
118
|
async def test_poll(device):
|