Hello everyone,
I have a project but my NodeMCU keeps resetting with causes 2 (even when I changed pins in order not to use D0, D2 and D8 because I read that they cause boot mode) and 4. This is causing my code to restart all over again every around 1 minute.
Exception (0):
epc1=0xc0030037 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
#include <SoftwareSerial.h>
SoftwareSerial mySerial(D2, -1, true, 128);
char telegram[64];
int readTelegram();
void setup()
{
Serial.begin(115200); // 115200 256000
mySerial.begin(115200);
}
void loop() {
int t = readTelegram();
yield();
}
int readTelegram() {
if (mySerial.available() > 0) {
int len = 0;
char c;
unsigned long timeout = 2;
unsigned long start = millis();
while ((len < 63) && (millis() - start < timeout)) {
c = mySerial.read();
if ((c == '\n') || (c == '\r')) break;
if ((c >= 32) && (c <= 126)) {
telegram[len++] = c;
}
yield();
}
telegram[len] = 0;
return len;
}
else return 0;
}
Pin D2 is connected to my “Smart Meter”, which generates a 27 lines, all terminated with \r\n.
Each line is max 47 char long (shortest is 5 char, longest 47 char).
It is at 115200 baud, with inverted signal.
The lines are sent every 10 sec.
Sometimes there is some garbage, and sometimes no \r\n is received, so I have a timeout (2mSec) and a filter (c = 32-127).
Earlier I tried ReadBytsUntil, it also crashed.
So I now tried to write it with just read() and my own filter and timeout function.
Also tried with a shorter timeout, using micros() and a value of 500.
After running for a couple of minutes, mostly less then an hour, it crashes with a WDT reset.
Also please run CheckFlashConfig example and verify that your flash chip is indeed 1Mb.
Looks like you need to erase flash completely and then try CheckFlashConfig with 512K option selected.
To erase the flash, you can use esptool (the same one which is used by Arduino to upload the sketch).
Run it like this: esptool -cp <port name> -cd ck -ce . Make sure the ESP is in bootloader mode before running this command (if you are triggering it manually).
A little question, does the NodeMCU do a software reset at each void loop() iteration? I had an infinitely running recursive method which I suspect to have causing the error. I fixed it. But I still have a problem because I am using Adafruit IO and so the data on a certain feed is read again at every loop() iteration although no new data is added to the feed.
0x4010023c: millis() at C:\Users\User\Documents\Arduino\hardware\esp8266com\esp8266\cores\esp8266\ core_esp8266_wiring.cpp line 188
0x401006d9: _umm_free(void)* at C:\Users\User\Documents\Arduino\hardware\esp8266com\esp8266\cores\esp8266\umm_malloc\ umm_malloc.cpp line 1380
0x40202bc8: Adafruit_MQTT::processPackets(short) at C:\Users\User\Documents\Arduino\libraries\Adafruit_MQTT_Library-master\ Adafruit_MQTT.cpp line 418
0x402097d8: Adafruit_MQTT_Client::connected() at C:\Users\User\Documents\Arduino\libraries\Adafruit_MQTT_Library-master\ Adafruit_MQTT_Client.cpp line 48
0x40201f84: AdafruitIO::run(unsigned short) at C:\Users\User\Documents\Arduino\libraries\Adafruit_IO_Arduino-master\src\ AdafruitIO.cpp line 179 0x402017df: loop() at C:\Users\User\Documents\Arduino\Project_NodeMCU/ Project_NodeMCU.ino line 142
0x4010015c: ets_post(uint8, ETSSignal, ETSParam) at C:\Users\User\Documents\Arduino\hardware\esp8266com\esp8266\cores\esp8266\ core_esp8266_main.cpp line 156
0x40207c6d: esp_schedule() at C:\Users\User\Documents\Arduino\hardware\esp8266com\esp8266\cores\esp8266\ core_esp8266_main.cpp line 109
0x40207d90: loop_wrapper() at C:\Users\User\Documents\Arduino\hardware\esp8266com\esp8266\cores\esp8266\ core_esp8266_main.cpp line 176
My understanding is that the NodeMCU code core requires CPU time to process the wi-fi operations (whether you’re using them or not). So you can’t run a while(1) because it doesn’t allow the wi-fi core to run, and the watchdog will reset the CPU.
You should include somewhere in any infinite loop (including the main loop) a delay(nnn); line or a yield(); line, either of which allows the background tasks to run periodically (when those commands are called).
Daniel