-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ESP8266 crashes when used with low RAM/Heaps available. EXCEPTION (29) #56
Comments
i was thinking if that space is reserved for the wifi stack and causes the ecxeption.
i wonder if it's possible to check the wifi stack size...? apart from that, i checked the addresses "3FFF3***" from the serial monitor and they seem to be well within range of the user RAM "dram1". can't be an out-of-range issue then.
source: Memory Map |
UPDATE: when i run that everything looks normal. stack size: 4KB and free stack around 1000B-1400B. but if the free heap size gets lower than 4KB it would cause a crash. (i assume) a successfull sendMessage free heap size goes:
which is quite close to 4KB..
and then it crashes in UniversalTelegramBot.cpp in function "UniversalTelegramBot::sendPostToTelegram" on exactly this line (est. 74):
which means its quite certainly not a bug in UniversalTelegramBot, but rather somewhere else. i did find another thread with a very similar issue in the esp8266 core
and devyte's response:
if it's the same issue i see little i can do about it... someone another idea? |
If it helps, I also got Exception(29) with the telegram bot, shown here: Aypac/Arduino-TR-064-SOAP-Library#2 (comment) |
@gon0 making a https connection uses 18k of heap memory, I presume you are out of memory by the time out get down to the telegram line |
@witnessmenow Yeah, seems like that. |
UPDATE
it sounds as if there's a pull request with a better solution which will fix this issue in the future. in my case the ESP crashed when free heap went under ~4.5KB. but that's not always the same it seems.
which implies his heap went down to near zero... |
FWIW, I updated my Arduino IDE to use the latest ESP8266 library following instructions here: https://github.com/esp8266/Arduino#using-git-version Now my sloppy mashup of the excellent Universal-Arduino-Telegram-Bot and a webserver based on this other excellent code: https://tttapa.github.io/ESP8266/Chap16%20-%20Data%20Logging.html Previously, it crashed repeatedly on |
Hello
I ran into a problem which i tried to investigate in the last week.
I'm using an ESP8266, wemos D1mini, and was able to reproduce the crash using the PhotoFromURL example.
This submitted issue might probably be a dublicate of #51 and #52 . Feel free to move and modify my post in any way you see fit.
Also note that this issue might be caused by ArduinoJSON or another library which Universal-Arduino-atelegram-Bot relies upon.
The crash occurs when sending messages. In my project the ESP crashes after sending 2-5 messages. Using the unmodified PhotoFromURL example it takes about 100-300 messages within ~3 minutes, which resulted in an Exception (29) crash.
I slightly modified the example and filled the RAM with a big global char array and wrote ESP.GetFreeHeap() to the serial output, which triggers the crash after sending ~10 messages.
The exception always occurs when the free heap size decreses beneath ~6500-5700.
The free heap size increases automatically when ~3min have passed. I assume the old buffers or something gets deleted when they are older than ~3min. The RAM gets filled the fastest when alternating between different messages, using my sketch: /get_test_photo and /status .
I enabled the _debug bool in UniversalTelegramBot.h
This is the modified sketch:
telegram_exceptionist.zip
Here 3 possible combinations and their outcome:
telegram_exeptionist.ino using WiFiClientSecure without filling RAM (no char array):
Sketch uses 296285 bytes (28%) of program storage space. Maximum is 1044464 bytes.
Global variables use 40484 bytes (49%) of dynamic memory, leaving 41436 bytes for local variables. Maximum is 81920 bytes.
Uploading 300432 bytes
free heaps:
at start 17300 B
crashes after 6160 B
(this was almost impossible since 100-300 messages have to be sent, but the RAM starts to free up again after ~3min.)
Serial output: [expand]
GET Update Messages .... connected to server{"ok":true,"result":[{"update_id":72978882,
"message":{"message_id":1980,"from":{"id":xxxxxxxx,"is_bot":false,"first_name":"Dejan","last_name":"Lauber","language_code":"en-US"},"chat":{"id":xxxxxxxx,"first_name":"Dejan","last_name":"Lauber","type":"private"},"date":1508349619,"text":"/status","entities":[{"offset":0,"length":7,"type":"bot_command"}]}}]}
incoming message length357
Creating DynamicJsonBuffer
got response
handleNewMessages
1
free heap: 6344 B
msg length: 298
sendMessage start: 8789721 ms
SEND Post Message
Exception (29):
epc1=0x4000e1b2 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000004 depc=0x00000000
ctx: cont
sp: 3fff0ee0 end: 3fff1500 offset: 01a0
ets Jan 8 2013,rst cause:2, boot mode:(1,6)
ets Jan 8 2013,rst cause:4, boot mode:(1,6)
wdt reset
telegram_exeptionist.ino using WiFiClientSecure and filling RAM:
Sketch uses 296389 bytes (28%) of program storage space. Maximum is 1044464 bytes.
Global variables use 50580 bytes (61%) of dynamic memory, leaving 31340 bytes for local variables. Maximum is 81920 bytes.
Uploading 300544 bytes
free heaps:
at start 7400 B
crashes after 6000 B
Serial output: [expand]
GET Update Messages .... connected to server{"ok":true,"result":[{"update_id":72978902,
"message":{"message_id":2016,"from":{"id":xxxxxxxx,"is_bot":false,"first_name":"Dejan","last_name":"Lauber","language_code":"en-US"},"chat":{"id":xxxxxxxx,"first_name":"Dejan","last_name":"Lauber","type":"private"},"date":1508350789,"text":"/status","entities":[{"offset":0,"length":7,"type":"bot_command"}]}}]}
incoming message length357
Creating DynamicJsonBuffer
got response
handleNewMessages
1
free heap: 6000 B
msg length: 298
sendMessage start: 29404
SEND Post Message
Exception (29):
epc1=0x4000e1b2 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000004 depc=0x00000000
ctx: cont
sp: 3fff3650 end: 3fff3c70 offset: 01a0
ets Jan 8 2013,rst cause:2, boot mode:(1,6)
ets Jan 8 2013,rst cause:4, boot mode:(1,6)
wdt reset
telegram_exeptionist.ino using HTTPSredirect and filling RAM:
I followed @witnessmenow 's suggestion in issue #52 to try HTTPSredirect instead of WiFiClientSecure. The same crash occurs.
Sketch uses 297021 bytes (28%) of program storage space. Maximum is 1044464 bytes.
Global variables use 51076 bytes (62%) of dynamic memory, leaving 30844 bytes for local variables. Maximum is 81920 bytes.
Uploading 301168 bytes
free heaps:
at start 6800 B
crashes after 5700 B
Serial output: [expand]
GET Update Messages .... connected to server{"ok":true,"result":[{"update_id":72978915,
"message":{"message_id":2047,"from":{"id":xxxxxxxx,"is_bot":false,"first_name":"Dejan","last_name":"Lauber","language_code":"en-US"},"chat":{"id":xxxxxxxx,"first_name":"Dejan","last_name":"Lauber","type":"private"},"date":1508501057,"text":"/status","entities":[{"offset":0,"length":7,"type":"bot_command"}]}}]}
incoming message length357
Creating DynamicJsonBuffer
got response
handleNewMessages
1
free heap: 5728 B
msg length: 298
sendMessage start: 72291
SEND Post Message
Exception (29):
epc1=0x4000e1b2 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000004 depc=0x00000000
ctx: cont
sp: 3fff3840 end: 3fff3e60 offset: 01a0
ets Jan 8 2013,rst cause:2, boot mode:(1,6)
ets Jan 8 2013,rst cause:4, boot mode:(1,6)
wdt reset
Notes
when the ESP crashes and dumps its stack, it waits 3s until the last line "wdt reset" happens.
i installed and tried the Arduino ESP8266/ESP32 Exception Stack Trace Decoder with an interesting first line. Apart from that i'm not sure what to look for..
The decoded output: [expand]
Exception 29: StoreProhibited: A store referenced a page mapped with an attribute that does not permit stores
Decoding 35 results
0x40223c0f: AES_cbc_decrypt at /Users/igrokhotkov/e/axtls/e1/crypto/aes.c line 337 (discriminator 2)
0x40223da8: trim at /Users/igrokhotkov/e/axtls/e1/crypto/bigint.c line 1203
0x4022405a: bi_terminate at /Users/igrokhotkov/e/axtls/e1/crypto/bigint.c line 119
0x40205f74: String::substring(unsigned int, unsigned int) const at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/WString.cpp line 618
0x40224bb6: bi_set_mod at /Users/igrokhotkov/e/axtls/e1/crypto/bigint.c line 749
0x40224e11: precompute_slide_window at /Users/igrokhotkov/e/axtls/e1/crypto/bigint.c line 1327
: (inlined by) bi_mod_power at /Users/igrokhotkov/e/axtls/e1/crypto/bigint.c line 1372
0x40223c74: htonl at /Users/igrokhotkov/e/axtls/e1/ssl/os_port.h line 209 (discriminator 2)
: (inlined by) AES_cbc_decrypt at /Users/igrokhotkov/e/axtls/e1/crypto/aes.c line 347 (discriminator 2)
0x40225e9d: RSA_print at /Users/igrokhotkov/e/axtls/e1/crypto/rsa.c line 230
0x40221fa8: verify_digest at /Users/igrokhotkov/e/axtls/e1/ssl/tls1.c line 610
: (inlined by) basic_read at /Users/igrokhotkov/e/axtls/e1/ssl/tls1.c line 1336
0x402223a9: process_server_hello at /Users/igrokhotkov/e/axtls/e1/ssl/tls1_clnt.c line 293
: (inlined by) do_clnt_handshake at /Users/igrokhotkov/e/axtls/e1/ssl/tls1_clnt.c line 89
0x402030bb: ClientContext::_consume(unsigned int) at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/libraries/ESP8266WiFi/src/WiFiClientSecure.cpp line 517
: (inlined by) ClientContext::read(char*, unsigned int) at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/libraries/ESP8266WiFi/src/include/ClientContext.h line 175
0x40221da0: verify_digest at /Users/igrokhotkov/e/axtls/e1/ssl/tls1.c line 709
: (inlined by) basic_read at /Users/igrokhotkov/e/axtls/e1/ssl/tls1.c line 1336
0x40222148: send_client_hello at /Users/igrokhotkov/e/axtls/e1/ssl/tls1_clnt.c line 200
: (inlined by) do_client_connect at /Users/igrokhotkov/e/axtls/e1/ssl/tls1_clnt.c line 153
0x401004d8: malloc at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/umm_malloc/umm_malloc.c line 1664
0x40221ef8: basic_read at /Users/igrokhotkov/e/axtls/e1/ssl/tls1.c line 1381
0x4020352d: WiFiClientSecure::_connectSSL(char const*) at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/libraries/ESP8266WiFi/src/WiFiClientSecure.cpp line 517
0x40202a12: WiFiClient::connect(IPAddress, unsigned short) at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/libraries/ESP8266WiFi/src/WiFiClient.cpp line 327
0x4020373d: WiFiClientSecure::connect(char const*, unsigned short) at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/libraries/ESP8266WiFi/src/WiFiClientSecure.cpp line 265
0x40204ad9: ArduinoJson::Internals::JsonSerializer > >::serialize(ArduinoJson::JsonVariant const&, ArduinoJson::Internals::JsonWriter >&) at /home/brian/share/arduino/libraries/UniversalTelegramBot/src/UniversalTelegramBot.cpp line 283
0x40205aa3: UpdaterClass::UpdaterClass() at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/Updater.cpp line 373
0x40205ad5: _GLOBAL__sub_D__ZN12UpdaterClassC2Ev at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/Updater.cpp line 375
0x40205b98: String::reserve(unsigned int) at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/WString.cpp line 589
0x40204d1c: UniversalTelegramBot::sendPostToTelegram(String, ArduinoJson::JsonObject&) at /home/brian/share/arduino/libraries/UniversalTelegramBot/src/UniversalTelegramBot.cpp line 283
0x40203cd4: ArduinoJson::JsonObject& ArduinoJson::JsonObject::createNestedObject_impl (char const*) at /home/brian/share/arduino/libraries/UniversalTelegramBot/src/UniversalTelegramBot.cpp line 283
0x40204ded: StringSumHelper at /home/brian/share/arduino/libraries/UniversalTelegramBot/src/UniversalTelegramBot.cpp line 283
: (inlined by) UniversalTelegramBot::sendPostMessage(ArduinoJson::JsonObject&) at /home/brian/share/arduino/libraries/UniversalTelegramBot/src/UniversalTelegramBot.cpp line 462
0x40205b26: String::init() at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/WString.cpp line 589
: (inlined by) String::invalidate() at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/WString.cpp line 135
0x40202164: handleNewMessages(int) at /home/brian/share/arduino/telegram_exceptionist/telegram_exceptionist.ino line 65
0x402059f8: Print::println(unsigned int, int) at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/Print.cpp line 76
0x4020639c: ArduinoJson::Internals::JsonBufferAllocated::operator new(unsigned int, ArduinoJson::JsonBuffer*) at /home/brian/share/arduino/libraries/ArduinoJson/src/ArduinoJson/Data/JsonBufferAllocated.hpp line 19
0x402056e9: HardwareSerial::begin(unsigned long, SerialConfig, SerialMode, unsigned char) at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/HardwareSerial.cpp line 193
0x40205714: _GLOBAL__sub_I__ZN14HardwareSerialC2Ei at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/HardwareSerial.cpp line 197
0x40202389: loop at /home/brian/share/arduino/telegram_exceptionist/telegram_exceptionist.ino line 111
0x40205fc0: operator delete(void*) at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/abi.cpp line 57
0x40100718: cont_norm at /home/brian/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/cores/esp8266/cont.S line 109
Build options:
Board: "Wemos D1 R2 & mini"
CPU Frequency: "80MHz"
Flash Size: "4M (3M SPIFFS)"
Upload Speed: "921600"
Other things i've tried:
Different USB Power adapter. no effect.
I got the same crash on another ESP8266, with different power adapter and cable.
470uF Capacitor is in place on the 5V rail.
Added a 2200uF Capacitor to the 3.3V rail. no effect.
changed to 1M flash size. no effect.
changed clock to 160mhz. no effect.
If anyone has a clue on how to resolve this issue, or an idea on what to try next, let me know.
Best regards,
dejan lauber
PS: The ESP8266 and this telegram library blew my mind! Awesome work!
The text was updated successfully, but these errors were encountered: