Description
Hardware
Arduino IDE 1.6.8
Hardware: Adafruit Huzzah
Core Version: 2.2.0
Description
ESP8266HTTPClient works fine in "http" mode. no leak. But when enabling SSL, it leaks 65 to 100 bytes per request (seems to depend on website how big the leak is). I tested different websites and on different Wifi connections. Other tests ran memory down from 30k free to 5k free after .GET() until it crashed. I even tried your latest libaxtls.a from master - since there were some recent fixes after 2.2.0, but no success.
Note: i tried HTTP keep-alive by also running it with .setReuse(true) following the "ReuseConnection" example code, with similar leak results.
Thanks for looking into this.
Best
flyinggorilla
Settings in IDE
Module: Adafruit Huzzah
Flash Size: 4MB (3MB spiffs)
CPU Frequency: 80Mhz
Flash Frequency: 40Mhz
Upload Using: SERIAL
Sketch
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
void WiFiEvent(WiFiEvent_t event) {
switch(event) {
case WIFI_EVENT_STAMODE_GOT_IP:
Serial.println("WiFi connected. IP address: " + String(WiFi.localIP().toString()) + " hostname: "+ WiFi.hostname() + " SSID: " + WiFi.SSID());
break;
case WIFI_EVENT_STAMODE_DISCONNECTED:
Serial.println("WiFi client lost connection");
break;
case WIFI_EVENT_STAMODE_CONNECTED:
Serial.println("WiFi client connected");
break;
case WIFI_EVENT_STAMODE_AUTHMODE_CHANGE:
Serial.println("WiFi client authentication mode changed.");
break;
//case WIFI_STAMODE_DHCP_TIMEOUT: THIS IS A NEW CONSTANT ENABLE WITH UPDATED SDK
// Serial.println("WiFi client DHCP timeout reached.");
//break;
case WIFI_EVENT_SOFTAPMODE_STACONNECTED:
Serial.println("WiFi accesspoint: new client connected. Clients: " + String(WiFi.softAPgetStationNum()));
break;
case WIFI_EVENT_SOFTAPMODE_STADISCONNECTED:
Serial.println("WiFi accesspoint: client disconnected. Clients: " + String(WiFi.softAPgetStationNum()));
break;
case WIFI_EVENT_SOFTAPMODE_PROBEREQRECVED:
//Serial.println("WiFi accesspoint: probe request received.");
break;
}
}
// HTTPClient http;
// initialization routines
void setup ( void ) {
int serialtimeout = 5000; //ms
Serial.begin ( 115200 );
while(!Serial) {
if (serialtimeout >0) {
serialtimeout -= 50;
} else {
break;
}
delay(50);
}
// initialize Wifi based on stored config
Serial.println("");
Serial.println("ESP8266 SDK Version: " +String(ESP.getSdkVersion()));
WiFi.begin("ssid", "pwd");
WiFi.onEvent(WiFiEvent);
Serial.println("Connecting to Wifi SSID: " + WiFi.SSID() + " as host "+ WiFi.hostname());
Serial.println("heap at begin: " + String(ESP.getFreeHeap()));
//http.setReuse(true); ---- this didnt help at all; free memory jumps up/down with almost every request, but overal leak persists
}
long count = 0;
long beginbytes = 0;
void loop() {
// wait for WiFi connection
if(WiFi.isConnected()) {
HTTPClient http;
// http.useHTTP10(true); ---- HTTP1.0 made it worse leading to WDT resets
Serial.println("[HTTP] begin...");
http.begin("https://www.herold.at/", "BE:70:4E:41:10:D9:2E:C9:37:F4:49:BB:06:CF:E6:7D:82:CD:47:1A");
//http.begin("http://www.herold.at/");
Serial.println("[HTTP] GET...");
// start connection and send HTTP header
int httpCode = http.GET();
long freebytes = ESP.getFreeHeap();
if (!count) {
beginbytes = freebytes;
Serial.println("heap after GET: " + String(freebytes));
} else {
Serial.println("heap after " + String(count) + "x GET: " + String(freebytes) + " average delta: " + String((beginbytes-freebytes)/count));
}
count++;
// httpCode will be negative on error
if(httpCode > 0) {
// HTTP header has been send and Server response header has been handled
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
// file found at server
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
Serial.println(payload.substring(0, 64) + "...");
//Serial.println(payload);
}
} else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
} else {
Serial.println("Wifi Station not yet connected.");
}
delay(5000);
}
Debug Messages
ESP8266 SDK Version: 1.5.2(7eee54f4)
Connecting to Wifi SSID: ssid as host ESP_0158F0
heap at begin: 41768
Wifi Station not yet connected.
WiFi client lost connection
WiFi client connected
WiFi connected. IP address: 10.10.129.129 hostname: ESP_0158F0 SSID: ssid
[HTTP] begin...
[HTTP] GET...
heap after GET: 23912
[HTTP] GET... code: 200
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:...
[HTTP] begin...
[HTTP] GET...
heap after 1x GET: 23720 average delta: 192
[HTTP] GET... code: 200
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:...
[HTTP] begin...
[HTTP] GET...
heap after 2x GET: 23816 average delta: 48
[HTTP] GET... code: 200
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:...
[HTTP] begin...
[HTTP] GET...
heap after 3x GET: 23696 average delta: 72
[HTTP] GET... code: 200
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:...
[HTTP] begin...
[HTTP] GET...
heap after 4x GET: 23576 average delta: 84
[HTTP] GET... code: 200
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:...
[HTTP] begin...
[HTTP] GET...
heap after 5x GET: 23552 average delta: 72
[HTTP] GET... code: 200
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:...
[HTTP] begin...
[HTTP] GET...
heap after 6x GET: 23456 average delta: 76
[HTTP] GET... code: 200
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:...
[HTTP] begin...
[HTTP] GET...
heap after 7x GET: 23384 average delta: 75
[HTTP] GET... code: 200
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:...
[HTTP] begin...
[HTTP] GET...
heap after 8x GET: 23288 average delta: 78
[HTTP] GET... code: 200
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:...
[HTTP] begin...
[HTTP] GET...
heap after 9x GET: 23144 average delta: 85
[HTTP] GET... code: 200
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:...
[HTTP] begin...
[HTTP] GET...
heap after 10x GET: 23168 average delta: 74
[HTTP] GET... code: 200
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:...
[HTTP] begin...
[HTTP] GET...
heap after 11x GET: 23072 average delta: 76
[HTTP] GET... code: 200
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:...
[HTTP] begin...
[HTTP] GET...
heap after 12x GET: 23024 average delta: 74
[HTTP] GET... code: 200
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:...
[HTTP] begin...
[HTTP] GET...
heap after 13x GET: 22952 average delta: 73
[HTTP] GET... code: 200
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:...
[HTTP] begin...
[HTTP] GET...
heap after 14x GET: 22784 average delta: 80
[HTTP] GET... code: 200
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:...
[HTTP] begin...
[HTTP] GET...
heap after 15x GET: 22880 average delta: 68
[HTTP] GET... code: 200
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:...
[HTTP] begin...
[HTTP] GET...
heap after 16x GET: 22736 average delta: 73
[HTTP] GET... code: 200
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:...
[HTTP] begin...
[HTTP] GET...
heap after 17x GET: 22544 average delta: 80
[HTTP] GET... code: 200
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:...
[HTTP] begin...
[HTTP] GET...
heap after 18x GET: 22592 average delta: 73
[HTTP] GET... code: 200
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:...
[HTTP] begin...
[HTTP] GET...
heap after 19x GET: 22520 average delta: 73
[HTTP] GET... code: 200
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:...
[HTTP] begin...
[HTTP] GET...
heap after 20x GET: 22496 average delta: 70
[HTTP] GET... code: 200
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:...
[HTTP] begin...
[HTTP] GET...
heap after 21x GET: 22352 average delta: 74
[HTTP] GET... code: 200
Soft WDT reset
ctx: cont
sp: 3fff11c0 end: 3fff1610 offset: 01b0
>>>stack>>>
3fff1370: 00000035 3fff1390 4022f60d 00000000
3fff1380: 00000001 6be79520 72a15a7e b5284f43
3fff1390: 40100000 00000000 00000000 00000000
3fff13a0: 3ffef4e0 3fff045c 3fff278c 00000000
3fff13b0: 00000001 402039ab 3fff2334 00000000
3fff13c0: 00000035 00000035 00000035 00000035
3fff13d0: 00000007 00000000 00000000 00000001
3fff13e0: 00000035 b5284f43 65176ed5 00000000
3fff13f0: 3fff26d4 00000000 00000035 40220c64
3fff1400: 00020315 3fff2702 3fff26d4 402212e8
3fff1410: 00000002 00000015 00000010 3fff04fc
3fff1420: 00000010 3fff14c0 00000000 00000000
3fff1430: 00000000 00080000 3fff26d4 40221142
3fff1440: 00000001 3fff1500 3fff05f0 3fff14f0
3fff1450: 00001ff8 3fff26d4 3fff2644 402216d2
3fff1460: 3ffe9b74 00001ff8 3fff2644 3fff14f0
3fff1470: 00001ff8 00000000 3fff26d4 4022119e
3fff1480: 3fff04fc 00001ff8 3fff2644 40203396
3fff1490: 00001ff8 00001ff8 3fff1cdc 40203ac0
3fff14a0: 3ffe9b74 00001ff8 3fff1530 40203c1a
3fff14b0: 00001ff8 00001ff8 3fff1530 402044ea
3fff14c0: 00000000 00000000 00000000 4020519a
3fff14d0: 3ffe9b74 3fff14e0 00000008 3ffe91c8
3fff14e0: 3ffe9b74 3fff1530 3fff15b8 4020455c
3fff14f0: 3ffe91c8 00000000 000003e8 4010020c
3fff1500: 3fff730c 00001fff 00001ff8 3fff1510
3fff1510: 00005750 000000c8 3fff15b8 3fff03fc
3fff1520: 00005750 000000c8 3fff0520 40202524
3fff1530: 3fff1d04 3fff1cdc 3fff1d6c 0000000f
3fff1540: 0000000d 000001bb 3f001388 3fff1d84
3fff1550: 0000000f 00000001 3fff16d4 0000000f
3fff1560: 00000005 3fff16ec 0000000f 00000000
3fff1570: 3fff1704 0000001f 00000011 3fff1cc4
3fff1580: 0000000f 00000000 00000000 00000000
3fff1590: 000000c8 00001ff8 3fff1500 00000001
3fff15a0: 00000000 00000000 00000000 00000000
3fff15b0: 00000000 00000000 00000000 00000000
3fff15c0: 00000000 00000000 00000000 00000000
3fff15d0: 3fff15b8 feefeffe feefeffe feefeffe
3fff15e0: 00000000 00000000 00000001 3fff05dc
3fff15f0: 3fffdad0 00000000 3fff05d4 40205a84
3fff1600: feefeffe feefeffe 3fff05f0 40100718
<<<stack<<<
ets Jan 8 2013,rst cause:2, boot mode:(1,6)
ets Jan 8 2013,rst cause:4, boot mode:(1,6)
wdt reset
Decoding 18 results
0x4022f60d: tcp_write at ?? line ?
0x40100000: _stext at ?? line ?
0x402039ab: ClientContext::write(char const*, unsigned int) at C:\Users\Bernd\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.2.0\libraries\ESP8266WiFi\src\include/ClientContext.h line 226
: (inlined by) ax_port_write at C:\Users\Bernd\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.2.0\libraries\ESP8266WiFi\src/WiFiClientSecure.cpp line 540
0x40220c64: send_raw_packet at /Users/igrokhotkov/e/axtls/e1/ssl/tls1.c line 979
: (inlined by) send_packet at /Users/igrokhotkov/e/axtls/e1/ssl/tls1.c line 1112
0x402212e8: basic_read at /Users/igrokhotkov/e/axtls/e1/ssl/tls1.c line 1240
0x40221142: DISPLAY_ALERT at /Users/igrokhotkov/e/axtls/e1/ssl/tls1.c line 2182 (discriminator 3)
: (inlined by) send_alert at /Users/igrokhotkov/e/axtls/e1/ssl/tls1.c line 1597 (discriminator 3)
0x402216d2: ssl_read at /Users/igrokhotkov/e/axtls/e1/ssl/tls1.c line 262
0x4022119e: ssl_free at /Users/igrokhotkov/e/axtls/e1/ssl/tls1.c line 236
0x40203396: ~SSLContext at C:\Users\Bernd\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.2.0\libraries\ESP8266WiFi\src/WiFiClientSecure.cpp line 497
: (inlined by) SSLContext::unref() at C:\Users\Bernd\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.2.0\libraries\ESP8266WiFi\src/WiFiClientSecure.cpp line 92
0x40203ac0: WiFiClientSecure::stop() at C:\Users\Bernd\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.2.0\libraries\ESP8266WiFi\src/WiFiClientSecure.cpp line 363
0x40203c1a: HTTPClient::end() at C:\Users\Bernd\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.2.0\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.cpp line 192
0x402044ea: HTTPClient::writeToStream(Stream*) at C:\Users\Bernd\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.2.0\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.cpp line 192
0x4020519a: String::String(char const*) at C:\Users\Bernd\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.2.0\cores\esp8266/WString.cpp line 519
0x4020455c: HTTPClient::getString() at C:\Users\Bernd\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.2.0\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.cpp line 192
0x4010020c: _umm_free at C:\Users\Bernd\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.2.0\cores\esp8266\umm_malloc/umm_malloc.c line 1285
0x40202524: loop at C:\Users\Bernd\Arduino\TestHTTPS/TestHTTPS.ino line 96
0x40205a84: loop_wrapper at C:\Users\Bernd\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.2.0\cores\esp8266/core_esp8266_main.cpp line 43
0x40100718: cont_norm at C:\Users\Bernd\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.2.0\cores\esp8266/cont.S line 109