S&B Volcano vaporizer remote control with Pi Pico W
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

scan.py 726B

1234567891011121314151617181920212223
  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. scanner = aioble.scan(int(timeout * 1000.0), interval_us=30000, window_us=30000, active=True)
  8. async with scanner as s:
  9. results = []
  10. async for d in s:
  11. if addr != None:
  12. if addr == d.device.addr_hex():
  13. return d
  14. elif name != None:
  15. if d.name() == name:
  16. return d
  17. else:
  18. results.append(d)
  19. return results
  20. return None