123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- #!/usr/bin/env python
-
- import simplepyble
- from scan import ble_scan
- import time
-
- serviceUuidVolcano3 = "10100000-5354-4f52-5a26-4249434b454c"
- serviceUuidVolcano4 = "10110000-5354-4f52-5a26-4249434b454c"
-
- def ble_conn(address, adapter):
- dev = ble_scan(address, adapter)
-
- if dev != None:
- address = dev.address()
- print("Connecting to '{}'...".format(address))
- dev.connect()
-
- return dev
-
- def get_current_temp(device):
- val = device.read(serviceUuidVolcano4, "10110001-5354-4f52-5a26-4249434b454c")
- num = int.from_bytes(val, byteorder="little")
- return num / 10.0
-
- def get_target_temp(device):
- val = device.read(serviceUuidVolcano4, "10110003-5354-4f52-5a26-4249434b454c")
- num = int.from_bytes(val, byteorder="little")
- return num / 10.0
-
- def set_target_temp(device, temp):
- val = int(temp * 10.0)
- d = val.to_bytes(4, byteorder="little")
- device.write_request(serviceUuidVolcano4, "10110003-5354-4f52-5a26-4249434b454c", d)
-
- def get_unit_is_fahrenheit(device):
- val = device.read(serviceUuidVolcano3, "1010000d-5354-4f52-5a26-4249434b454c")
- num = int.from_bytes(val, byteorder="little")
- return (num & 0x200) != 0
-
- def get_state(device):
- val = device.read(serviceUuidVolcano3, "1010000c-5354-4f52-5a26-4249434b454c")
- num = int.from_bytes(val, byteorder="little")
- heater = (num & 0x0020) != 0
- pump = (num & 0x2000) != 0
- return (heater, pump)
-
- def set_state(device, state):
- heater, pump = state
- if heater:
- device.write_request(serviceUuidVolcano4, "1011000f-5354-4f52-5a26-4249434b454c", 0)
- else:
- device.write_request(serviceUuidVolcano4, "10110010-5354-4f52-5a26-4249434b454c", 0)
- if pump:
- device.write_request(serviceUuidVolcano4, "10110013-5354-4f52-5a26-4249434b454c", 0)
- else:
- device.write_request(serviceUuidVolcano4, "10110014-5354-4f52-5a26-4249434b454c", 0)
-
- if __name__ == "__main__":
- def test_poll(device):
- temp = get_current_temp(device)
- print("Current Temperature: {}".format(temp))
-
- target = get_target_temp(device)
- print("Target Temperature: {}".format(target))
-
- fahrenheit = get_unit_is_fahrenheit(device)
- if fahrenheit:
- print("Unit is Fahrenheit")
- else:
- print("Unit is Celsius")
-
- heater, pump = get_state(device)
- if heater:
- print("Heater is On")
- else:
- print("Heater is Off")
- if pump:
- print("Pump is On")
- else:
- print("Pump is Off")
-
- def test(address, adapter):
- device = ble_conn(address, adapter)
- if device == None:
- return
-
- try:
- print("Writing...")
- set_target_temp(device, 190.0)
-
- print("Reading...")
- for i in range(0, 5):
- test_poll(device)
- print()
- time.sleep(2.0)
- except:
- print("Disconnecting")
- client.disconnect()
-
- raise
-
- print("Disconnecting")
- client.disconnect()
-
- import sys
-
- adapter = None
- mac = None
- if len(sys.argv) > 1:
- adapter = int(sys.argv[1])
- if len(sys.argv) > 2:
- mac = sys.argv[2]
-
- test(mac, adapter)
|