[beken-72xx] Reset scan state after timeout

This commit is contained in:
Kuba Szczodrzyński
2022-09-09 20:21:33 +02:00
parent dfde2d8a62
commit 96c7fdc02c
2 changed files with 19 additions and 7 deletions

View File

@@ -41,15 +41,25 @@ static void scanHandler(void *ctx, uint8_t param) {
wifiEventSendArduino(ARDUINO_EVENT_WIFI_SCAN_DONE); wifiEventSendArduino(ARDUINO_EVENT_WIFI_SCAN_DONE);
end: end:
scan->running = false; scan->timeout = 0;
xSemaphoreGive(cls->data.scanSem); if (scan->running) {
// running == false means it was discarded (timeout)
scan->running = false;
xSemaphoreGive(cls->data.scanSem);
}
LT_HEAP_I(); LT_HEAP_I();
return; return;
} }
int16_t WiFiClass::scanNetworks(bool async, bool showHidden, bool passive, uint32_t maxMsPerChannel, uint8_t channel) { int16_t WiFiClass::scanNetworks(bool async, bool showHidden, bool passive, uint32_t maxMsPerChannel, uint8_t channel) {
if (scan && scan->running) if (scan && scan->running) {
return WIFI_SCAN_RUNNING; if (scan->timeout && millis() > scan->timeout) {
LT_WM(WIFI, "Scan timeout, discarding");
scan->running = false;
} else {
return WIFI_SCAN_RUNNING;
}
}
enableSTA(true); enableSTA(true);
scanDelete(); scanDelete();
scanInit(); scanInit();
@@ -63,6 +73,7 @@ int16_t WiFiClass::scanNetworks(bool async, bool showHidden, bool passive, uint3
LT_HEAP_I(); LT_HEAP_I();
scan->running = true; scan->running = true;
scan->timeout = millis() + maxMsPerChannel * 20 + 1000;
int16_t ret = WIFI_SCAN_RUNNING; int16_t ret = WIFI_SCAN_RUNNING;
if (!async) { if (!async) {

View File

@@ -137,9 +137,10 @@ typedef struct {
} WiFiScanAP; } WiFiScanAP;
typedef struct { typedef struct {
bool running = false; bool running = false;
uint8_t count = 0; unsigned long timeout = 0;
WiFiScanAP *ap = NULL; uint8_t count = 0;
WiFiScanAP *ap = NULL;
} WiFiScanData; } WiFiScanData;
typedef enum { typedef enum {