S&B Volcano vaporizer remote control with Pi Pico W
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

scan.py 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env python3
  2. # ----------------------------------------------------------------------------
  3. # Copyright (c) 2023 Thomas Buck (thomas@xythobuz.de)
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # See <http://www.gnu.org/licenses/>.
  16. # ----------------------------------------------------------------------------
  17. # https://github.com/micropython/micropython-lib/blob/master/micropython/bluetooth/aioble/examples/temp_client.py
  18. import uasyncio as asyncio
  19. import aioble
  20. import bluetooth
  21. import sys
  22. async def ble_scan(addr = None, name = "S&B VOLCANO H", timeout = 0.5):
  23. scanner = aioble.scan(int(timeout * 1000.0), interval_us=30000, window_us=30000, active=True)
  24. async with scanner as s:
  25. results = []
  26. async for d in s:
  27. if addr != None:
  28. if addr == d.device.addr_hex():
  29. return d
  30. elif name != None:
  31. if d.name() == name:
  32. return d
  33. else:
  34. results.append(d)
  35. return results
  36. return None