Skip to content
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

ESP Crashing after upgrading to latest version 2.3 #430

Closed
arihantdaga opened this issue Mar 13, 2018 · 15 comments
Closed

ESP Crashing after upgrading to latest version 2.3 #430

arihantdaga opened this issue Mar 13, 2018 · 15 comments
Assignees

Comments

@arihantdaga
Copy link
Contributor

arihantdaga commented Mar 13, 2018

Version/revison of the library used

2.3.3

Expected behavior

Version 1 of library was working fine. Today i updated to v 2.3.3 and i checked ir firing and my esp is crashing everytime it fires a code (right after firing the code i think).
I am firing this with AsyncWebserver and not in the main loop. So i fire IR Code in the callback function after recieving http request.
I know that there is a possibility that esp crashes if delay() is very long. But it was working fine in previous version(Version 1 i guess, in library.json no version is mentioned).
And i also added this code for safety


ESP.wdtDisable();
irsend.sendLG((unsigned long)actCode,length);
ESP.wdtFeed();
ESP.wdtEnable(5000);

Can anybody point out to me whats wrong here.. ?

I am also adding stack trace from esp exception decoder

Exception 9: LoadStoreAlignmentCause: Load or store to an unaligned address
Decoding 94 results
0x40104de0: ets_timer_setfn at ?? line ?
0x40106a34: delayMicroseconds at /Users/iamnostar/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.0/cores/esp8266/core_esp8266_wiring.c line 83
0x40221ebc: IRtimer::reset() at /Users/iamnostar/Documents/Arduino/libraries/IRremoteESP8266/src/IRtimer.cpp line 26
0x4010500c: ets_timer_arm_new at ?? line ?
0x40221bb4: IRsend::mark(unsigned short) at /Users/iamnostar/Documents/Arduino/libraries/IRremoteESP8266/src/IRsend.cpp line 466
0x40201678: delay at /Users/iamnostar/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.0/cores/esp8266/core_esp8266_wiring.c line 46
0x40221a8c: IRsend::ledOff() at /Users/iamnostar/Documents/Arduino/libraries/IRremoteESP8266/src/IRsend.cpp line 466
0x40221c1c: IRsend::space(unsigned int) at /Users/iamnostar/Documents/Arduino/libraries/IRremoteESP8266/src/IRsend.cpp line 466
0x40221e04: IRsend::sendGeneric(unsigned short, unsigned int, unsigned short, unsigned int, unsigned short, unsigned int, unsigned short, unsigned int, unsigned int, unsigned long long, unsigned short, unsigned short, bool, unsigned short, unsigned char) at /Users/iamnostar/Documents/Arduino/libraries/IRremoteESP8266/src/IRsend.cpp line 466
0x40238e79: pbuf_free_LWIP2 at /local/users/gauchard/arduino/arduino_esp8266/origin/tools/sdk/lwip2/builder/lwip2-src/src/core/pbuf.c line 1306
0x40222130: IRsend::sendLG(unsigned long long, unsigned short, unsigned short) at /Users/iamnostar/Documents/Arduino/libraries/IRremoteESP8266/src/ir_LG.cpp line 80
@crankyoldgit
Copy link
Owner

crankyoldgit commented Mar 13, 2018 via email

@crankyoldgit
Copy link
Owner

crankyoldgit commented Mar 14, 2018

Now that I can see the stack trace, this reads more like a language use error/problem.
i.e. A google search of "Exception 9: LoadStoreAlignmentCause: Load or store to an unaligned address" indicates some issues with users using references to objects that no-longer exist. i.e. They (object) were on the stack, and then destroyed, then subsequently tried to be used.

I can't suggest anything more without seeing the real code etc.

TL;DR: I think you've got a coding problem based on that stack trace, not a WDT error etc. The delay thing might be a red-herring. Try reducing your code to as simple as possible that still causes the issue, and post that code here. That process may help you see the cause of the error along the way.

@crankyoldgit
Copy link
Owner

How are you going with this?

@arihantdaga
Copy link
Contributor Author

@crankyoldgit Thank you for explaining this.. I dint get a chance to work on it again, so for now i just rolled back to the previous version, But i'll check this soon..

@crankyoldgit
Copy link
Owner

Friendly ping. How did you go?

@arihantdaga
Copy link
Contributor Author

arihantdaga commented Apr 3, 2018

Still caught up in other things. Will get back to it as soon as possible. :)

@arihantdaga
Copy link
Contributor Author

@crankyoldgit
Hi, I am sorry, I was gone long, was busy with other things.
Today i tried to fix it.

I changed the _delayMicroSeconds() function a little bit.
Turns out that we cannot call delay() in async Callbacks. But delaymicroseconds() goes just fine.

So i updated this code

delay(usec / 1000UL); 
delayMicroseconds(static_cast<uint16_t>(usec % 1000UL));

to this one.


uint16_t wholes =  usec / 1000UL;
    while(wholes--){
      delayMicroseconds(1000);
    }
    delayMicroseconds(static_cast<uint16_t>(usec % 1000UL));

Its working fine right now. I tested it with both sendRaw() and Other Protocol based Functions.
Do you think it's alright to do this ? or will it create any issue ?
If its alright, I can submit the PR.

@crankyoldgit
Copy link
Owner

An issue/feature request is probably best.
Thinking about it, we should set a flag or a compile-time option (i.e. a #define) for this sort of behaviour.
Giving up on using the delay() which feeds the watchdog timer is something that is not really best practice on the ESP8266, so it should be something that a user explicitly requests/configures. I don't want to cause WDT resets for people.

Also, probably best to use a modulus that is much higher than 1000, as each iteration through that loop may lose microseconds with the while/decrement statements.

crankyoldgit added a commit that referenced this issue May 4, 2018
Per Issue #430, the use of delay() calls is incompatible with the AsyncWebserver
library. Give users of the library a way to send IR messages without the delay()
calls which cause it to break the callbacks of AsyncWebserver. This is not
without risk as the delay() calls feed the WDT.

No delay() calls means the user can easily cause the WDT to reset the ESP8266.
Thus the default is to use delay() calls where possible, and make this a
compile-time option to try to limit people shooting themselves in the foot.
@crankyoldgit
Copy link
Owner

crankyoldgit commented May 4, 2018

@arihantdaga Can you please try out the new branch https://github.com/markszabo/IRremoteESP8266/tree/asyncweb-support and let me know if it fixes your issue? I've just added what I think will support what you want to do w.r.t. AsyncWebserver etc.

Per the new comments in IRremoteESP8266.h you'll need to set ALLOW_DELAY_CALLS to false for your situation.

@arihantdaga
Copy link
Contributor Author

arihantdaga commented May 6, 2018 via email

@crankyoldgit
Copy link
Owner

Did the changes I made work for you?

@arihantdaga
Copy link
Contributor Author

arihantdaga commented May 7, 2018 via email

@crankyoldgit
Copy link
Owner

Excellent. I'll mark this closed when the PR is merged in.

crankyoldgit added a commit that referenced this issue May 7, 2018
Per Issue #430, the use of delay() calls is incompatible with the AsyncWebserver
library. Give users of the library a way to send IR messages without the delay()
calls which cause it to break the callbacks of AsyncWebserver. This is not
without risk as the delay() calls feed the WDT.

No delay() calls means the user can easily cause the WDT to reset the ESP8266.
Thus the default is to use delay() calls where possible, and make this a
compile-time option to try to limit people shooting themselves in the foot.
@crankyoldgit
Copy link
Owner

Merged in to the master branch. Closing this now.

@crankyoldgit
Copy link
Owner

FYI, the fix was included in the latest offical release of the library. (v2.4.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants