From 99b42932fe1dc709320d135b0c53a3a2a2225110 Mon Sep 17 00:00:00 2001 From: sandeep Date: Sun, 5 Oct 2025 17:54:18 +0530 Subject: [PATCH 1/9] allows WiFi to attempt reconnect more than once as defined, default 6 attempts. Signed-off-by: 'sandeep <'sandeepkumar0153@gmail.com'> --- src/mesh/wifi/WiFiAPClient.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/mesh/wifi/WiFiAPClient.cpp b/src/mesh/wifi/WiFiAPClient.cpp index 1133ad424f..abad9a5f1c 100644 --- a/src/mesh/wifi/WiFiAPClient.cpp +++ b/src/mesh/wifi/WiFiAPClient.cpp @@ -50,6 +50,10 @@ char ourHost[16]; static unsigned long wifiReconnectStartMillis = 0; static bool wifiReconnectPending = false; +// // This will allow 6 attemps to retry every 5 seconds on bootup +static unsigned char wifiReconnectAttempts=0; +#define wifiReconnectAttemptsMax 6 + bool APStartupComplete = 0; unsigned long lastrun_ntp = 0; @@ -187,9 +191,23 @@ static int32_t reconnectWiFi() WiFi.mode(WIFI_STA); #endif WiFi.begin(wifiName, wifiPsw); + wifiReconnectAttempts=0; + } + + if(wifiReconnectAttempts <= wifiReconnectAttemptsMax) { + wifiReconnectAttempts ++; + isReconnecting = true; + wifiReconnectPending = true; + wifiReconnectStartMillis=millis(); + LOG_INFO("Reconnecting to WiFi access point %s", wifiName); + + } + else { + wifiReconnectAttempts =0; + wifiReconnectPending = false; + LOG_INFO("Multiple connection attempts have failed to WiFi access point %s", wifiName); } - isReconnecting = false; - wifiReconnectPending = false; + } else { // Still waiting for 5s to elapse return 100; // Check again soon From e8dcc30784413aa48df2bf08fc9f346855a526bc Mon Sep 17 00:00:00 2001 From: sandeep Date: Sun, 5 Oct 2025 19:00:08 +0530 Subject: [PATCH 2/9] changes to pin config based on custom hardware. updated wifi reconnect attempts code. --- src/mesh/wifi/WiFiAPClient.cpp | 45 +++++++++++-------- .../diy/nrf52_promicro_diy_tcxo/variant.h | 30 ++++++------- variants/rp2040/rpipicow/variant.h | 3 +- 3 files changed, 43 insertions(+), 35 deletions(-) diff --git a/src/mesh/wifi/WiFiAPClient.cpp b/src/mesh/wifi/WiFiAPClient.cpp index abad9a5f1c..9f4eace7aa 100644 --- a/src/mesh/wifi/WiFiAPClient.cpp +++ b/src/mesh/wifi/WiFiAPClient.cpp @@ -49,10 +49,15 @@ char ourHost[16]; // To replace blocking wifi connect delay with a non-blocking sleep static unsigned long wifiReconnectStartMillis = 0; static bool wifiReconnectPending = false; +static unsigned char wifiConnectAttempts=0; -// // This will allow 6 attemps to retry every 5 seconds on bootup -static unsigned char wifiReconnectAttempts=0; -#define wifiReconnectAttemptsMax 6 +#ifndef MaxWifiConnectionAttempts +#define MaxWifiConnectionAttempts 6 +#endif + +#ifndef wifiReconnectGap +#define wifiReconnectGap 10000 +#endif bool APStartupComplete = 0; @@ -172,42 +177,44 @@ static int32_t reconnectWiFi() #elif defined(ARCH_RP2040) WiFi.disconnect(false); #endif - LOG_INFO("Reconnecting to WiFi access point %s", wifiName); + LOG_INFO("Connecting to WiFi access point %s", wifiName); // Start the non-blocking wait for 5 seconds wifiReconnectStartMillis = millis(); wifiReconnectPending = true; // Do not attempt to connect yet, wait for the next invocation - return 5000; // Schedule next check soon + return wifiReconnectGap; // Schedule next check soon } // Check if we are ready to proceed with the WiFi connection after the 5s wait if (wifiReconnectPending) { - if (millis() - wifiReconnectStartMillis >= 5000) { + if (millis() - wifiReconnectStartMillis >= wifiReconnectGap) { if (!WiFi.isConnected()) { + wifiConnectAttempts++; + LOG_INFO("Reconnecting to WiFi access point %s, attempt %d", wifiName, wifiConnectAttempts); #ifdef CONFIG_IDF_TARGET_ESP32C3 WiFi.mode(WIFI_MODE_NULL); WiFi.useStaticBuffers(true); WiFi.mode(WIFI_STA); #endif WiFi.begin(wifiName, wifiPsw); - wifiReconnectAttempts=0; - } - - if(wifiReconnectAttempts <= wifiReconnectAttemptsMax) { - wifiReconnectAttempts ++; - isReconnecting = true; - wifiReconnectPending = true; wifiReconnectStartMillis=millis(); - LOG_INFO("Reconnecting to WiFi access point %s", wifiName); - + if(wifiConnectAttempts 3.0V ADC range and 12-bit ADC resolution = 3000mV/4096 #define VBAT_MV_PER_LSB (0.73242188F) // Voltage divider value => 1.5M + 1M voltage divider on VBAT = (1.5M / (1M + 1.5M)) -#define VBAT_DIVIDER (0.6F) +#define VBAT_DIVIDER (0.39F) // Compensation factor for the VBAT divider -#define VBAT_DIVIDER_COMP (1.73) +#define VBAT_DIVIDER_COMP (1.65) // Fixed calculation of milliVolt from compensation value #define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB) #undef AREF_VOLTAGE @@ -87,23 +87,23 @@ NRF52 PRO MICRO PIN ASSIGNMENT #define LED_STATE_ON 1 // State when LED is lit // Button -#define BUTTON_PIN (32 + 0) // P1.00 +#define BUTTON_PIN (32 + 7) // P1.00 // modified // GPS -#define PIN_GPS_TX (0 + 22) // P0.22 -#define PIN_GPS_RX (0 + 20) // P0.20 +#define PIN_GPS_TX (0 + 6) // P0.22 // modified +#define PIN_GPS_RX (0 + 8) // P0.20 // modified #define PIN_GPS_EN (0 + 24) // P0.24 -#define GPS_POWER_TOGGLE +// #define GPS_POWER_TOGGLE /modified #define GPS_UBLOX // define GPS_DEBUG -// UART interfaces -#define PIN_SERIAL1_RX PIN_GPS_TX -#define PIN_SERIAL1_TX PIN_GPS_RX +// // UART interfaces //modified + #define PIN_SERIAL1_RX PIN_GPS_TX + #define PIN_SERIAL1_TX PIN_GPS_RX -#define PIN_SERIAL2_RX (0 + 6) // P0.06 -#define PIN_SERIAL2_TX (0 + 8) // P0.08 + #define PIN_SERIAL2_RX (0 + 20) // P0.06 + #define PIN_SERIAL2_TX (0 + 22) // P0.08 // Serial interfaces #define SPI_INTERFACES_COUNT 1 @@ -118,11 +118,11 @@ NRF52 PRO MICRO PIN ASSIGNMENT #define LORA_CS (32 + 13) // P1.13 // LORA MODULES -#define USE_LLCC68 +// #define USE_LLCC68 #define USE_SX1262 -#define USE_RF95 -#define USE_SX1268 -#define USE_LR1121 +// #define USE_RF95 +// #define USE_SX1268 +// #define USE_LR1121 // RF95 CONFIG diff --git a/variants/rp2040/rpipicow/variant.h b/variants/rp2040/rpipicow/variant.h index 24da8f932a..9cd05edf9b 100644 --- a/variants/rp2040/rpipicow/variant.h +++ b/variants/rp2040/rpipicow/variant.h @@ -17,7 +17,8 @@ // rxd = 9 #define EXT_NOTIFY_OUT 22 -#define BUTTON_PIN 17 + +#define BUTTON_PIN 6 #define LED_PIN LED_BUILTIN From 55a7c955241dd299fffa435d3a245d8a719e3688 Mon Sep 17 00:00:00 2001 From: sandeep kumar <7038078+sandeepkumar0153@users.noreply.github.com> Date: Tue, 7 Oct 2025 19:04:15 +0530 Subject: [PATCH 3/9] Update src/mesh/wifi/WiFiAPClient.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/mesh/wifi/WiFiAPClient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mesh/wifi/WiFiAPClient.cpp b/src/mesh/wifi/WiFiAPClient.cpp index 747d7bbde2..315052c7b9 100644 --- a/src/mesh/wifi/WiFiAPClient.cpp +++ b/src/mesh/wifi/WiFiAPClient.cpp @@ -49,7 +49,7 @@ char ourHost[16]; // To replace blocking wifi connect delay with a non-blocking sleep static unsigned long wifiReconnectStartMillis = 0; static bool wifiReconnectPending = false; -static unsigned char wifiConnectAttempts=0; +static unsigned char wifiConnectAttempts = 0; #ifndef MaxWifiConnectionAttempts #define MaxWifiConnectionAttempts 6 From bdc28f90b9aedcc4646cd6f27b24dab83cdaeb3d Mon Sep 17 00:00:00 2001 From: sandeep kumar <7038078+sandeepkumar0153@users.noreply.github.com> Date: Tue, 7 Oct 2025 19:04:32 +0530 Subject: [PATCH 4/9] Update src/mesh/wifi/WiFiAPClient.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/mesh/wifi/WiFiAPClient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mesh/wifi/WiFiAPClient.cpp b/src/mesh/wifi/WiFiAPClient.cpp index 315052c7b9..16cbf785b4 100644 --- a/src/mesh/wifi/WiFiAPClient.cpp +++ b/src/mesh/wifi/WiFiAPClient.cpp @@ -211,7 +211,7 @@ static int32_t reconnectWiFi() } else{ - LOG_INFO("WiFi succesfully connected to access point %s", wifiName); + LOG_INFO("WiFi successfully connected to access point %s", wifiName); LOG_INFO("Connection attempts %d", wifiConnectAttempts); wifiReconnectPending = false; } From 38d5e46df418dd3c39f8dd59453cc4ef82df7635 Mon Sep 17 00:00:00 2001 From: sandeep kumar <7038078+sandeepkumar0153@users.noreply.github.com> Date: Tue, 7 Oct 2025 19:13:43 +0530 Subject: [PATCH 5/9] Update variant.h to default --- variants/rp2040/rpipicow/variant.h | 1 - 1 file changed, 1 deletion(-) diff --git a/variants/rp2040/rpipicow/variant.h b/variants/rp2040/rpipicow/variant.h index 9cd05edf9b..a77e8ee33f 100644 --- a/variants/rp2040/rpipicow/variant.h +++ b/variants/rp2040/rpipicow/variant.h @@ -17,7 +17,6 @@ // rxd = 9 #define EXT_NOTIFY_OUT 22 - #define BUTTON_PIN 6 #define LED_PIN LED_BUILTIN From c2224ad6f89a05e3d39ce7f14e4728e70c30e3c9 Mon Sep 17 00:00:00 2001 From: sandeep kumar <7038078+sandeepkumar0153@users.noreply.github.com> Date: Tue, 7 Oct 2025 19:14:18 +0530 Subject: [PATCH 6/9] Update variant.h to default --- .../diy/nrf52_promicro_diy_tcxo/variant.h | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/variants/nrf52840/diy/nrf52_promicro_diy_tcxo/variant.h b/variants/nrf52840/diy/nrf52_promicro_diy_tcxo/variant.h index c9b47a280a..e93442c7e1 100644 --- a/variants/nrf52840/diy/nrf52_promicro_diy_tcxo/variant.h +++ b/variants/nrf52840/diy/nrf52_promicro_diy_tcxo/variant.h @@ -62,9 +62,9 @@ NRF52 PRO MICRO PIN ASSIGNMENT // Definition of milliVolt per LSB => 3.0V ADC range and 12-bit ADC resolution = 3000mV/4096 #define VBAT_MV_PER_LSB (0.73242188F) // Voltage divider value => 1.5M + 1M voltage divider on VBAT = (1.5M / (1M + 1.5M)) -#define VBAT_DIVIDER (0.39F) +#define VBAT_DIVIDER (0.6F) // Compensation factor for the VBAT divider -#define VBAT_DIVIDER_COMP (1.65) +#define VBAT_DIVIDER_COMP (1.73) // Fixed calculation of milliVolt from compensation value #define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB) #undef AREF_VOLTAGE @@ -87,23 +87,23 @@ NRF52 PRO MICRO PIN ASSIGNMENT #define LED_STATE_ON 1 // State when LED is lit // Button -#define BUTTON_PIN (32 + 7) // P1.00 // modified +#define BUTTON_PIN (32 + 0) // P1.00 // GPS -#define PIN_GPS_TX (0 + 6) // P0.22 // modified -#define PIN_GPS_RX (0 + 8) // P0.20 // modified +#define PIN_GPS_TX (0 + 22) // P0.22 +#define PIN_GPS_RX (0 + 20) // P0.20 #define PIN_GPS_EN (0 + 24) // P0.24 -// #define GPS_POWER_TOGGLE /modified +#define GPS_POWER_TOGGLE #define GPS_UBLOX // define GPS_DEBUG -// // UART interfaces //modified - #define PIN_SERIAL1_RX PIN_GPS_TX - #define PIN_SERIAL1_TX PIN_GPS_RX +// UART interfaces +#define PIN_SERIAL1_RX PIN_GPS_TX +#define PIN_SERIAL1_TX PIN_GPS_RX - #define PIN_SERIAL2_RX (0 + 20) // P0.06 - #define PIN_SERIAL2_TX (0 + 22) // P0.08 +#define PIN_SERIAL2_RX (0 + 6) // P0.06 +#define PIN_SERIAL2_TX (0 + 8) // P0.08 // Serial interfaces #define SPI_INTERFACES_COUNT 1 @@ -118,11 +118,11 @@ NRF52 PRO MICRO PIN ASSIGNMENT #define LORA_CS (32 + 13) // P1.13 // LORA MODULES -// #define USE_LLCC68 +#define USE_LLCC68 #define USE_SX1262 -// #define USE_RF95 -// #define USE_SX1268 -// #define USE_LR1121 +#define USE_RF95 +#define USE_SX1268 +#define USE_LR1121 // RF95 CONFIG From c6c5307f58bf7544b474efc6fdf9daf7fff9ae98 Mon Sep 17 00:00:00 2001 From: sandeep kumar <7038078+sandeepkumar0153@users.noreply.github.com> Date: Tue, 7 Oct 2025 19:18:45 +0530 Subject: [PATCH 7/9] Update variant.h --- variants/rp2040/rpipicow/variant.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variants/rp2040/rpipicow/variant.h b/variants/rp2040/rpipicow/variant.h index a77e8ee33f..24da8f932a 100644 --- a/variants/rp2040/rpipicow/variant.h +++ b/variants/rp2040/rpipicow/variant.h @@ -17,7 +17,7 @@ // rxd = 9 #define EXT_NOTIFY_OUT 22 -#define BUTTON_PIN 6 +#define BUTTON_PIN 17 #define LED_PIN LED_BUILTIN From 4ff4358188be7dbc48e5f30e9c7e3cd362d350d6 Mon Sep 17 00:00:00 2001 From: sandeep kumar <7038078+sandeepkumar0153@users.noreply.github.com> Date: Tue, 7 Oct 2025 19:23:06 +0530 Subject: [PATCH 8/9] Update WiFiAPClient.cpp --- src/mesh/wifi/WiFiAPClient.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mesh/wifi/WiFiAPClient.cpp b/src/mesh/wifi/WiFiAPClient.cpp index 16cbf785b4..47233f2f43 100644 --- a/src/mesh/wifi/WiFiAPClient.cpp +++ b/src/mesh/wifi/WiFiAPClient.cpp @@ -198,12 +198,12 @@ static int32_t reconnectWiFi() WiFi.mode(WIFI_STA); #endif WiFi.begin(wifiName, wifiPsw); - wifiReconnectStartMillis=millis(); - if(wifiConnectAttempts Date: Sun, 12 Oct 2025 20:21:23 +0530 Subject: [PATCH 9/9] Macros have been capitalised, Updated WiFiAPClient.cpp macros have been capitalized, no further modification to code flow and logic from my end --- src/mesh/wifi/WiFiAPClient.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/mesh/wifi/WiFiAPClient.cpp b/src/mesh/wifi/WiFiAPClient.cpp index bcd09cc274..408b42039f 100644 --- a/src/mesh/wifi/WiFiAPClient.cpp +++ b/src/mesh/wifi/WiFiAPClient.cpp @@ -51,12 +51,12 @@ static unsigned long wifiReconnectStartMillis = 0; static bool wifiReconnectPending = false; static unsigned char wifiConnectAttempts = 0; -#ifndef MaxWifiConnectionAttempts -#define MaxWifiConnectionAttempts 6 +#ifndef MAXWIFICONNECTIONATTEMPTS +#define MAXWIFICONNECTIONATTEMPTS 6 #endif -#ifndef wifiReconnectGap -#define wifiReconnectGap 10000 +#ifndef WIFIRECONNECTGAP +#define WIFIRECONNECTGAP 10000 #endif bool APStartupComplete = 0; @@ -185,12 +185,12 @@ static int32_t reconnectWiFi() wifiReconnectStartMillis = millis(); wifiReconnectPending = true; // Do not attempt to connect yet, wait for the next invocation - return wifiReconnectGap; // Schedule next check soon + return WIFIRECONNECTGAP; // Schedule next check soon } // Check if we are ready to proceed with the WiFi connection after the 5s wait if (wifiReconnectPending) { - if (millis() - wifiReconnectStartMillis >= wifiReconnectGap) { + if (millis() - wifiReconnectStartMillis >= WIFIRECONNECTGAP) { if (!WiFi.isConnected()) { wifiConnectAttempts++; LOG_INFO("Reconnecting to WiFi access point %s, attempt %d", wifiName, wifiConnectAttempts); @@ -201,7 +201,7 @@ static int32_t reconnectWiFi() #endif WiFi.begin(wifiName, wifiPsw); wifiReconnectStartMillis = millis(); - if(wifiConnectAttempts < MaxWifiConnectionAttempts){ + if(wifiConnectAttempts < MAXWIFICONNECTIONATTEMPTS){ needReconnect = true; } else{