[beken-72xx] Scan networks before connecting, if needed
This commit is contained in:
@@ -14,6 +14,7 @@ extern "C" {
|
||||
typedef struct {
|
||||
char ssid[32 + 1];
|
||||
char pass[64 + 1];
|
||||
unsigned long scannedAt;
|
||||
uint32_t ipSta[4];
|
||||
uint32_t ipAp[4];
|
||||
SemaphoreHandle_t scanSem;
|
||||
|
||||
@@ -56,7 +56,11 @@ bool WiFiClass::reconnect(const uint8_t *bssid) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
LT_D_WG("Connecting to " MACSTR, MAC2STR(bssid));
|
||||
if (bssid) {
|
||||
LT_D_WG("Connecting to " MACSTR, MAC2STR(bssid));
|
||||
} else {
|
||||
LT_D_WG("Connecting to %s", data.ssid);
|
||||
}
|
||||
|
||||
network_InitTypeDef_st config;
|
||||
memset(&config, 0, sizeof(network_InitTypeDef_st));
|
||||
@@ -92,6 +96,13 @@ bool WiFiClass::reconnect(const uint8_t *bssid) {
|
||||
LT_D_WG("Static DNS: %s", config.dns_server_ip_addr);
|
||||
}
|
||||
|
||||
if (!data.scannedAt || millis() - data.scannedAt > 10000) {
|
||||
LT_D_WG("Scan needed");
|
||||
// apparently a scan must be performed first,
|
||||
// else it hangs at "[sa_sta]MM_START_REQ"
|
||||
scanNetworks(false);
|
||||
}
|
||||
|
||||
LT_D_WG("Starting WiFi...");
|
||||
__wrap_bk_printf_disable();
|
||||
bk_wlan_start_sta(&config);
|
||||
|
||||
@@ -36,6 +36,8 @@ static void scanHandler(void *ctx, uint8_t param) {
|
||||
memcpy(scan->ap[i].bssid.addr, result.ApList[i].bssid, 6);
|
||||
}
|
||||
|
||||
cls->data.scannedAt = millis();
|
||||
|
||||
end:
|
||||
scan->running = false;
|
||||
xSemaphoreGive(cls->data.scanSem);
|
||||
|
||||
Reference in New Issue
Block a user