S&B Volcano vaporizer remote control with Pi Pico W
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

scan.py 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import simplepyble
  2. def ble_scan(addr = None, adapterIndex = 0, timeout = 1):
  3. adapters = simplepyble.Adapter.get_adapters()
  4. if len(adapters) == 0:
  5. print("No adapters found")
  6. return None
  7. adapter = adapters[adapterIndex]
  8. print("Selected adapter: {} [{}]".format(adapter.identifier(), adapter.address()))
  9. # TODO abort scan when found?
  10. print("Scanning for '{}' for {}s...".format(addr, timeout))
  11. adapter.scan_for(timeout * 1000)
  12. peripherals = adapter.scan_get_results()
  13. for peripheral in peripherals:
  14. if addr != None:
  15. if addr == peripheral.address():
  16. return peripheral
  17. else:
  18. if peripheral.identifier() == "S&B VOLCANO H":
  19. return peripheral
  20. print("No device found")
  21. return None
  22. if __name__ == "__main__":
  23. import sys
  24. adapter = None
  25. mac = None
  26. if len(sys.argv) > 1:
  27. adapter = int(sys.argv[1])
  28. if len(sys.argv) > 2:
  29. mac = sys.argv[2]
  30. dev = ble_scan(mac, adapter)
  31. if dev != None:
  32. print("{} {}".format(dev.identifier(), dev.address()))