8
8
9
9
Built by Khoi Hoang https://github.com/khoih-prog/ESP_AT_WM_Lite
10
10
Licensed under MIT license
11
- Version: 1.4.1
11
+ Version: 1.5.0
12
12
13
13
Version Modified By Date Comments
14
14
------- ----------- ---------- -----------
15
15
1.0.0 K Hoang 09/03/2020 Initial coding
16
16
1.0.1 K Hoang 20/03/2020 Add feature to enable adding dynamically more Credentials parameters in sketch
17
17
1.0.2 K Hoang 17/04/2020 Fix bug. Add support to SAMD51 and SAMD DUE. WPA2 SSID PW to 63 chars.
18
- Permit to input special chars such as !,@,#,$,%,^,&,* into data fields.
18
+ Permit to input special chars such as !,@,#,$,%,^,&,* into data fields.
19
19
1.0.3 K Hoang 11/06/2020 Add support to nRF52 boards, such as AdaFruit Feather nRF52832, NINA_B30_ublox, etc.
20
- Add DRD support. Add MultiWiFi support
20
+ Add DRD support. Add MultiWiFi support
21
21
1.0.4 K Hoang 03/07/2020 Add support to ESP32-AT shields. Modify LOAD_DEFAULT_CONFIG_DATA logic.
22
- Enhance MultiWiFi connection logic. Fix WiFi Status bug.
22
+ Enhance MultiWiFi connection logic. Fix WiFi Status bug.
23
23
1.1.0 K Hoang 13/04/2021 Fix invalid "blank" Config Data treated as Valid. Optional one set of WiFi Credentials
24
24
1.2.0 Michael H 28/04/2021 Enable scan of WiFi networks for selection in Configuration Portal
25
25
1.3.0 K Hoang 12/05/2021 Add support to RASPBERRY_PI_PICO using Arduino-pico core
26
26
1.4.0 K Hoang 01/06/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core
27
- 1.4.1 K Hoang 10/10/2021 Update `platform.ini` and `library.json`
27
+ 1.4.1 K Hoang 10/10/2021 Update `platform.ini` and `library.json`
28
+ 1.5.0 K Hoang 08/01/2022 Fix the blocking issue in loop() with configurable WIFI_RECON_INTERVAL
28
29
***************************************************************************************************************************************/
29
30
30
31
#ifndef Esp8266_AT_WM_Lite_h
38
39
#error This code is intended to run on the Mega2560 platform! Please check your Tools->Board setting.
39
40
#endif
40
41
41
- #define ESP_AT_WM_LITE_VERSION " ESP_AT_WM_Lite v1.4.1 "
42
+ #define ESP_AT_WM_LITE_VERSION " ESP_AT_WM_Lite v1.5.0 "
42
43
43
44
#define DEFAULT_BOARD_NAME " AVR-MEGA"
44
45
@@ -295,6 +296,16 @@ class ESP_AT_WiFiManager_Lite
295
296
296
297
// ////////////////////////////////////////////
297
298
299
+ #if !defined(WIFI_RECON_INTERVAL)
300
+ #define WIFI_RECON_INTERVAL 0 // default 0s between reconnecting WiFi
301
+ #else
302
+ #if (WIFI_RECON_INTERVAL < 0)
303
+ #define WIFI_RECON_INTERVAL 0
304
+ #elif (WIFI_RECON_INTERVAL > 600000)
305
+ #define WIFI_RECON_INTERVAL 600000 // Max 10min
306
+ #endif
307
+ #endif
308
+
298
309
void run ()
299
310
{
300
311
static int retryTimes = 0 ;
@@ -306,15 +317,19 @@ class ESP_AT_WiFiManager_Lite
306
317
static unsigned long checkstatus_timeout = 0 ;
307
318
#define WIFI_STATUS_CHECK_INTERVAL 5000L
308
319
320
+ static uint32_t curMillis;
321
+
322
+ curMillis = millis ();
323
+
309
324
// // New DRD ////
310
325
// Call the double reset detector loop method every so often,
311
326
// so that it can recognise when the timeout expires.
312
327
// You can also call drd.stop() when you wish to no longer
313
328
// consider the next reset as a double reset.
314
329
drd->loop ();
315
330
// // New DRD ////
316
-
317
- if ( !configuration_mode && (millis () > checkstatus_timeout) )
331
+
332
+ if ( !configuration_mode && (curMillis > checkstatus_timeout) )
318
333
{
319
334
if (WiFi.status () == WL_CONNECTED)
320
335
{
@@ -326,16 +341,16 @@ class ESP_AT_WiFiManager_Lite
326
341
{
327
342
wifiDisconnectedOnce = false ;
328
343
wifi_connected = false ;
329
- ESP_AT_LOGDEBUG (F (" r:Check&WLost" ));
344
+ ESP_AT_LOGERROR (F (" r:Check&WLost" ));
330
345
}
331
346
else
332
347
{
333
348
wifiDisconnectedOnce = true ;
334
349
}
335
350
}
336
351
337
- checkstatus_timeout = millis () + WIFI_STATUS_CHECK_INTERVAL;
338
- }
352
+ checkstatus_timeout = curMillis + WIFI_STATUS_CHECK_INTERVAL;
353
+ }
339
354
340
355
// Lost connection in running. Give chance to reconfig.
341
356
if ( !wifi_connected )
@@ -348,7 +363,7 @@ class ESP_AT_WiFiManager_Lite
348
363
349
364
if (server)
350
365
{
351
- // ESP_AT_LOGDEBUG(F("r:hC "));
366
+ // ESP_AT_LOGDEBUG(F("r:handleClient "));
352
367
server->handleClient ();
353
368
}
354
369
@@ -363,7 +378,7 @@ class ESP_AT_WiFiManager_Lite
363
378
{
364
379
if (++retryTimes <= CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET)
365
380
{
366
- ESP_AT_LOGDEBUG1 (F (" r:Wlost &TOut.ConW.Retry#" ), retryTimes);
381
+ ESP_AT_LOGERROR1 (F (" r:WLost &TOut.ConW.Retry#" ), retryTimes);
367
382
}
368
383
else
369
384
{
@@ -375,18 +390,38 @@ class ESP_AT_WiFiManager_Lite
375
390
// Not in config mode, try reconnecting before forcing to config mode
376
391
if ( !wifi_connected )
377
392
{
378
- ESP_AT_LOGDEBUG (F (" r:Wlost.ReconW" ));
393
+
394
+
395
+ #if (WIFI_RECON_INTERVAL > 0)
396
+
397
+ static uint32_t lastMillis = 0 ;
398
+
399
+ if ( (lastMillis == 0 ) || (curMillis - lastMillis) > WIFI_RECON_INTERVAL )
400
+ {
401
+ lastMillis = curMillis;
402
+
403
+ ESP_AT_LOGERROR (F (" r:WLost.ReconW" ));
404
+
405
+ if (connectToWifi (RETRY_TIMES_RECONNECT_WIFI))
406
+ {
407
+ ESP_AT_LOGERROR (F (" r:WOK" ));
408
+ }
409
+ }
410
+ #else
411
+ ESP_AT_LOGERROR (F (" r:WLost.ReconW" ));
412
+
379
413
if (connectToWifi (RETRY_TIMES_RECONNECT_WIFI))
380
414
{
381
- ESP_AT_LOGDEBUG (F (" r:WOK" ));
415
+ ESP_AT_LOGERROR (F (" r:WOK" ));
382
416
}
417
+ #endif
383
418
}
384
419
}
385
420
}
386
421
else if (configuration_mode)
387
422
{
388
423
configuration_mode = false ;
389
- ESP_AT_LOGDEBUG (F (" r:gotWBack" ));
424
+ ESP_AT_LOGERROR (F (" r:gotWBack" ));
390
425
}
391
426
}
392
427
@@ -984,8 +1019,18 @@ class ESP_AT_WiFiManager_Lite
984
1019
}
985
1020
986
1021
// ////////////////////////////////////////////
1022
+
1023
+ // Max times to try WiFi per loop() iteration. To avoid blocking issue in loop()
1024
+ // Default 1 and minimum 1.
1025
+ #if !defined(MAX_NUM_WIFI_RECON_TRIES_PER_LOOP)
1026
+ #define MAX_NUM_WIFI_RECON_TRIES_PER_LOOP 1
1027
+ #else
1028
+ #if (MAX_NUM_WIFI_RECON_TRIES_PER_LOOP < 1)
1029
+ #define MAX_NUM_WIFI_RECON_TRIES_PER_LOOP 1
1030
+ #endif
1031
+ #endif
987
1032
988
- // New connection logic for ESP32-AT from v1.0.6
1033
+ // New connection logic for ESP32-AT from v1.0.6
989
1034
bool connectToWifi (int retry_time)
990
1035
{
991
1036
int sleep_time = 250 ;
@@ -1000,8 +1045,10 @@ class ESP_AT_WiFiManager_Lite
1000
1045
}
1001
1046
1002
1047
ESP_AT_LOGDEBUG3 (F (" con2WF:SSID=" ), ESP8266_AT_config.wifi_ssid , F (" ,PW=" ), ESP8266_AT_config.wifi_pw );
1048
+
1049
+ uint8_t numWiFiReconTries = 0 ;
1003
1050
1004
- while ( !wifi_connected && ( 0 < retry_time ) )
1051
+ while ( !wifi_connected && ( 0 < retry_time ) && (numWiFiReconTries++ < MAX_NUM_WIFI_RECON_TRIES_PER_LOOP) )
1005
1052
{
1006
1053
ESP_AT_LOGDEBUG1 (F (" Remaining retry_time=" ), retry_time);
1007
1054
0 commit comments