Browse Source

fix: direct-connect-first for hidden SSIDs to avoid 50-120 min reconnects

When isHidden is set, try WiFi.begin(ssid, pwd) without a BSSID up to
3 times (20 s timeout each) before falling back to the existing blind-
scan BSSID carousel.  The SDK's directed probe picks the strongest
matching AP automatically.

Clear stale mBSSIDList before each direct attempt so a CONNECTING
timeout returns to DISCONNECTED (not stale SCAN_READY).  Gate on
!mScanActive to avoid overlapping WiFi.begin with an active scan.
Reset mDirectAttempts on GOT_IP and on disconnect-from-connected.

Worst case (all 3 direct attempts fail) = 60 s overhead before the
existing scan path runs — functionally identical to current behavior.

Measured: reconnect drops from 50-120+ minutes to ~5-8 seconds on a
hidden-SSID network with two APs at RSSI -78..-91 dBm.
pull/1891/head
permissionBRICK 2 weeks ago
parent
commit
85cb92362c
  1. 16
      src/network/AhoyWifiEsp8266.h

16
src/network/AhoyWifiEsp8266.h

@ -37,13 +37,24 @@ class AhoyWifi : public AhoyNetwork {
mOnNetworkCB(false); mOnNetworkCB(false);
mAp.enable(); mAp.enable();
MDNS.end(); MDNS.end();
mDirectAttempts = 0;
} }
if (WiFi.softAPgetStationNum() > 0) { if (WiFi.softAPgetStationNum() > 0) {
DBGPRINTLN(F("AP client connected")); DBGPRINTLN(F("AP client connected"));
} }
#if !defined(AP_ONLY) #if !defined(AP_ONLY)
else if (!mScanActive) { else if (mConfig->sys.isHidden && (mDirectAttempts < MAX_DIRECT_ATTEMPTS) && !mScanActive) {
DBGPRINT(F("hidden SSID direct connect attempt "));
DBGPRINTLN(String(mDirectAttempts + 1));
mBSSIDList.clear();
setStaticIp();
WiFi.begin(mConfig->sys.stationSsid, mConfig->sys.stationPwd);
mDirectAttempts++;
mWifiConnecting = true;
mCnt = 0;
mStatus = NetworkState::CONNECTING;
} else if (!mScanActive) {
DBGPRINT(F("scanning APs with SSID ")); DBGPRINT(F("scanning APs with SSID "));
DBGPRINTLN(String(mConfig->sys.stationSsid)); DBGPRINTLN(String(mConfig->sys.stationSsid));
mScanCnt = 0; mScanCnt = 0;
@ -92,6 +103,7 @@ class AhoyWifi : public AhoyNetwork {
if(!mConnected) { if(!mConnected) {
mAp.disable(); mAp.disable();
mConnected = true; mConnected = true;
mDirectAttempts = 0;
ah::welcome(WiFi.localIP().toString(), F("Station")); ah::welcome(WiFi.localIP().toString(), F("Station"));
MDNS.begin(mConfig->sys.deviceName); MDNS.begin(mConfig->sys.deviceName);
MDNSResponder::hMDNSService hRes = MDNS.addService(NULL, "http", "tcp", 80); MDNSResponder::hMDNSService hRes = MDNS.addService(NULL, "http", "tcp", 80);
@ -161,10 +173,12 @@ class AhoyWifi : public AhoyNetwork {
private: private:
uint8_t mCnt = 0; uint8_t mCnt = 0;
uint8_t mScanCnt = 0; uint8_t mScanCnt = 0;
uint8_t mDirectAttempts = 0;
std::list<uint8_t> mBSSIDList; std::list<uint8_t> mBSSIDList;
bool mWasInCh12to14 = false; bool mWasInCh12to14 = false;
static constexpr uint8_t TIMEOUT = 20; static constexpr uint8_t TIMEOUT = 20;
static constexpr uint8_t SCAN_TIMEOUT = 10; static constexpr uint8_t SCAN_TIMEOUT = 10;
static constexpr uint8_t MAX_DIRECT_ATTEMPTS = 3;
}; };
#endif /*ESP8266*/ #endif /*ESP8266*/

Loading…
Cancel
Save