is possible to implement non blocking wlan scan (especially on esp32 port)? #9828
-
Hello everybody. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
I don't think so. I would personally love to see callbacks on every scan result, similar to the bluetooth IRQ callback system. Which could then be wrapped into an asyncio system. |
Beta Was this translation helpful? Give feedback.
-
I'm a bit late to this question, but in case it's still useful to you (or useful to someone else) I wrap the Adapted excerpt from my code: class WifiManager:
def __init__(self):
self.wlan = network.WLAN(network.STA_IF)
self.wlan.active(True)
self._scan_start = _thread.allocate_lock()
self._scan_start.acquire()
self._scan_complete = asyncio.ThreadSafeFlag()
self._scan_thread = _thread.start_new_thread(self._scan, ())
self._scan_results = None
def _scan(self):
while True:
self._scan_start.acquire()
try:
self._scan_results = self.wlan.scan()
except Exception as exc:
Log.warning("Exception running scan", exc=exc)
self._scan_results = []
self._scan_complete.set()
async def scan(self):
self._scan_start.release()
await self._scan_complete.wait()
self._scan_complete.clear()
return self._scan_results I keep one, long-running background thread to look after scans. This thread is woken up by releasing a |
Beta Was this translation helpful? Give feedback.
I don't think so. I would personally love to see callbacks on every scan result, similar to the bluetooth IRQ callback system. Which could then be wrapped into an asyncio system.