I'm quite new to the esp8266 and the microcontroller world and its quite fun even tho it can be a bit frustrating.
I am currently developing a simple programm that goes to coingecko api and gets the crypto historic prices to draw a chart on a TFT display using the tft_espi library.
Everything is working great however, watchdog keeps resetting my esp at random times(always when preforming the same http.get) but at different times(Dont think its memory as i'm checking that).
Things i tried:
[*]Add yield() everywhere(or just in front of places that take long)
[*]Changed the cable
[*]changed the esp8266(i changed it twice)
[*]I'm constantly checking free heap memory to make sure i'm not running out.
Anyone got any suggestions?
Dont be surprised by the amount of Serial.println() in the code i rly tried to find the place where it dies.
void getChartDataFromApi(String ids, String vs_curry, String days, String interval){
Serial.println("started sh*t method");
if(WiFi.status() == WL_CONNECTED){
String host = "https://api.coingecko.com/api/v3/coins/" + ids + "/market_chart?vs_currency=" + vs_curry + "&days=" + days + "&interval=" + interval;
WiFiClientSecure chartClient;
HTTPClient chartHttp;
Serial.println("Setup 1");
chartClient.setInsecure(); //the magic line, use with caution
chartClient.connect(host, 443);
Serial.println("After client connect");
//chartClient.setTimeout(10);
chartHttp.begin(chartClient, host);
chartHttp.useHTTP10(true);
Serial.println("After http begin");
//chartHttp.setTimeout(10);
Serial.print("free memory before get: ");
Serial.println(ESP.getFreeHeap(),DEC);
yield();
int http_code = chartHttp.GET();
Serial.print("free memory after get: ");
Serial.println(ESP.getFreeHeap(),DEC);
Serial.println("http code: " || String(http_code));
if (http_code == HTTP_CODE_OK){
Serial.println("after get");
DynamicJsonDocument filter(16);
filter["prices"] = true;
DynamicJsonDocument doc(1024);
Serial.println("after creation of doc");
DeserializationError error = deserializeJson(doc, chartHttp.getStream(), DeserializationOption::Filter(filter));
Serial.println("after deserialization");
if (error) {
Serial.print(F("deserializeJson() failed: "));
Serial.println(error.f_str());
return;
}
Serial.println("after error if");
JsonArray prices = doc["prices"];
Serial.println("Saving prices");
//todo make this better(don't judge this is temporary)
currentChartPrices[0] = prices[0][1].as<float>(); // 16422.562273279298
currentChartPrices[1] = prices[1][1].as<float>(); // 16899.331969046758
currentChartPrices[2] = prices[2][1].as<float>(); // 16816.85370118997
currentChartPrices[3] = prices[3][1].as<float>(); // 16824.790162441503
currentChartPrices[4] = prices[4][1].as<float>(); // 16791.45543916491
currentChartPrices[5] = prices[5][1].as<float>(); // 16848.568708323422
currentChartPrices[6] = prices[6][1].as<float>(); // 16842.177039905502
currentChartPrices[7] = prices[7][1].as<float>(); // 16838.576336989227
Serial.println("after saving prices");
chartHttp.end();
chartClient.stop();
filter.clear();
doc.clear();
Serial.println("after closing everything");
}
else{
Serial.println("Failed to get chart api data");
delay(300);
}
}
Serial.println("outside of if");
}
Stack trace decoded including last few serial.println that show improtant info:
Free Memory after chart data: 43056
Y: 116
X: 0
X: 46.00 Y: 120.00 Price: 16899.33
X: 77.00 Y: 196.46 Price: 16816.85
X: 108.00 Y: 189.10 Price: 16824.79
X: 139.00 Y: 220.00 Price: 16791.46
X: 170.00 Y: 167.06 Price: 16848.57
X: 201.00 Y: 172.98 Price: 16842.18
X: 232.00 Y: 123.32 Price: 16895.75
Loopcounter: 5
Free Memory: 43384
Symbol: btc
Price: 16957.33 Change: 0.71
Free Memory before chart data: 43384
started sh*t method
Setup 1
After client connect
After http begin
free memory before get: 36648
free memory after get: 15112
1
after get
after creation of doc
after deserialization
after error if
Saving prices
after saving prices
after closing everything
outside of if
Price: 16899.33
Price: 16816.85
Price: 16824.79
Price: 16791.46
Price: 16848.57
Price: 16842.18
Price: 16895.75
Free Memory after chart data: 43056
Y: 116
X: 0
X: 46.00 Y: 120.00 Price: 16899.33
X: 77.00 Y: 196.46 Price: 16816.85
X: 108.00 Y: 189.10 Price: 16824.79
X: 139.00 Y: 220.00 Price: 16791.46
X: 170.00 Y: 167.06 Price: 16848.57
X: 201.00 Y: 172.98 Price: 16842.18
X: 232.00 Y: 123.32 Price: 16895.75
Loopcounter: 6
Free Memory: 43384
Symbol: btc
Price: 16957.33 Change: 0.71
Free Memory before chart data: 43384
started sh*t method
Setup 1
After client connect
After http begin
free memory before get: 36648
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
Soft WDT reset
0x40100571 in millis at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/core_esp8266_wiring.cpp:188
0x40100555 in millis at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/core_esp8266_wiring.cpp:185
0x40223d56 in optimistic_yield at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/core_esp8266_main.cpp:150 (discriminator 1)
0x40217538 in esp8266::polledTimeout::timeoutTemplate<false, esp8266::polledTimeout::YieldPolicy::DoNothing, esp8266::polledTimeout::TimePolicy::TimeUnit<esp8266::polledTimeout::TimePolicy::TimeSourceMillis, 1000ull> >::checkExpired(unsigned long) const at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/PolledTimeout.h:238
(inlined by) esp8266::polledTimeout::timeoutTemplate<false, esp8266::polledTimeout::YieldPolicy::DoNothing, esp8266::polledTimeout::TimePolicy::TimeUnit<esp8266::polledTimeout::TimePolicy::TimeSourceMillis, 1000ull> >::expiredOneShot() const at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/PolledTimeout.h:263
(inlined by) esp8266::polledTimeout::timeoutTemplate<false, esp8266::polledTimeout::YieldPolicy::DoNothing, esp8266::polledTimeout::TimePolicy::TimeUnit<esp8266::polledTimeout::TimePolicy::TimeSourceMillis, 1000ull> >::expired() at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/PolledTimeout.h:163
(inlined by) esp8266::polledTimeout::timeoutTemplate<false, esp8266::polledTimeout::YieldPolicy::DoNothing, esp8266::polledTimeout::TimePolicy::TimeUnit<esp8266::polledTimeout::TimePolicy::TimeSourceMillis, 1000ull> >::operator bool() at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/PolledTimeout.h:169
(inlined by) BearSSL::WiFiClientSecureCtx::_run_until(unsigned int, bool) at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\libraries\ESP8266WiFi\src/WiFiClientSecureBearSSL.cpp:468
0x40249e2a in br_ssl_engine_hs_reset at /home/earle/src/esp-quick-toolchain/arduino/tools/sdk/ssl/bearssl/src/ssl/ssl_engine.c:1320
0x40217678 in BearSSL::WiFiClientSecureCtx::_wait_for_handshake() at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\libraries\ESP8266WiFi\src/WiFiClientSecureBearSSL.cpp:585
0x402179bd in BearSSL::WiFiClientSecureCtx::_connectSSL(char const*) at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\libraries\ESP8266WiFi\src/WiFiClientSecureBearSSL.cpp:1170
0x402433bf in ip_chksum_pseudo at /home/earle/src/esp-quick-toolchain/arduino/tools/sdk/lwip2/builder/lwip2-src/src/core/inet_chksum.c:395
0x4023ea2e in tcp_output at /home/earle/src/esp-quick-toolchain/arduino/tools/sdk/lwip2/builder/lwip2-src/src/core/tcp_out.c:1361
0x4010601d in ets_timer_arm_new at ??:?
0x4022463a in __delay at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/core_esp8266_wiring.cpp:54
0x40215c9a in ClientContext::connect(ip4_addr*, unsigned short) at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\libraries\ESP8266WiFi\src/include/ClientContext.h:148
(inlined by) WiFiClient::connect(IPAddress, unsigned short) at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\libraries\ESP8266WiFi\src/WiFiClient.cpp:162
0x40217b4c in BearSSL::WiFiClientSecureCtx::connect(char const*, unsigned short) at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\libraries\ESP8266WiFi\src/WiFiClientSecureBearSSL.cpp:232
0x40233140 in std::function<void (void*, AsyncClient*, unsigned int)>::function(std::function<void (void*, AsyncClient*, unsigned int)> const&) at ??:?
0x40233140 in std::function<void (void*, AsyncClient*, unsigned int)>::function(std::function<void (void*, AsyncClient*, unsigned int)> const&) at ??:?
0x40230c8e in BearSSL::WiFiClientSecure::connect(char const*, unsigned short) at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\libraries\ESP8266WiFi\src/WiFiClientSecureBearSSL.h:245
0x402206e8 in HardwareSerial::write(unsigned char const*, unsigned int) at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/HardwareSerial.h:191
0x4021f02f in HTTPClient::connect() at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.cpp:867
0x40224645 in __delay at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/core_esp8266_wiring.cpp:57
0x4021fa83 in HTTPClient::sendRequest(char const*, unsigned char const*, unsigned int) at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.cpp:436
0x402265ad in uart_write at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/uart.cpp:544
0x402265ad in uart_write at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/uart.cpp:544
0x402206e8 in HardwareSerial::write(unsigned char const*, unsigned int) at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/HardwareSerial.h:191
0x402206f4 in HardwareSerial::write(unsigned char const*, unsigned int) at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/HardwareSerial.h:194
0x40100458 in ets_post at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/core_esp8266_main.cpp:181
0x4021fc4e in HTTPClient::GET() at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.cpp:356
0x4020bc03 in getChartDataFromApi(String, String, String, String) at src/main.cpp:370
0x40240fd8 in etharp_output_LWIP2 at /home/earle/src/esp-quick-toolchain/arduino/tools/sdk/lwip2/builder/lwip2-src/src/core/ipv4/etharp.c:885
0x402427d0 in ip4_output_if_opt_src at /home/earle/src/esp-quick-toolchain/arduino/tools/sdk/lwip2/builder/lwip2-src/src/core/ipv4/ip4.c:1765
0x40100b39 in umm_free_core at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266\umm_malloc/umm_malloc.cpp:549
0x40100d5d in malloc at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266\umm_malloc/umm_malloc.cpp:821
0x40100b39 in umm_free_core at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266\umm_malloc/umm_malloc.cpp:549
0x40100b39 in umm_free_core at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266\umm_malloc/umm_malloc.cpp:549
0x40100b39 in umm_free_core at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266\umm_malloc/umm_malloc.cpp:549
0x40100d26 in free at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266\umm_malloc/umm_malloc.cpp:595
0x4023aa28 in operator delete(void*) at /workdir/repo/gcc-gnu/libstdc++-v3/libsupc++/del_op.cc:50
0x40100b39 in umm_free_core at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266\umm_malloc/umm_malloc.cpp:549
0x40100d26 in free at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266\umm_malloc/umm_malloc.cpp:595
0x402220f4 in String::init() at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/WString.h:289
(inlined by) String::invalidate() at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/WString.cpp:147
0x4020d9d8 in getPriceFromAPI(String, String) at src/main.cpp:302
0x40100b39 in umm_free_core at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266\umm_malloc/umm_malloc.cpp:549
0x40220073 in EspClass::flashWrite(unsigned int, unsigned char const*, unsigned int) at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/Esp.cpp:884
0x402265ad in uart_write at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/uart.cpp:544
0x402206e8 in HardwareSerial::write(unsigned char const*, unsigned int) at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/HardwareSerial.h:191
0x402206f4 in HardwareSerial::write(unsigned char const*, unsigned int) at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/HardwareSerial.h:194
0x402206e8 in HardwareSerial::write(unsigned char const*, unsigned int) at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/HardwareSerial.h:191
0x40221718 in Print::write(char const*) at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/Print.h:59
(inlined by) unsigned int Print::printNumber<unsigned long>(unsigned long, unsigned char) at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/Print.cpp:264
0x40232b30 in std::function<void (void*, AsyncClient*, unsigned int)>::function(std::function<void (void*, AsyncClient*, unsigned int)> const&) at ??:?
0x402206e8 in HardwareSerial::write(unsigned char const*, unsigned int) at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/HardwareSerial.h:191
0x402206f4 in HardwareSerial::write(unsigned char const*, unsigned int) at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/HardwareSerial.h:194
0x402206e8 in HardwareSerial::write(unsigned char const*, unsigned int) at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/HardwareSerial.h:191
0x402223e9 in String::copy(char const*, unsigned int) at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/WString.cpp:226
0x4020fbb3 in String::~String() at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/WString.h:79
(inlined by) loop at src/main.cpp:731
0x401032ec in wDev_ProcessFiq at ??:?
0x40210da4 in TFT_eSPI::drawChar(unsigned short, int, int, unsigned char) at .pio\libdeps\d1_mini\TFT_eSPI/TFT_eSPI.cpp:4624
0x40222880 in String::isSSO() const at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/WString.h:262
(inlined by) String::setLen(int) at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/WString.h:267
(inlined by) String::concat(char const*, unsigned int) at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/WString.cpp:309
0x40100b39 in umm_free_core at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266\umm_malloc/umm_malloc.cpp:549
0x40213d00 in TFT_eSPI::drawString(char const*, int, int, unsigned char) at .pio\libdeps\d1_mini\TFT_eSPI/TFT_eSPI.cpp:5066
0x40213d00 in TFT_eSPI::drawString(char const*, int, int, unsigned char) at .pio\libdeps\d1_mini\TFT_eSPI/TFT_eSPI.cpp:5066
0x402265ad in uart_write at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/uart.cpp:544
0x40220031 in EspClass::flashWrite(unsigned int, unsigned char const*, unsigned int) at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/Esp.cpp:834
0x40220031 in EspClass::flashWrite(unsigned int, unsigned char const*, unsigned int) at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/Esp.cpp:834
0x40223da2 in loop_wrapper() at C:\Users\Sadfiesch\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/core_esp8266_main.cpp:201