probonopd / ESP8266HueEmulator

Emulate a Philips Hue bridge running on an ESP8266 using the Arduino IDE.
MIT License
411 stars 93 forks source link

exception (28) #95

Open rmuike opened 6 years ago

rmuike commented 6 years ago

i get this crash, i am using a nodemcu esp8266 ESP-12E Setting in arduino ide CPU 80 Mhz Flash size 4M(3M spffs) upload speed 115200

everything worked the first time i tried but as soon as i hit the save button during first setup in ios app, it crashes and gives me this error ⸮..Starting HTTP at 192.168.1.45:80 Starting SSDP... SSDP Started FS Starting initializeGroupSlots() Reading in to buffer Loading GROUP-0.json initializeSceneSlots() Reading in to buffer Loading SCENE-0.json Reading in to buffer Loading SCENE-1.json Reading in to buffer Loading SCENE-2.json Reading in to buffer Loading SCENE-3.json Reading in to buffer

Exception (28): epc1=0x4021348e epc2=0x00000000 epc3=0x00000000 excvaddr=0x0000000c depc=0x00000000

ctx: cont sp: 3fff19a0 end: 3fff1ca0 offset: 01a0

stack>>> 3fff1b40: 3ffe98f4 3fff0bbc 3fff0ac8 402131d8
3fff1b50: 00000000 3fff0bbc 3fff6284 402081a1
3fff1b60: 00000000 3fff6290 00000004 401004d8
3fff1b70: 00000000 00000000 00000000 00000000
3fff1b80: 3fff6284 3fff0bbc 00000004 4020b3b5
3fff1b90: 3ffea418 00000000 000003e8 4020b2ed
3fff1ba0: 3fff4a3c 3fff4a7c 00000000 00000000
3fff1bb0: 00000000 3fff4994 0000000f 0000000c
3fff1bc0: 00000000 00000000 00000000 00000000
3fff1bd0: 402090e8 3fff061c 3fff0bbc 3fff0610
3fff1be0: 402090e8 3fff061c 3fff0bbc 4020ba20
3fff1bf0: 3fff496c 0000001f 00000011 402077d8
3fff1c00: 00000000 00000000 00000000 00000000
3fff1c10: 00000000 00000000 3fff3ef4 402147a2
3fff1c20: 3fff1c00 3fff04f4 3ffe98f4 40210a98
3fff1c30: 00000000 00000000 3fff3624 3fff04f4
3fff1c40: 3fff0a94 3fff04f4 3fff3624 4020ba60
3fff1c50: 3fff0a94 00000000 00000000 402076b4
3fff1c60: 00000000 00000000 00000000 40206c6c
3fff1c70: feefeffe feefeffe feefeffe 3fff0c78
3fff1c80: 3fffdad0 00000000 3fff0c72 402151c8
3fff1c90: feefeffe feefeffe 3fff0c80 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

then i tried to reset it and it just keeps repeating this over and over again ⸮..Starting HTTP at 192.168.1.45:80 Starting SSDP... SSDP Started FS Starting initializeGroupSlots() Reading in to buffer Loading GROUP-0.json initializeSceneSlots() Reading in to buffer Loading SCENE-0.json Reading in to buffer Loading SCENE-1.json Reading in to buffer Loading SCENE-2.json Reading in to buffer Loading SCENE-3.json Reading in to buffer

Exception (28): epc1=0x4021348e epc2=0x00000000 epc3=0x00000000 excvaddr=0x0000000c depc=0x00000000

ctx: cont sp: 3fff19a0 end: 3fff1ca0 offset: 01a0

stack>>> 3fff1b40: 3ffe98f4 3fff0bbc 3fff0ac8 402131d8
3fff1b50: 00000000 3fff0bbc 3fff6284 402081a1
3fff1b60: 00000000 3fff6290 00000004 401004d8
3fff1b70: 00000000 00000000 00000000 00000000
3fff1b80: 3fff6284 3fff0bbc 00000004 4020b3b5
3fff1b90: 3ffea418 00000000 000003e8 4020b2ed
3fff1ba0: 3fff4a3c 3fff4a7c 00000000 00000000
3fff1bb0: 00000000 3fff4994 0000000f 0000000c
3fff1bc0: 00000000 00000000 00000000 00000000
3fff1bd0: 402090e8 3fff061c 3fff0bbc 3fff0610
3fff1be0: 402090e8 3fff061c 3fff0bbc 4020ba20
3fff1bf0: 3fff496c 0000001f 00000011 402077d8
3fff1c00: 00000000 00000000 00000000 00000000
3fff1c10: 00000000 00000000 3fff3ef4 402147a2
3fff1c20: 3fff1c00 3fff04f4 3ffe98f4 40210a98
3fff1c30: 00000000 00000000 3fff3624 3fff04f4
3fff1c40: 3fff0a94 3fff04f4 3fff3624 4020ba60
3fff1c50: 3fff0a94 00000000 00000000 402076b4
3fff1c60: 00000000 00000000 00000000 40206c6c
3fff1c70: feefeffe feefeffe feefeffe 3fff0c78
3fff1c80: 3fffdad0 00000000 3fff0c72 402151c8
3fff1c90: feefeffe feefeffe 3fff0c80 40100718
<<<stack<<<

ets Jan 8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16 tail 8 chksum 0x2d csum 0x2d v3fff2328 ~ld then i tried with a new board and the exact same thing happend, it worked the first time and then this error. i have tried re uploading the sketch but i get the same thing, i really dont know what to do, so if any one can help i would appreciate that very much.

Edit: I googled some more and found something called stack trace, hwen i trace it it gives me this. Exception 28: LoadProhibited: A load referenced a page mapped with an attribute that does not permit loads Decoding 17 results 0x4021348a: aJsonClass::getObjectItem(aJsonObject, char const) at C:\Users\1234\Documents\Arduino\libraries\aJson/aJSON.cpp line 970 0x402131d4: aJsonClass::parse(aJsonStream) at C:\Users\1234\Documents\Arduino\libraries\aJson/aJSON.cpp line 970 0x402081a1: LightGroup::LightGroup(aJsonObject) at C:\Users\1234\AppData\Local\Temp\arduino_build_853378\sketch/LightService.cpp line 1695 0x401004d8: malloc at C:\Users\1234\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266\umm_malloc/umm_malloc.c line 1664 0x4020b2a9: initializeGroupSlots() at C:\Users\1234\AppData\Local\Temp\arduino_build_853378\sketch/LightService.cpp line 1695 0x40213df9: Print::write(char const) at C:\Users\1234\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/Print.cpp line 76 0x402090e8: scenesIdLightFn(WcFnRequestHandler, String, HTTPMethod) at C:\Users\1234\AppData\Local\Temp\arduino_build_853378\sketch/LightService.cpp line 1695 0x402090e8: scenesIdLightFn(WcFnRequestHandler, String, HTTPMethod) at C:\Users\1234\AppData\Local\Temp\arduino_build_853378\sketch/LightService.cpp line 1695 0x4020ba1d: LightServiceClass::begin(ESP8266WebServer) at C:\Users\1234\AppData\Local\Temp\arduino_build_853378\sketch/LightService.cpp line 1695 0x402077d8: std::_Function_handler ::_M_invoke(std::_Any_data const&, WcFnRequestHandler, String, HTTPMethod) at C:\Users\1234\AppData\Local\Temp\arduino_build_853378\sketch/LightService.cpp line 1695 0x402147ce: String::String(char const) at C:\Users\1234\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/WString.cpp line 720 0x40210a94: HTTPUpload::HTTPUpload() at C:\Users\1234\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\ESP8266WebServer\src\detail/RequestHandlersImpl.h line 53 0x4020ba60: LightServiceClass::begin() at C:\Users\1234\AppData\Local\Temp\arduino_build_853378\sketch/LightService.cpp line 1695 0x402076b0: setup at C:\Users\1234\Desktop\ESP8266HueEmulator-master\ESP8266HueEmulator/ESP8266HueEmulator.ino line 180 (discriminator 2) 0x40206c6c: _M_invoke at c:\users\1234\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\include\c++\4.8.2/functional line 2069 0x402151f4: loop_wrapper at C:\Users\1234\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/core_esp8266_main.cpp line 56 0x40100718: cont_norm at C:\Users\1234\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/cont.S line 109

Quanghoster commented 6 years ago

Try commenting out the call to initializeSceneSlots(). I will take a look at it tomorrow evening

Quanghoster commented 6 years ago

Ok, I can see where the way this is working at the moment is most likely causing the Heap to run out of memory which is causing the exception 28 and reboots. I'm guessing different boards have differing amounts of RAM which is probably why some are experiencing it earlier than others. In my case if I get up 2 groups and 4 scenes I end up with exception 28 when a client polls to retrieve the device config. When it get to add the scenes to the response, it creates the Json response, taking up heap and it then creates a char buffer version of the response in sendJson(). I think there are a couple of approaches we can use to resolve this. 1) Look in to streaming the Json response instead of sending the char buffer. Not sure this will solve the problem if internally the approach is the same, but worth investigating. 2) move away totally from using the heap to store group and scene info. Currently this info is stored on the heap in the following arrays

LightGroup lightGroups[16] = {nullptr, }; LightGroup lightScenes[16] = {nullptr, };

My mods were simply saving changes to SPIFFS files and reloading from these files on start up. I will look into updating the code so that these arrays are no longer used and SPIFFS is read to recover the info. This will free up some of the heap atleast.

LarsHanegraaf commented 6 years ago

Hi all,

I've got the same problem at exactly the same moment as described by @rmuike . (However I'm using an Adafruit Feather HUZZAH ESP8266).

I also found out how to generate a stacktrace using EspExceptionDecoder. However in my stacktrace it references to line 491 of SSDP.cpp, so I'm not sure whether it is a memory issue as described above (@Quanghoster).

Since I have no experience in C++, I can not confirm this, but hope that someone has extra information to solve this issue.

Please find my stacktrace attached:

0x4020bd84: UdpContext::_reserve(unsigned int) at C:\Users\<user>\AppData\Local\Temp\arduino_build_497420\sketch/SSDP.cpp line 491
:  (inlined by) UdpContext::append(char const*, unsigned int) at C:\Users\<user>\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\ESP8266WiFi\src/include/UdpContext.h line 237
:  (inlined by) SSDPClass::_send(ssdp_method_t) at C:\Users\<user>\AppData\Local\Temp\arduino_build_497420\sketch/SSDP.cpp line 220
0x4023b9ec: ip_output_if at /Users/igrokhotkov/espressif/arduino/tools/sdk/lwip/src/core/ipv4/ip.c line 631
0x4023a20d: udp_sendto_if at /Users/igrokhotkov/espressif/arduino/tools/sdk/lwip/src/core/udp.c line 674
0x4010068c: free at C:\Users\<user>\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266\umm_malloc/umm_malloc.c line 1733
0x4023a271: udp_sendto at /Users/igrokhotkov/espressif/arduino/tools/sdk/lwip/src/core/udp.c line 465
0x4010020c: _umm_free at C:\Users\<user>\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266\umm_malloc/umm_malloc.c line 1287
0x4010068c: free at C:\Users\<user>\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266\umm_malloc/umm_malloc.c line 1733
0x40214674: String::~String() at C:\Users\<user>\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/WString.cpp line 720
0x4020e513: MDNSResponder::_reply(unsigned char, char*, char*, unsigned short) at C:\Users\<user>\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\ESP8266mDNS/ESP8266mDNS.cpp line 384
0x4020e101: String::length() const at C:\Users\<user>\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\ESP8266mDNS/ESP8266mDNS.cpp line 384
:  (inlined by) MDNSResponder::_reply(unsigned char, char*, char*, unsigned short) at C:\Users\<user>\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\ESP8266mDNS/ESP8266mDNS.cpp line 870
0x4020e95d: MDNSResponder::_parsePacket() at C:\Users\<user>\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\ESP8266mDNS/ESP8266mDNS.cpp line 384
0x4010522e: lmacTxFrame at ?? line ?
0x4021b3cb: pp_attach at ?? line ?
0x4021b41e: pp_attach at ?? line ?
0x4021b52a: pp_attach at ?? line ?
0x40102006: pp_post at ?? line ?
0x4021a86f: ppTxPkt at ?? line ?
0x402225c0: ieee80211_output_pbuf at ?? line ?
0x4021b3cb: pp_attach at ?? line ?
0x4021b3cb: pp_attach at ?? line ?
0x4021a824: ppTxPkt at ?? line ?
0x402225c0: ieee80211_output_pbuf at ?? line ?
0x4023a524: etharp_send_ip at /Users/igrokhotkov/espressif/arduino/tools/sdk/lwip/src/netif/etharp.c line 435
0x4010020c: _umm_free at C:\Users\<user>\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266\umm_malloc/umm_malloc.c line 1287
0x40100648: _umm_realloc at C:\Users\<user>\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266\umm_malloc/umm_malloc.c line 1616
:  (inlined by) realloc at C:\Users\<user>\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266\umm_malloc/umm_malloc.c line 1709
0x402146d0: String::changeBuffer(unsigned int) at C:\Users\<user>\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/WString.cpp line 720
0x40101b9a: ppEnqueueRxq at ?? line ?
0x40102006: pp_post at ?? line ?
0x40220e5e: ieee80211_ht_updateparams at ?? line ?
0x402273c8: cnx_update_bss_more at ?? line ?
0x40225179: scan_parse_beacon at ?? line ?
0x402251d9: scan_parse_beacon at ?? line ?
0x402250c1: scan_parse_beacon at ?? line ?
0x40105af5: ets_timer_disarm at ?? line ?
0x40105af5: ets_timer_disarm at ?? line ?
0x4021513f: loop_task at C:\Users\<user>\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/core_esp8266_main.cpp line 56
0x40107776: cont_check at C:\Users\<user>\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/cont_util.c line 42
0x40215147: loop_task at C:\Users\<user>\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/core_esp8266_main.cpp line 56
0x4021cd52: esf_buf_recycle at ?? line ?
0x401059aa: wdt_feed at ?? line ?
0x4020c24c: SSDPClass::_update() at C:\Users\<user>\AppData\Local\Temp\arduino_build_497420\sketch/SSDP.cpp line 491
0x4022f0ec: ets_timer_handler_isr at ?? line ?
0x4020c2a4: SSDPClass::_onTimerStatic(SSDPClass*) at C:\Users\<user>\AppData\Local\Temp\arduino_build_497420\sketch/SSDP.cpp line 491
0x4022f0f9: ets_timer_handler_isr at ?? line ?
0x4022f13e: ets_timer_handler_isr at ?? line ?
0x4021513f: loop_task at C:\Users\<user>\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/core_esp8266_main.cpp line 56

Thanks!

xifer commented 6 years ago

Looks like a few memory leaks in scenePutHandler and sceneCreationHandler (LightService.cpp), I changed:

char* json = aJson.print(lightScenes[sceneIndex]->getSceneJson(true));
f.print(json);

to

aJsonObject *json_object = lightScenes[sceneIndex]->getSceneJson(true);

char* json = aJson.print(json_object);
f.print(json);
f.close();
free(json);
aJson.deleteItem(json_object);

I've also been formatting the SPIFFS each time I run it.

SPIFFS.format(); after SPIFFS.begin(); in LightService.cpp

This work for anyone else?

MopheusDG commented 6 years ago

Not working for me even with those changes to LightService.cpp. As soon as I create the Room, I get this error:

Updating Scene 6SCENE-6.json Adding lightstates

Exception (28): epc1=0x4020b9c7 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000008 depc=0x00000000

ctx: sys sp: 3ffff790 end: 3fffffb0 offset: 01a0

Pfulben commented 6 years ago

Hi all! I have the same problem. With the solution of xifer I got rid of the exception, but I was not able to save a Room. Any update? Thanks!