ESP32 Guru meditiation error

I have an ESP32Devkit C monitoring the output of my solar panels by counting pulses from the LED on the meter. It displays values to a web page and records daily totals data to a spiffs file.
Its working fine but following a power fail I discovered the day data is lost.
I'm trying to add code to save 6 min data to a second spiffs file so its preserved, thenI can read it back at the end of the day to give my daily total.
However I keep getting a guru error and reset; and I dont know how to interpret the output.
The error doesnt seem to occur in a consiten place in the program.

What I have tried:
disable the wifievents handling
disable the interrupt handler and poll input instead.
disable the sections that create, write and recover data from the "day data" spiffs file.

I've put the main code here and attached the rest.
The "SolarLoggerAnon.h" is just SolarLogger.h with the pwd & ssid changed.
webpage.ino (1.0 KB)
wifi.ino (1.1 KB)
datavalues.ino (4.7 KB)
SolarLoggerAnon.h (7.9 KB)
spiffs.ino (2.2 KB)

/*
  Running on ESP32
*/

#include <WiFi.h>
#include "time.h"
#include "SPIFFS.h"
#include <ESP8266FtpServer.h>
#include <AsyncTCP.h> //the library for the 8266 is different
#include <ESPAsyncWebServer.h>

#include "SolarLogger.h" //my definitions, function prototypes etc

void setup() {
  Serial.begin(115200);
  pinMode(LED_WiFi, OUTPUT);
  pinMode(LED_Pulse, OUTPUT);
  pinMode(intPin, INPUT_PULLUP);
  digitalWrite(LED_WiFi,0); //ensure blue LED off

  // delete old wifi config
  WiFi.disconnect(true);
  delay(200);
  //separate heading from reset diagnostic messages
  Serial.println("");
  Serial.println("Starting Solar Logger");

  //monitor Wifi connection and handle LED - nb these dont work as is on 8266
  WiFi.onEvent(WiFiStationConnected, SYSTEM_EVENT_STA_CONNECTED);
  WiFi.onEvent(WiFiGotIP, SYSTEM_EVENT_STA_GOT_IP);
  WiFi.onEvent(WiFiStationDisconnected, SYSTEM_EVENT_STA_DISCONNECTED);

  //  connectWiFi();
  WiFi.begin(ssid, password);
  delay(200);
  configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);   // Init and get the time

  //  FTP Setup, ensure SPIFFS is started before ftp;
  if (SPIFFS.begin(true)) {
    Serial.println("SPIFFS opened!");
    ftpSrv.begin("esp8266", "esp8266");  //ftp username, password. set ports in ESP8266FtpServer.h (default 21, 50009 for PASV)
  }
  delay(100); //allow to get NTP time
  while (!getLocalTime(&timeinfo)) { delay(100);  }
  currMonth = 1 + timeinfo.tm_mon; //tm_mon gives months since jan so eg April is 03 hence add 1
  currDay = timeinfo.tm_mday; //set current day
  Serial.printf("Setup: -  success getting time. currMonth is %i: currDay is %i \n",currMonth,currDay);
  currDay = 0; //testing - force new day scenario
  //currMonth = 0; //testing - force new month scenario
  newMonth();  //if no file exists as yet create one; but if there is one dont overwrite it.

  // Handle Web Server
  server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
    request->send_P(200, "text/html", index_html, processor);
  });

  // Handle Web Server Events
  events.onConnect([](AsyncEventSourceClient * client) {
    if (client->lastId()) {
      Serial.printf("Client reconnected! Last message ID that it got is: %u\n", client->lastId());
    }
    // send event with message "hello!", id, current millis and set reconnect delay to 1 second
    client->send("hello!", NULL, millis(), 1000);
  });
  server.addHandler(&events);
  server.begin(); //start web server
  zeroStats();
  configInterrupt();
  Serial.println("Setup complete \n");
}   //*** end of Setup ***

void loop() {
  ftpSrv.handleFTP();        //make sure in loop you call handleFTP()!!
  //pollInput();
  pulseState = digitalRead(intPin); //reflect input pulse to LED
  digitalWrite(LED_Pulse, (pulseState + 1) % 2); //because input active low
  /*  *** members of timeinfo structure access as eg timeinfo.tm_yday for day number of year
    int tm_sec  seconds [0,61]; int tm_min  minutes [0,59]; int tm_hour  hour [0,23]; 
    int tm_mday  day of month [1,31]; int tm_mon  month of year [0,11]; int tm_year years since 1900; 
    int tm_wday  day of week [0,6] (Sunday = 0) int tm_yday days since Jan 1 [0,365]; int tm_isdst daylight savings flag
  */
  if (!getLocalTime(&timeinfo)) { 
    Serial.println("Failed to obtain time");
    return;
  }

  checkPeriod(); //if 6 min record current, previous, max values of watts

  if (timeinfo.tm_mday != currDay) {
    //start of new day
    newDay(); //save day data to file
    currDay = timeinfo.tm_mday; //update current day
  }

  if (timeinfo.tm_mon != currMonth) {
    //start of new month
    newMonth();
  }

  buildDate(); //only needed for web page date & time display

  if ((millis() - lastTime) > timerDelay) {
    // Send Events to the Web Server with the current values
    events.send("ping", NULL, millis());
    events.send(String(myDate).c_str(), "time", millis());
    events.send(String(dTotalkWh).c_str(), "dtotal", millis());
    events.send(String(yTotalkWh).c_str(), "ytotal", millis());
    events.send(String(pWatts).c_str(), "pwatts", millis());
    events.send(String(mWatts).c_str(), "mwatts", millis());
    events.send(String(cWatts).c_str(), "cwatts", millis());

    lastTime = millis();
  }

} //end of loop

Have you tried using the ESP32 Exception decoder and putting the debug print into the Exception Decoder to see what the exception means?

Me, I've never got the #include <ESPAsyncWebServer.h> to work correctly.

I have it running flawlessly on two devices -
1: a simple BME "weather station" reporting temp, humidity and current / 3h / 24h change, and
2: the earlier "solar monitor".

Thanks for the advice re the exception decoder, I've installed it and its working fine, with these (consistent) results - that seem to indicate an issue with the Asynch event handler.

So why should it fail when the changes I have made are to the SPIFFs setup?

checkPeriod: at time 14:00:00
cWatts: 400; mWatts: 400 
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC      : 0x400d7fc6  PS      : 0x00060230  A0      : 0x800d8066  A1      : 0x3ffb1ef0  
A2      : 0x3ffbbe7c  A3      : 0x000e0b01  A4      : 0x00008100  A5      : 0x3ffd2e4c  
A6      : 0x3036203a  A7      : 0x0a0d0a0d  A8      : 0x00008100  A9      : 0x3ffb1ed0  
A10     : 0x30333033  A11     : 0x3ffd2ff0  A12     : 0x00000028  A13     : 0x00000028  
A14     : 0x00000000  A15     : 0x000a0d0a  SAR     : 0x0000000a  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x000e0b01  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0xffffffff  

ELF file SHA256: 0000000000000000

Backtrace: 0x400d7fc6:0x3ffb1ef0 0x400d8063:0x3ffb1f10 0x400d8083:0x3ffb1f30 0x400d80d9:0x3ffb1f50 0x400d1921:0x3ffb1f80 0x400df275:0x3ffb1fb0 0x40089a8e:0x3ffb1fd0

Decoding 7 results
0x400d7fc6: AsyncEventSourceClient::_runQueue() at c:\arduinoideportable\portable\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-97-gc752ad5-5.2.0\xtensa-esp32-elf\include\c++\5.2.0/functional line 1858
0x400d8063: AsyncEventSourceClient::_queueMessage(AsyncEventSourceMessage*) at c:\arduinoideportable\portable\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-97-gc752ad5-5.2.0\xtensa-esp32-elf\include\c++\5.2.0/functional line 1858
0x400d8083: AsyncEventSourceClient::write(char const*, unsigned int) at c:\arduinoideportable\portable\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-97-gc752ad5-5.2.0\xtensa-esp32-elf\include\c++\5.2.0/functional line 1858
0x400d80d9: AsyncEventSource::send(char const*, char const*, unsigned int, unsigned int) at c:\arduinoideportable\portable\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-97-gc752ad5-5.2.0\xtensa-esp32-elf\include\c++\5.2.0/functional line 1858
0x400d1921: loop() at C:\ArduinoIDEPortable\portable\sketchbook\ESP32\SolarLoggerFinal3/wifi.ino line 12
0x400df275: loopTask(void*) at C:\ArduinoIDEPortable\portable\packages\esp32\hardware\esp32\1.0.6\cores\esp32/main.cpp line 23
0x40089a8e: vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c line 355 (discriminator 1)

********************************

checkPeriod: at time 14:36:00
cWatts: 0; mWatts: 30 
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC      : 0x400d7fc8  PS      : 0x00060230  A0      : 0x800d8066  A1      : 0x3ffb1ef0  
A2      : 0x3ffbbe7c  A3      : 0x3ffd2970  A4      : 0x00000028  A5      : 0x3ffd31bc  
A6      : 0x3033203a  A7      : 0x0a0d0a0d  A8      : 0x800d7fd4  A9      : 0x3ffb1ed0  
A10     : 0xe008a082  A11     : 0x00000028  A12     : 0x00000028  A13     : 0x00000028  
A14     : 0x00000000  A15     : 0x000a0d0a  SAR     : 0x0000000a  EXCCAUSE: 0x0000001c  
EXCVADDR: 0xe008a08a  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0xffffffff  

ELF file SHA256: 0000000000000000

Backtrace: 0x400d7fc8:0x3ffb1ef0 0x400d8063:0x3ffb1f10 0x400d8083:0x3ffb1f30 0x400d80d9:0x3ffb1f50 0x400d18ea:0x3ffb1f80 0x400df275:0x3ffb1fb0 0x40089a8e:0x3ffb1fd0
Decoding 7 results
0x400d7fc8: AsyncEventSourceClient::_runQueue() at c:\arduinoideportable\portable\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-97-gc752ad5-5.2.0\xtensa-esp32-elf\include\c++\5.2.0/functional line 1858
0x400d8063: AsyncEventSourceClient::_queueMessage(AsyncEventSourceMessage*) at c:\arduinoideportable\portable\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-97-gc752ad5-5.2.0\xtensa-esp32-elf\include\c++\5.2.0/functional line 1858
0x400d8083: AsyncEventSourceClient::write(char const*, unsigned int) at c:\arduinoideportable\portable\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-97-gc752ad5-5.2.0\xtensa-esp32-elf\include\c++\5.2.0/functional line 1858
0x400d80d9: AsyncEventSource::send(char const*, char const*, unsigned int, unsigned int) at c:\arduinoideportable\portable\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-97-gc752ad5-5.2.0\xtensa-esp32-elf\include\c++\5.2.0/functional line 1858
0x400d18ea: loop() at C:\ArduinoIDEPortable\portable\sketchbook\ESP32\SolarLoggerFinal3/wifi.ino line 12
0x400df275: loopTask(void*) at C:\ArduinoIDEPortable\portable\packages\esp32\hardware\esp32\1.0.6\cores\esp32/main.cpp line 23
0x40089a8e: vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c line 355 (discriminator 1)

So start over with a fresh working thingy, then add a small change at a time, till the issue comes back. Adding and removing the additional pieces till you come to the line or section that is the error thingy.

It does look like a task is exceeding its allocated task space. Like an array going beyond its boundaries though with

Typically, EXCAVADOR will be 0 when an array goes beyond its boundaries.

Trying it; its a slow process as the "events" only happen at multiples of 6 min intervals; however theres no rush.

Where would we be without metasyntactic variables?

Yes, a slow and tedious process that I've had to do many times. Typically such issues are with the Adafruit library. After sending Adafruit my core dump and coded debug data they fix the issue in less than 3 weeks.

Variables that don't matter.

It seems I'm not alone with this problem IdahoWalker;

I've conceded defeat; I cant reconfigure the hardware to use a NODE and while the Asysnch server seems to work OK on apps that arent time-critical (like this)

its not happy in my situation with SPIFFS, FTP, interrupts etc all going on at the same time. The issue seems to only happen when a client connects or refreshes the web page.

Follow up: after spending a LOT of time on this - the error sometimes doesnt crop up for days, but thats still no use as when it resets all the data is lost. So testing is a slow process.

However I have found that the ESP32 & program is unstable when running on a PC running the arduino IDE; but much more stable when running on an old laptop reading the serial output with PUTTY under linux.

Why - I have no idea.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.