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

ESP8266 might crash in S8_UART::serial_read_bytes if sensor not connected #4

Open
EricDuminil opened this issue Jul 4, 2022 · 2 comments

Comments

@EricDuminil
Copy link

In https://github.com/jcomas/S8_UART/blob/main/examples/co2/co2.cpp, if Senseair S8 isn't connected, the example code is supposed to display Serial.println("SenseAir S8 CO2 sensor not found!");.

On a ESP8266, it often doesn't. The microcontroller crashes instead, because the while loop in S8_UART::serial_read_bytes blocks during 5 seconds, and the watchdog resets the ESP.

Adding a short delay (e.g. delay(50)) in the loop, before end_t = millis(); seems to fix the problem.

Other than that, the library seems to work well, on both ESP32 and ESP8266.
On ESP8266, I replaced SoftwareSerial with https://github.com/CrazyRobMiles/Esp8266EdgeSoftwareSerial, which uses much less memory.
Thanks for the good work!

@jcomas
Copy link
Owner

jcomas commented Jul 4, 2022

Can you try adding "yield" instead of delay in S8_UART::serial_read_bytes ?

while (((end_t - start_t) <= timeout_ms) && !readed) {

     yield();

     if(mySerial->available()) {
          nb = mySerial->readBytes(buf_msg, max_bytes);
          readed = true;
     }
     end_t = millis();
}

@EricDuminil
Copy link
Author

Yes, yield(); seems to also fix the problem.

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

No branches or pull requests

2 participants