S&B Volcano vaporizer remote control with Pi Pico W
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

scan.py 1.0KB

12345678910111213141516171819202122232425262728293031
  1. # https://github.com/micropython/micropython-lib/blob/master/micropython/bluetooth/aioble/examples/temp_client.py
  2. import uasyncio as asyncio
  3. import aioble
  4. import bluetooth
  5. import sys
  6. async def ble_scan(addr = None, name = "S&B VOLCANO H", timeout = 0.5):
  7. #print("Scanning for '{}' for {}s...".format(addr, timeout))
  8. scanner = aioble.scan(int(timeout * 1000.0), interval_us=30000, window_us=30000, active=True)
  9. async with scanner as s:
  10. results = []
  11. async for d in s:
  12. #print("Scan: '{}' [{}]".format(d.name(), d.device.addr_hex()))
  13. if addr != None:
  14. if addr == d.device.addr_hex():
  15. return d
  16. elif name != None:
  17. if d.name() == name:
  18. return d
  19. else:
  20. results.append(d)
  21. return results
  22. print("No device found")
  23. return None
  24. if __name__ == "__main__":
  25. dev = asyncio.run(ble_scan())
  26. if dev != None:
  27. print("{}".format(dev.device.addr_hex()))