From 85cb92362caaf7985a4e6d6a556b4c4dea2b7581 Mon Sep 17 00:00:00 2001 From: permissionBRICK <40219477+permissionBRICK@users.noreply.github.com> Date: Sun, 12 Jul 2026 01:59:45 +0000 Subject: [PATCH] fix: direct-connect-first for hidden SSIDs to avoid 50-120 min reconnects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/network/AhoyWifiEsp8266.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/network/AhoyWifiEsp8266.h b/src/network/AhoyWifiEsp8266.h index 03cd54b1..648b7aad 100644 --- a/src/network/AhoyWifiEsp8266.h +++ b/src/network/AhoyWifiEsp8266.h @@ -37,13 +37,24 @@ class AhoyWifi : public AhoyNetwork { mOnNetworkCB(false); mAp.enable(); MDNS.end(); + mDirectAttempts = 0; } if (WiFi.softAPgetStationNum() > 0) { DBGPRINTLN(F("AP client connected")); } #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 ")); DBGPRINTLN(String(mConfig->sys.stationSsid)); mScanCnt = 0; @@ -92,6 +103,7 @@ class AhoyWifi : public AhoyNetwork { if(!mConnected) { mAp.disable(); mConnected = true; + mDirectAttempts = 0; ah::welcome(WiFi.localIP().toString(), F("Station")); MDNS.begin(mConfig->sys.deviceName); MDNSResponder::hMDNSService hRes = MDNS.addService(NULL, "http", "tcp", 80); @@ -161,10 +173,12 @@ class AhoyWifi : public AhoyNetwork { private: uint8_t mCnt = 0; uint8_t mScanCnt = 0; + uint8_t mDirectAttempts = 0; std::list mBSSIDList; bool mWasInCh12to14 = false; static constexpr uint8_t TIMEOUT = 20; static constexpr uint8_t SCAN_TIMEOUT = 10; + static constexpr uint8_t MAX_DIRECT_ATTEMPTS = 3; }; #endif /*ESP8266*/