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