-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Crashes and libraries that use interrupts #1020
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
Comments
maybe if the library starts to use our attachInterrupt/detachInterrupt routines, then it might work. |
Thanks for the tip, I will look at that. |
I have taken a look at this library and couldn't find any obvious reason why it would have to crash, especially during WiFi events. This needs some investigation, perhaps @plerup can give some pointers. |
I'm having similar symptom not with some specific library but attachInterrupt(). |
I had to disable the interrupts while processing WebServer requests too. |
@adrionics What baud rate are you using? |
9600 or 2400, both have the problem. |
I tried disabling interrupt while handling http request and enabling back afterward but still crashing. const int PIR = 12; void loop(void) { void enableInterrupt() { void disableInterrupt() { void processPresence() { .... |
I fixed it by adding these two functions to the ESP SoftwareSerial library: Then, call them before and after. |
I found a glitch in my code. I forgot to comment out a single debugging message using softwareserial.... |
If it helps just to disable the interrupts then there must be something triggering them when you get the crash. Maybe noise on the used rx pin. As I stated in the comment in the source code the interrupt seems to trigger on any change on the pin although GPIO_PIN_INTR_NEGEDGE has been set. I assume it's not real serial traffic in your case because then you would have missed it by disabling the interrupts. |
plerup, I suspect it may be noise or real serial traffic that triggers the crash - as you say, any change on the pin. I sometimes do miss serial packets while the interrupt is disabled, but luckily in my case this does not matter. I believe that if an interrupt is triggered for any reason, and the device is in the process of handling some routine like WiFi.begin, it crashes. |
PS, it becomes more apparent with a fast stream of serial data. If the serial data is at a low rate, you may need to wait for an exact "while the WiFi / server" functions are called interrupt crash. |
I too can confirm this issue. My code keeps crashing during wificlient sessions with SofwareSerial enabled. After using @adrionics disable/enable functions it seems to be working better. |
@adrionics You sir, are a life saver !! Was using a interrupt based power measurement on ESP while making HTTP requests. It used to crash randomly and was unable to debug. Boy oh boy did this post come handy !! Switched to non-interrupt based power measurement and its working fine now :) |
Im having similar problem, using WIFI_AP_STA mode, WebServer on port 80, and simultaneous connecting to a local network. When enabling a timer 0 or 1 interrupt to blink a led, ESP start to crash randomly. |
Are you using the generic C wifi functions or the Arduino ESP8266WiFi header? I had a dreadful problem where my ESP8266 kept crashing on an interrupt. The interrupt was triggering a sequence of wifi, webserver, and dnsserver setup functions. At first I assumed it was just something with the interrupt. However, after narrowing down the possibilities, I discovered it was caused by mix and matching generic C wifi functions and Arduino WiFi methods. I had something like this:
instead of something like this:
Hope this helps some people! |
AltSoftSerial solved the problem for me. I initially had SoftwareSerial and my AJAX requests would get errors and disrupts Serial communications. |
I wanted to let others know that if you use a library that uses interrupts, those interrupt events may cause your ESP to crash if you call WiFi or WiFiClient functions and an interrupt happens while the call is in progress.
I experienced this with the excellent SoftwareSerial port from here: https://github.com/plerup/espsoftwareserial.
The solution was to add functions to the library to disable the interrupts and then call that disable function before calling the WiFi and Client functions, then re-enable interrupts after.
Hope this helps some who may be experiencing crashes that may be hard to stop or explain!
The text was updated successfully, but these errors were encountered: