[GH-ISSUE #1663] wm.autoConnect(ssid, password); consumes cumulative memory #1411

Open
opened 2026-02-28 01:29:58 +03:00 by kerem · 19 comments
Owner

Originally created by @RulioHT2021 on GitHub (Oct 9, 2023).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1663

PLEASE TRY Latest Master BRANCH before submitting bugs, in case they were already fixed.

Issues without basic info will be ignored or closed!

Please fill the info fields, it helps to get you faster support ;)

if you have a stack dump decode it:
https://github.com/esp8266/Arduino/blob/master/doc/Troubleshooting/stack_dump.rst

for better debug messages:
https://github.com/esp8266/Arduino/blob/master/doc/Troubleshooting/debugging.rst

----------------------------- Remove above -----------------------------

Basic Infos

Hardware

WiFimanager Branch/Release: Master

Esp8266/Esp32:

Hardware: ESP-12e, esp01, esp25

Core Version: 2.4.0, staging

Description

Problem description

Settings in IDE

Module: NodeMcu, Wemos D1

Additional libraries:

Sketch

void task_reconnect(void * parameter){
  task_rec = true;
  wm.autoConnect(ssid, password);
  if(WiFi.status() == WL_CONNECTED){
    Serial.println("WIFI OK");
    timeClient.update();
    ping_test();
    Serial.println(resp);
    if(client.connected()){
      Serial.println("BROKER OK.");
    }else if(client.connect("A")){
      Serial.println("BROKER OK.");
    }else{
      Serial.println("ERRO BROKER não conectado.");
    }
  }else{
    Serial.println("ERRO WIFI não conectado");
  }
  Serial.print("ESP.getFreeHeap(): ");
  Serial.println(ESP.getFreeHeap());
  vTaskDelete(NULL);    // Delete task
}
#END

Debug Messages

messages here
Originally created by @RulioHT2021 on GitHub (Oct 9, 2023). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1663 ## PLEASE TRY Latest Master BRANCH before submitting bugs, in case they were already fixed. ## Issues without basic info will be ignored or closed! Please fill the info fields, it helps to get you faster support ;) if you have a stack dump decode it: https://github.com/esp8266/Arduino/blob/master/doc/Troubleshooting/stack_dump.rst for better debug messages: https://github.com/esp8266/Arduino/blob/master/doc/Troubleshooting/debugging.rst ----------------------------- Remove above ----------------------------- ### Basic Infos #### Hardware WiFimanager Branch/Release: Master Esp8266/Esp32: Hardware: ESP-12e, esp01, esp25 Core Version: 2.4.0, staging ### Description Problem description ### Settings in IDE Module: NodeMcu, Wemos D1 Additional libraries: ### Sketch ```C++ void task_reconnect(void * parameter){ task_rec = true; wm.autoConnect(ssid, password); if(WiFi.status() == WL_CONNECTED){ Serial.println("WIFI OK"); timeClient.update(); ping_test(); Serial.println(resp); if(client.connected()){ Serial.println("BROKER OK."); }else if(client.connect("A")){ Serial.println("BROKER OK."); }else{ Serial.println("ERRO BROKER não conectado."); } }else{ Serial.println("ERRO WIFI não conectado"); } Serial.print("ESP.getFreeHeap(): "); Serial.println(ESP.getFreeHeap()); vTaskDelete(NULL); // Delete task } #END ``` ### Debug Messages ``` messages here ```
Author
Owner

@RulioHT2021 commented on GitHub (Oct 9, 2023):

Sorry, I'm new here, I'm having a memory problem, as each reconnection test consumes more memory.

<!-- gh-comment-id:1753446666 --> @RulioHT2021 commented on GitHub (Oct 9, 2023): Sorry, I'm new here, I'm having a memory problem, as each reconnection test consumes more memory.
Author
Owner

@tablatronix commented on GitHub (Oct 10, 2023):

Will test thanks

<!-- gh-comment-id:1754159459 --> @tablatronix commented on GitHub (Oct 10, 2023): Will test thanks
Author
Owner

@tablatronix commented on GitHub (Oct 10, 2023):

I am assuming you have removed your local callouts to timeClient, ping, client checks and you are not leaking memory in them ?

<!-- gh-comment-id:1754271322 --> @tablatronix commented on GitHub (Oct 10, 2023): I am assuming you have removed your local callouts to timeClient, ping, client checks and you are not leaking memory in them ?
Author
Owner

@tablatronix commented on GitHub (Oct 10, 2023):

Make sure you are pulling git, there was an esp8266 fix recently

I am calling autoconnect in a loop and not leaking any memory.. Are you using blocking or non blocking mode?
Let me try esp8266

<!-- gh-comment-id:1754272460 --> @tablatronix commented on GitHub (Oct 10, 2023): Make sure you are pulling git, there was an esp8266 fix recently I am calling autoconnect in a loop and not leaking any memory.. Are you using blocking or non blocking mode? Let me try esp8266
Author
Owner

@RulioHT2021 commented on GitHub (Oct 10, 2023):

Sorry I wasn't so clear, after connecting the network I turn off the router and with each reconnection attempt with the router turned off it consumes memory.
I'm using it without blocking.

<!-- gh-comment-id:1755868017 --> @RulioHT2021 commented on GitHub (Oct 10, 2023): Sorry I wasn't so clear, after connecting the network I turn off the router and with each reconnection attempt with the router turned off it consumes memory. I'm using it without blocking.
Author
Owner

@tablatronix commented on GitHub (Oct 11, 2023):

Ok so the configportal is starting each time? How do you get out of it, do you have a timeout?

and how do you know its not your code?

timeClient.update();
ping_test();
<!-- gh-comment-id:1756556563 --> @tablatronix commented on GitHub (Oct 11, 2023): Ok so the configportal is starting each time? How do you get out of it, do you have a timeout? and how do you know its not your code? timeClient.update(); ping_test();
Author
Owner

@tablatronix commented on GitHub (Oct 11, 2023):

Not seeing it, what exact hardware you using ?

<!-- gh-comment-id:1756599479 --> @tablatronix commented on GitHub (Oct 11, 2023): Not seeing it, what exact hardware you using ?
Author
Owner

@RulioHT2021 commented on GitHub (Oct 11, 2023):

`bool ping_test(){
bool success = Ping.ping(p_url, 1);
float avg_time_ms = Ping.averageTime();
if (success) {
resp = "{"avg_ping":"" + String(avg_time_ms) + ""}";
} else {
resp = "{"avg_ping":"erro"}";
}
return success;
}

if(((millis() - time_conect_broker) >= 60000)||(timeClient.getSeconds() == 50)){
Serial.println("Tempo atingido!");
time_conect_broker = millis();
digitalWrite(LED, HIGH);
if(!client.connected()){
Serial.println("Chamando task_reconnect");
xTaskCreate(
task_reconnect, //Nome da função
"task_reconnect", //Nome da tarefa
10000, //Tamanho da tarefa
NULL, //Parametros
2, //Prioridade
NULL //Handle
);
}else{
Serial.println("Conectado!");
}
}
`

<!-- gh-comment-id:1758076251 --> @RulioHT2021 commented on GitHub (Oct 11, 2023): `bool ping_test(){ bool success = Ping.ping(p_url, 1); float avg_time_ms = Ping.averageTime(); if (success) { resp = "{\"avg_ping\":\"" + String(avg_time_ms) + "\"}"; } else { resp = "{\"avg_ping\":\"erro\"}"; } return success; } if(((millis() - time_conect_broker) >= 60000)||(timeClient.getSeconds() == 50)){ Serial.println("Tempo atingido!"); time_conect_broker = millis(); digitalWrite(LED, HIGH); if(!client.connected()){ Serial.println("Chamando task_reconnect"); xTaskCreate( task_reconnect, //Nome da função "task_reconnect", //Nome da tarefa 10000, //Tamanho da tarefa NULL, //Parametros 2, //Prioridade NULL //Handle ); }else{ Serial.println("Conectado!"); } } `
Author
Owner

@RulioHT2021 commented on GitHub (Oct 11, 2023):

I make a routine to check if 60 seconds have passed or if the timestamp is correct when it is 50 seconds, and I leave it inside the main loop.

<!-- gh-comment-id:1758079887 --> @RulioHT2021 commented on GitHub (Oct 11, 2023): I make a routine to check if 60 seconds have passed or if the timestamp is correct when it is 50 seconds, and I leave it inside the main loop.
Author
Owner

@tablatronix commented on GitHub (Oct 11, 2023):

Are you sure your tasks wrappers are cleaned up after each ? Sounds like it could be leaking there

<!-- gh-comment-id:1758132946 --> @tablatronix commented on GitHub (Oct 11, 2023): Are you sure your tasks wrappers are cleaned up after each ? Sounds like it could be leaking there
Author
Owner

@RulioHT2021 commented on GitHub (Oct 11, 2023):

I'll need to test other routines, I'll get back to you as soon as possible.
Thanks.

<!-- gh-comment-id:1758291741 --> @RulioHT2021 commented on GitHub (Oct 11, 2023): I'll need to test other routines, I'll get back to you as soon as possible. Thanks.
Author
Owner

@RulioHT2021 commented on GitHub (Oct 19, 2023):

16:39:29.378 -> ESP.getFreeHeap(): 207916
16:39:29.378 -> *wm:AutoConnect
16:39:29.378 -> *wm:Connecting to SAVED AP: Teste
16:39:29.892 -> *wm:connectTimeout not set, ESP waitForConnectResult...
16:39:34.269 -> *wm:AutoConnect: FAILED for 4902 ms
16:39:34.269 -> *wm:StartAP with SSID: AFL_0212848844
16:39:34.784 -> *wm:AP IP address: 192.168.4.1
16:39:34.784 -> Entrando em modo de configuração
16:39:34.784 -> Nome da rede WIFI, SSID: AFL_0212848844
16:39:34.784 -> Endereço de IP: 192.168.4.1
16:39:34.784 -> *wm:Starting Web Portal
16:39:35.297 -> *wm:config portal has timed out
16:39:35.297 -> *wm:[ERROR] disconnect configportal - softAPdisconnect FAILED
16:39:36.278 -> *wm:config portal exiting
16:39:36.278 -> ESP.getFreeHeap(): 206900
16:42:33.080 -> ESP.getFreeHeap(): 206852
16:42:33.080 -> *wm:AutoConnect
16:42:33.080 -> *wm:Connecting to SAVED AP: Teste
16:42:33.590 -> *wm:connectTimeout not set, ESP waitForConnectResult...
16:42:38.012 -> *wm:AutoConnect: FAILED for 4902 ms
16:42:38.012 -> *wm:StartAP with SSID: AFL_0212848844
16:42:38.475 -> *wm:AP IP address: 192.168.4.1
16:42:38.475 -> Entrando em modo de configuração
16:42:38.521 -> Nome da rede WIFI, SSID: AFL_0212848844
16:42:38.521 -> Endereço de IP: 192.168.4.1
16:42:38.521 -> *wm:Starting Web Portal
16:42:38.988 -> *wm:config portal has timed out
16:42:38.988 -> *wm:[ERROR] disconnect configportal - softAPdisconnect FAILED
16:42:40.015 -> *wm:config portal exiting
16:42:40.015 -> ESP.getFreeHeap(): 205848

void task_reconnect(void * parameter){
  Serial.print("ESP.getFreeHeap(): ");
  Serial.println(ESP.getFreeHeap());
  wm.autoConnect(ssid, password);
  Serial.print("ESP.getFreeHeap(): ");
  Serial.println(ESP.getFreeHeap());
  if(WiFi.status() == WL_CONNECTED){
    Serial.println("WIFI OK");
    timeClient.update();
    ping_test();
    Serial.println(resp);
    if(client.connected()){
      Serial.println("BROKER OK.");
    }else if(client.connect((char*) s_id.c_str(), mqttUser, mqttPassword)){
      Serial.println("BROKER OK.");
    }else{
      Serial.println("ERRO BROKER não conectado.");
    }
  }else{
    Serial.println("ERRO WIFI não conectado");
  }
  vTaskDelete(NULL);    // Delete task
}
<!-- gh-comment-id:1771598409 --> @RulioHT2021 commented on GitHub (Oct 19, 2023): 16:39:29.378 -> ESP.getFreeHeap(): 207916 16:39:29.378 -> *wm:AutoConnect 16:39:29.378 -> *wm:Connecting to SAVED AP: Teste 16:39:29.892 -> *wm:connectTimeout not set, ESP waitForConnectResult... 16:39:34.269 -> *wm:AutoConnect: FAILED for 4902 ms 16:39:34.269 -> *wm:StartAP with SSID: AFL_0212848844 16:39:34.784 -> *wm:AP IP address: 192.168.4.1 16:39:34.784 -> Entrando em modo de configuração 16:39:34.784 -> Nome da rede WIFI, SSID: AFL_0212848844 16:39:34.784 -> Endereço de IP: 192.168.4.1 16:39:34.784 -> *wm:Starting Web Portal 16:39:35.297 -> *wm:config portal has timed out 16:39:35.297 -> *wm:[ERROR] disconnect configportal - softAPdisconnect FAILED 16:39:36.278 -> *wm:config portal exiting 16:39:36.278 -> ESP.getFreeHeap(): 206900 16:42:33.080 -> ESP.getFreeHeap(): 206852 16:42:33.080 -> *wm:AutoConnect 16:42:33.080 -> *wm:Connecting to SAVED AP: Teste 16:42:33.590 -> *wm:connectTimeout not set, ESP waitForConnectResult... 16:42:38.012 -> *wm:AutoConnect: FAILED for 4902 ms 16:42:38.012 -> *wm:StartAP with SSID: AFL_0212848844 16:42:38.475 -> *wm:AP IP address: 192.168.4.1 16:42:38.475 -> Entrando em modo de configuração 16:42:38.521 -> Nome da rede WIFI, SSID: AFL_0212848844 16:42:38.521 -> Endereço de IP: 192.168.4.1 16:42:38.521 -> *wm:Starting Web Portal 16:42:38.988 -> *wm:config portal has timed out 16:42:38.988 -> *wm:[ERROR] disconnect configportal - softAPdisconnect FAILED 16:42:40.015 -> *wm:config portal exiting 16:42:40.015 -> ESP.getFreeHeap(): 205848 ```C++ void task_reconnect(void * parameter){ Serial.print("ESP.getFreeHeap(): "); Serial.println(ESP.getFreeHeap()); wm.autoConnect(ssid, password); Serial.print("ESP.getFreeHeap(): "); Serial.println(ESP.getFreeHeap()); if(WiFi.status() == WL_CONNECTED){ Serial.println("WIFI OK"); timeClient.update(); ping_test(); Serial.println(resp); if(client.connected()){ Serial.println("BROKER OK."); }else if(client.connect((char*) s_id.c_str(), mqttUser, mqttPassword)){ Serial.println("BROKER OK."); }else{ Serial.println("ERRO BROKER não conectado."); } }else{ Serial.println("ERRO WIFI não conectado"); } vTaskDelete(NULL); // Delete task } ```
Author
Owner

@RulioHT2021 commented on GitHub (Oct 19, 2023):

I created a task to reconnect and as you can see, each call consumes a little memory after wm.autoConnect(ssid, password);
The scenario I'm testing is:
in case there is a power outage and the router does not come back on.
Sooner or later it will restart due to lack of memory.
The problem is that I'm running a routine that cannot be restarted.

<!-- gh-comment-id:1771605688 --> @RulioHT2021 commented on GitHub (Oct 19, 2023): I created a task to reconnect and as you can see, each call consumes a little memory after wm.autoConnect(ssid, password); The scenario I'm testing is: in case there is a power outage and the router does not come back on. Sooner or later it will restart due to lack of memory. The problem is that I'm running a routine that cannot be restarted.
Author
Owner

@tablatronix commented on GitHub (Oct 19, 2023):

Just set WM debug level to WM_DEBUG_MAX it will dump heap stats

<!-- gh-comment-id:1771758084 --> @tablatronix commented on GitHub (Oct 19, 2023): Just set WM debug level to WM_DEBUG_MAX it will dump heap stats
Author
Owner

@tablatronix commented on GitHub (Oct 20, 2023):

Looks like leaking 1440 bytes, hmm I was not seeing this the other day.

<!-- gh-comment-id:1771902327 --> @tablatronix commented on GitHub (Oct 20, 2023): Looks like leaking 1440 bytes, hmm I was not seeing this the other day.
Author
Owner

@tablatronix commented on GitHub (Oct 20, 2023):

I cant find it yet, but my memory jumps up and down but stays <100% so something is cleaning up, but maybe not under certain conditions. I will have to run memory deugging and find what on the heap. I thought It was the known DNSD issue but that might only be a tiny bit.

Do you have many AP found during scans?
Are you using hostname or mdns?
If you change the configportaltimeout to like 20 seconds does anything change memory wise?

I might also want to copy your config, what partition config are you using, and what esp32 and rev ?
I am testing on an S3 with default partitions

<!-- gh-comment-id:1772016762 --> @tablatronix commented on GitHub (Oct 20, 2023): I cant find it yet, but my memory jumps up and down but stays <100% so something is cleaning up, but maybe not under certain conditions. I will have to run memory deugging and find what on the heap. I thought It was the known DNSD issue but that might only be a tiny bit. Do you have many AP found during scans? Are you using hostname or mdns? If you change the configportaltimeout to like 20 seconds does anything change memory wise? I might also want to copy your config, what partition config are you using, and what esp32 and rev ? I am testing on an S3 with default partitions
Author
Owner

@RulioHT2021 commented on GitHub (Oct 20, 2023):

partitions: LITTLEFS

If you change the configportaltimeout to like 20 seconds does anything change memory wise?
yes, Do not change

Are you using hostname or mdns?
no

<!-- gh-comment-id:1773063388 --> @RulioHT2021 commented on GitHub (Oct 20, 2023): partitions: LITTLEFS If you change the configportaltimeout to like 20 seconds does anything change memory wise? yes, Do not change Are you using hostname or mdns? no
Author
Owner

@RulioHT2021 commented on GitHub (Oct 20, 2023):

I changed the code this way and solved the consumption problem.

void task_reconnect(void * parameter){
  Serial.print("ESP.getFreeHeap(): ");
  Serial.println(ESP.getFreeHeap());
  WiFi.begin();
  timeClient.begin();
  //wm.autoConnect(ssid, password);
  Serial.print("ESP.getFreeHeap(): ");
  Serial.println(ESP.getFreeHeap());
  if(WiFi.status() == WL_CONNECTED){
    Serial.println("WIFI OK");
    timeClient.update();
    ping_test();
    Serial.println(resp);
    if(client.connected()){
      Serial.println("BROKER OK.");
      timeClient.begin();
    }if(client.connect((char*) s_id.c_str(), mqttUser, mqttPassword)){
      Serial.println("BROKER RECONECTADO.");
    }else{
      Serial.println("ERRO BROKER não RECONECTADO.");
    }
  }else{
    Serial.println("ERRO WIFI não conectado");
  }
  vTaskDelete(NULL);    // Delete task
}

12:38:56.216 -> ESP.getFreeHeap(): 207768
12:38:56.216 -> E (67820332) wifi:sta is connecting, return error
12:38:56.216 -> ESP.getFreeHeap(): 207476
12:39:56.854 -> ESP.getFreeHeap(): 207768
12:39:56.854 -> E (67880968) wifi:sta is connecting, return error
12:39:56.854 -> ESP.getFreeHeap(): 207476
12:40:57.179 -> ESP.getFreeHeap(): 207768
12:40:57.179 -> E (67941314) wifi:sta is connecting, return error
12:40:57.179 -> ESP.getFreeHeap(): 207476

<!-- gh-comment-id:1773063887 --> @RulioHT2021 commented on GitHub (Oct 20, 2023): I changed the code this way and solved the consumption problem. ```C++ void task_reconnect(void * parameter){ Serial.print("ESP.getFreeHeap(): "); Serial.println(ESP.getFreeHeap()); WiFi.begin(); timeClient.begin(); //wm.autoConnect(ssid, password); Serial.print("ESP.getFreeHeap(): "); Serial.println(ESP.getFreeHeap()); if(WiFi.status() == WL_CONNECTED){ Serial.println("WIFI OK"); timeClient.update(); ping_test(); Serial.println(resp); if(client.connected()){ Serial.println("BROKER OK."); timeClient.begin(); }if(client.connect((char*) s_id.c_str(), mqttUser, mqttPassword)){ Serial.println("BROKER RECONECTADO."); }else{ Serial.println("ERRO BROKER não RECONECTADO."); } }else{ Serial.println("ERRO WIFI não conectado"); } vTaskDelete(NULL); // Delete task } ``` 12:38:56.216 -> ESP.getFreeHeap(): 207768 12:38:56.216 -> E (67820332) wifi:sta is connecting, return error 12:38:56.216 -> ESP.getFreeHeap(): 207476 12:39:56.854 -> ESP.getFreeHeap(): 207768 12:39:56.854 -> E (67880968) wifi:sta is connecting, return error 12:39:56.854 -> ESP.getFreeHeap(): 207476 12:40:57.179 -> ESP.getFreeHeap(): 207768 12:40:57.179 -> E (67941314) wifi:sta is connecting, return error 12:40:57.179 -> ESP.getFreeHeap(): 207476
Author
Owner

@tablatronix commented on GitHub (Oct 20, 2023):

Yeah I am not really sure what the issue is.. I will keep testing

My memory does this if i autoconnect loop
Screenshot 2023-10-20 at 11 55 53 AM

<!-- gh-comment-id:1773081892 --> @tablatronix commented on GitHub (Oct 20, 2023): Yeah I am not really sure what the issue is.. I will keep testing My memory does this if i autoconnect loop ![Screenshot 2023-10-20 at 11 55 53 AM](https://github.com/tzapu/WiFiManager/assets/807787/5b0cfed0-d8cd-411b-84fd-b7eeea2dc199)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#1411
No description provided.