diff --git a/src/CHANGES.md b/src/CHANGES.md index fd855e3cd..0af4746b6 100644 --- a/src/CHANGES.md +++ b/src/CHANGES.md @@ -7,6 +7,7 @@ * removed `#` character from ePaper * fixed saving pinout for `Nokia-Display` * removed `Reset` Pin for monochrome displays +* improved wifi connection #652 ## 0.5.103 * merged MI improvements, thx @rejoe2 #778 diff --git a/src/wifi/ahoywifi.cpp b/src/wifi/ahoywifi.cpp index 9109c831a..0acdf9e2c 100644 --- a/src/wifi/ahoywifi.cpp +++ b/src/wifi/ahoywifi.cpp @@ -88,12 +88,11 @@ void ahoywifi::tickWifiLoop() { } mCnt++; - uint8_t timeout = 10; // seconds + uint8_t timeout = (mStaConn == DISCONNECTED) ? 10 : 20; // seconds if (mStaConn == CONNECTED) // connected but no ip timeout = 20; - - if(!mScanActive && mBSSIDList.empty() && ((mCnt % timeout) == 0)) { // start scanning APs with the given SSID + if(!mScanActive && mBSSIDList.empty() && (mStaConn == DISCONNECTED)) { // start scanning APs with the given SSID DBGPRINT(F("scanning APs with SSID ")); DBGPRINTLN(String(mConfig->sys.stationSsid)); mScanCnt = 0; @@ -115,8 +114,9 @@ void ahoywifi::tickWifiLoop() { mCnt = timeout - 2; } if((mCnt % timeout) == 0) { // try to reconnect after x sec without connection - if(mStaConn != CONNECTED) - mStaConn = CONNECTING; + mStaConn = CONNECTING; + WiFi.disconnect(); + if(mBSSIDList.size() > 0) { // get first BSSID in list DBGPRINT(F("try to connect to AP with BSSID:")); uint8_t bssid[6]; @@ -126,9 +126,11 @@ void ahoywifi::tickWifiLoop() { DBGPRINT(" " + String(bssid[j], HEX)); } DBGPRINTLN(""); - WiFi.disconnect(); WiFi.begin(mConfig->sys.stationSsid, mConfig->sys.stationPwd, 0, &bssid[0]); } + else + mStaConn = DISCONNECTED; + mCnt = 0; } }