preserve AP connections if STA side reconnects

This commit is contained in:
joba-1 2022-11-16 17:28:03 +01:00
parent 8af22a1904
commit 4eb0bf80dc
2 changed files with 10 additions and 15 deletions

View File

@ -210,10 +210,13 @@ void WifiBegin(uint8_t flag, uint8_t channel)
#endif // USE_EMULATION
WiFi.persistent(false); // Solve possible wifi init errors (re-add at 6.2.1.16 #4044, #4083)
WiFi.disconnect(true); // Delete SDK wifi config
delay(200);
if (WiFi.getMode() != WIFI_AP_STA) // Preserve range extender connections
{
WiFi.disconnect(true); // Delete SDK wifi config
delay(200);
WifiSetMode(WIFI_STA); // Disable AP mode
WifiSetMode(WIFI_STA); // Disable AP mode
}
WiFiSetSleepMode();
// if (WiFi.getPhyMode() != WIFI_PHY_MODE_11N) { WiFi.setPhyMode(WIFI_PHY_MODE_11N); } // B/G/N
// if (WiFi.getPhyMode() != WIFI_PHY_MODE_11G) { WiFi.setPhyMode(WIFI_PHY_MODE_11G); } // B/G

View File

@ -146,7 +146,6 @@ void (*const DrvRgxCommand[])(void) PROGMEM = {
typedef struct
{
uint8_t status = RGX_NOT_CONFIGURED;
uint16_t lastlinkcount = 0;
#ifdef USE_WIFI_RANGE_EXTENDER_NAPT
bool napt_enabled = false;
#endif // USE_WIFI_RANGE_EXTENDER_NAPT
@ -360,7 +359,6 @@ void rngxSetup()
WiFi.softAP(SettingsText(SET_RGX_SSID), SettingsText(SET_RGX_PASSWORD));
AddLog(LOG_LEVEL_INFO, PSTR("RGX: WiFi Extender AP Enabled with SSID: %s"), WiFi.softAPSSID().c_str());
RgxSettings.status = RGX_SETUP_NAPT;
RgxSettings.lastlinkcount = Wifi.link_count;
}
void rngxSetupNAPT(void)
@ -463,17 +461,11 @@ bool Xdrv58(uint32_t function)
}
else if (RgxSettings.status == RGX_CONFIGURED)
{
if (Wifi.status != WL_CONNECTED)
if (Wifi.status == WL_CONNECTED && WiFi.getMode() != WIFI_AP_STA)
{
// No longer connected, need to setup again
AddLog(LOG_LEVEL_INFO, PSTR("RGX: No longer connected, prepare to reconnect WiFi AP..."));
RgxSettings.status = RGX_NOT_CONFIGURED;
}
else if (RgxSettings.lastlinkcount != Wifi.link_count && WiFi.getMode() != WIFI_AP_STA)
{
// Assume WiFi has reconnected and been reconfigured, prepare to reconnect
AddLog(LOG_LEVEL_INFO, PSTR("RGX: Link count now: %d, WiFi.getMode(): %d, unconfigure..."), Wifi.link_count, WiFi.getMode());
RgxSettings.status = RGX_NOT_CONFIGURED;
// Should not happen... our AP is gone and only a restart will get it back properly
AddLog(LOG_LEVEL_INFO, PSTR("RGX: WiFi mode is %d not %d. Restart..."), WiFi.getMode(), WIFI_AP_STA);
TasmotaGlobal.restart_flag = 2;
}
}
break;