S&B Volcano vaporizer remote control with Pi Pico W
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/usr/bin/env python
  2. import simplepyble
  3. from scan import ble_scan
  4. import time
  5. serviceUuidVolcano3 = "10100000-5354-4f52-5a26-4249434b454c"
  6. serviceUuidVolcano4 = "10110000-5354-4f52-5a26-4249434b454c"
  7. def ble_conn(address, adapter):
  8. dev = ble_scan(address, adapter)
  9. if dev != None:
  10. address = dev.address()
  11. print("Connecting to '{}'...".format(address))
  12. dev.connect()
  13. return dev
  14. def get_current_temp(device):
  15. val = device.read(serviceUuidVolcano4, "10110001-5354-4f52-5a26-4249434b454c")
  16. num = int.from_bytes(val, byteorder="little")
  17. return num / 10.0
  18. def get_target_temp(device):
  19. val = device.read(serviceUuidVolcano4, "10110003-5354-4f52-5a26-4249434b454c")
  20. num = int.from_bytes(val, byteorder="little")
  21. return num / 10.0
  22. def set_target_temp(device, temp):
  23. val = int(temp * 10.0)
  24. d = val.to_bytes(4, byteorder="little")
  25. device.write_request(serviceUuidVolcano4, "10110003-5354-4f52-5a26-4249434b454c", d)
  26. def get_unit_is_fahrenheit(device):
  27. val = device.read(serviceUuidVolcano3, "1010000d-5354-4f52-5a26-4249434b454c")
  28. num = int.from_bytes(val, byteorder="little")
  29. return (num & 0x200) != 0
  30. def get_state(device):
  31. val = device.read(serviceUuidVolcano3, "1010000c-5354-4f52-5a26-4249434b454c")
  32. num = int.from_bytes(val, byteorder="little")
  33. heater = (num & 0x0020) != 0
  34. pump = (num & 0x2000) != 0
  35. return (heater, pump)
  36. def set_state(device, state):
  37. heater, pump = state
  38. if heater:
  39. device.write_request(serviceUuidVolcano4, "1011000f-5354-4f52-5a26-4249434b454c", 0)
  40. else:
  41. device.write_request(serviceUuidVolcano4, "10110010-5354-4f52-5a26-4249434b454c", 0)
  42. if pump:
  43. device.write_request(serviceUuidVolcano4, "10110013-5354-4f52-5a26-4249434b454c", 0)
  44. else:
  45. device.write_request(serviceUuidVolcano4, "10110014-5354-4f52-5a26-4249434b454c", 0)
  46. if __name__ == "__main__":
  47. def test_poll(device):
  48. temp = get_current_temp(device)
  49. print("Current Temperature: {}".format(temp))
  50. target = get_target_temp(device)
  51. print("Target Temperature: {}".format(target))
  52. fahrenheit = get_unit_is_fahrenheit(device)
  53. if fahrenheit:
  54. print("Unit is Fahrenheit")
  55. else:
  56. print("Unit is Celsius")
  57. heater, pump = get_state(device)
  58. if heater:
  59. print("Heater is On")
  60. else:
  61. print("Heater is Off")
  62. if pump:
  63. print("Pump is On")
  64. else:
  65. print("Pump is Off")
  66. def test(address, adapter):
  67. device = ble_conn(address, adapter)
  68. if device == None:
  69. return
  70. try:
  71. print("Writing...")
  72. set_target_temp(device, 190.0)
  73. print("Reading...")
  74. for i in range(0, 5):
  75. test_poll(device)
  76. print()
  77. time.sleep(2.0)
  78. except:
  79. print("Disconnecting")
  80. client.disconnect()
  81. raise
  82. print("Disconnecting")
  83. client.disconnect()
  84. import sys
  85. adapter = None
  86. mac = None
  87. if len(sys.argv) > 1:
  88. adapter = int(sys.argv[1])
  89. if len(sys.argv) > 2:
  90. mac = sys.argv[2]
  91. test(mac, adapter)