I'm having trouble figuring out why my sketch keeps on crashing at random intervals
I already did a CrashDecode but unfortunately that isn't tooooo much help on my skill level.
basically I'm getting this exception:
Exception (0):
epc1=0x4000e25d epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
>>>stack>>>
ctx: cont
sp: 3ffefac0 end: 3ffefe50 offset: 0190
3ffefc50: ffffffff 3ffeecbc 3ffeecb8 40100ece
3ffefc60: 3ffe9934 7fffffff 00000000 00000020
3ffefc70: ffffffff 0000000f 00000000 40100404
3ffefc80: c003b025 00000000 0000001f 40100168
3ffefc90: 00000005 00000000 00000020 00000022
3ffefca0: 3fffc200 40100340 3fffc258 4000050c
3ffefcb0: 4000067d 00000030 00000010 ffffffff
3ffefcc0: 00000000 f3b9abe0 38d79cc3 00000000
3ffefcd0: 00004bc6 f3b9abe0 00000000 fffffffe
3ffefce0: 0000be93 3fffc6fc 8f2dabe0 4bc6a7f0
3ffefcf0: 00000000 c008da42 00000000 00000030
3ffefd00: 402011c8 14c975f8 60000304 00000005
3ffefd10: 00004bc6 00000000 00000000 fffffffe
3ffefd20: 00000000 3fffc6fc 00000000 3ffee990
3ffefd30: 00000000 3fffdad0 3ffee9d0 00000030
3ffefd40: 40102838 3fffc200 00000022 00000000
3ffefd50: 4023447a 00000030 0000001b ffffffff
3ffefd60: 40201050 3ffeee30 402011d8 00000000
3ffefd70: 00000000 00000000 00000000 fffffffe
3ffefd80: ffffffff 3fffc6fc 00000001 3ffe85bc
3ffefd90: 00000000 3fffdad0 3ffee9d0 00000030
3ffefda0: c008da42 4bc6a7f0 c008da42 00000000
3ffefdb0: c008da42 00000000 4bc6a7f0 00000000
3ffefdc0: 00000000 00000001 401001e4 4bc6a7f0
3ffefdd0: 00000000 00000000 3ffeebc4 40206a05
3ffefde0: 38d79cc2 00000000 00001388 411f1e8d
3ffefdf0: 00000000 00000000 00000000 3ffe84f0
3ffefe00: 3fffdad0 00000000 3ffe84f0 40206b5a
3ffefe10: 00000000 00000000 00000001 40100168
3ffefe20: 3fffdad0 00000000 3ffee990 3ffee9d0
3ffefe30: 3fffdad0 00000000 3ffee990 402011f8
3ffefe40: feefeffe feefeffe 3ffe85bc 40100515
<<<stack<<<
which according to the Decoder translates to this:
Exception 0: Illegal instruction
PC: 0x4000e25d
EXCVADDR: 0x00000000
Decoding stack results
0x40100ece: onPowerPulse() at master.ino line 222
0x40100404: interrupt_handler(void*) at ../esp8266/cores/esp8266/interrupts.h line 29
0x40100340: interrupt_handler(void*) at ../esp8266/cores/esp8266/core_esp8266_wiring_digital.cpp line 135
0x40210369: WiFiClient::operator bool() at ../esp8266/libraries/ESP8266WiFi/src/WiFiClient.cpp line 349
0x4020a8d8: WiFiClient::connected() at ../esp8266/libraries/ESP8266WiFi/src/WiFiClient.cpp line 333
0x401001e4: millis() at ../esp8266/cores/esp8266/core_esp8266_wiring.cpp line 185
0x40206a05: esp8266webserver::ESP8266WebServerTemplate ::handleClient() at ../esp8266/libraries/ESP8266WebServer/src/ESP8266WebServer-impl.h line 307
0x40206b5a: loop() at master.ino line 422
0x40100168: ets_post(uint8, ETSSignal, ETSParam) at ../esp8266/cores/esp8266/core_esp8266_main.cpp line 177
0x402011f8: loop_wrapper() at ../esp8266/cores/esp8266/core_esp8266_main.cpp line 197
can somebody help me shed some light what I'm even supposed to look at here?
below the sections which i *think* are the problematic ones
the sketch should be fairly easy, I'm trying to read 2 DHT humidity sensors and also keep track of an S0 enegry meter by interrupt.
most of the lines/files in the Decoder output were not written by me / are part of the esp compiler package, the 2 snippets that I think are relevant are
the s0 interrupt function looks like this: (which is the first line in the decoders output on line 222
void ICACHE_RAM_ATTR onPowerPulse() {
//used to measure time between pulses.
lastTime = pulseTime;
pulseTime = millis();
//pulseCounter
pulseCount++;
//Calculate power
double powertmp = (60*60*1000 / (pulseTime - lastTime))/ppwh;
Serial.print("S0 interrupt, Powervalue: ");
Serial.print(powertmp);
Serial.println(" Wh");
//check if value is reasonable, i.e. avoid reboot nirvana values
if ( powertmp > 3000 || powertmp < 2 ) {
return;
}
power = powertmp;
//Find kwh elapsed
elapsedkWh = (1.0 * pulseCount/(ppwh * 1000)); //multiply by 1000 to convert pulses per wh to kwh
}
and here is the full loop code: line 422 is marked where the second DHT block starts
void loop(void){
httpServer.handleClient();
if( millis() >= rebootInterval ) {
ESP.restart();
}
// read front DHT
if ( millis() > front.timer ) {
//Serial.print("DHT front ... ");
//// Read sensor
float tmpTemp = dhtfront.readTemperature();
float tmpHumidity = dhtfront.readHumidity();
// Check if any reads failed and exit early (to try again).
if (isnan(tmpHumidity) or isnan(tmpTemp)) {
//Serial.println("Failed to read front sensor!");
front.timer = millis() + dhtDelayFail; // if sensor reading failed try again after FAILFREQUENCY
} else {
//Serial.println("OK");
front.temp = tmpTemp;
front.humidity = tmpHumidity;
front.timer = millis() + dhtDelayRead;
// Compute heat index and dewpoint
front.dew = dewPoint(front.temp, front.humidity);
front.hi = dhtfront.computeHeatIndex(front.temp, front.humidity, false);
printDhtSerial(front); //// printing it all on the Serial if we actually got values
}
}
// read door DHT
if ( millis() > door.timer ) { // <<<< line 422 in sketch that is being complained about in the decode
//Serial.print("DHT door ... ");
//// Read sensor
float tmpTemp = dhtdoor.readTemperature();
float tmpHumidity = dhtdoor.readHumidity();
// Check if any reads failed and exit early (to try again).
if (isnan(tmpHumidity) or isnan(tmpTemp)) {
//Serial.println("Failed to read door sensor!");
door.timer = millis() + dhtDelayFail; // if sensor reading failed try again after FAILFREQUENCY
} else {
//Serial.println("OK");
door.temp = tmpTemp;
door.humidity = tmpHumidity;
door.timer = millis() + dhtDelayRead;
// Compute heat index and dewpoint
door.dew = dewPoint(door.temp, door.humidity);
door.hi = dhtdoor.computeHeatIndex(door.temp, door.humidity, false);
printDhtSerial(door); //// printing it all on the Serial if we actually got values
}
}
if ((relay1.offDelay > 0) && ((millis() - relay1.lastSwitch) > relay1.offDelay)) {
relay1.status = OFF;
digitalWrite(relay1.pin, relay1.status);
}
}
but I don't even know where to start why these 2 would cause a crash
thanks a lot in advance.
the sketch is a bit longer but it seems to always crash with the same stack trace pointing to the same 2 problematic lines
happy to share the whole sketch though if that is helpful.