S&B Volcano vaporizer remote control with Pi Pico W
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

poll.py 2.9KB

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