Hi
I am working on a a WiFi localization project.
With the excellent uasyncio module, I log data from several sensors including gps.
In addition I want to log wireless network scan's. Is it possible make scan's asynchronously? Now it is blocking the rest of the functions.
Also I'd like to have a look at the code for wlan scanning to get a better understanding.
Where is the source located? I am using the ESP32.
asynchronous wlan scans
Re: asynchronous wlan scans
I don't know how it works, but it looks like the code you're after can be found here:
https://github.com/micropython/micropyt ... #L439-L473
https://github.com/micropython/micropyt ... #L439-L473
Re: asynchronous wlan scans
Thanks jcw. That looks like the part where the scanning happens.
For the esp8266, this ardruino example from shows asynchronous scanning for networks.
https://arduino-esp8266.readthedocs.io/ ... mples.html
How would you write equivalents for WiFi.scanNetworks() and WiFi.scanComplete() for micropython?
For the esp8266, this ardruino example from shows asynchronous scanning for networks.
https://arduino-esp8266.readthedocs.io/ ... mples.html
Code: Select all
// trigger Wi-Fi network scan
if (currentMillis - lastScanMillis > SCAN_PERIOD)
{
WiFi.scanNetworks(true);
Serial.print("\nScan start ... ");
lastScanMillis = currentMillis;
}
// print out Wi-Fi network scan result uppon completion
int n = WiFi.scanComplete();
if(n >= 0)
{
Serial.printf("%d network(s) found\n", n);
for (int i = 0; i < n; i++)
{
Serial.printf("%d: %s, Ch:%d (%ddBm) %s\n", i+1, WiFi.SSID(i).c_str(), WiFi.channel(i), WiFi.RSSI(i), WiFi.encryptionType(i) == ENC_TYPE_NONE ? "open" : "");
}
WiFi.scanDelete();
Re: asynchronous wlan scans
Dunno, sorry.
Re: asynchronous wlan scans
There's a couple of options here --
1. Make modnetwork "asyncio-aware". i.e. scan() would be something you could use with "async for"
Code: Select all
async def do_scan():
async for result in sta_if.scan():
handle(result)
2. Make modnetwork irq/callback-based. This is what we did in modbluetooth.
Code: Select all
def handler(event, data):
if event == IRQ_SCAN_RESULT:
handle(data)
elif event == IRQ_SCAN_COMPLETE:
handle(None)
ble.irq(handler)
ble.gap_scan(...)
Re: asynchronous wlan scans
Thanks
[/quote]
More general, if you want to get started with development of c code for micropython, where can you start? Are there perhaps some warm-up examples to get something very basic done? Or some other resources?
This is what I would love to use. It is not there, but how about your toy examplejimmo wrote: ↑Wed Jun 10, 2020 6:43 amCode: Select all
async def do_scan(): async for result in sta_if.scan(): handle(result)
[/quote]
how would you design this? are there any obstacles?
More general, if you want to get started with development of c code for micropython, where can you start? Are there perhaps some warm-up examples to get something very basic done? Or some other resources?