Trying to compile this code which I have not modified/worked on for quite some time. I don't understand the SPIFFS error since I am using LittleFS commands. The deprecated warning never occurred before or at least it never prevented a successful comple. Is this because I am using the latest IDE 2.3.3 that has a new requirement/standard? Hopefuly there is a workaround for this that won't require code mods related to storing file information.
As a sidenote this ESP8266 has started freezing up after working fine for months on end. I thought about trying to do a forced reset periodically just to give it a fresh start every week or two, based on millis or date/time.
```cpp
#include <ESP8266WiFi.h>
#include <LittleFS.h>
#include <time.h>
#include <tz.h>
#include <Arduino.h>
#ifdef ESP32
#include <WiFi.h>
#include <AsyncTCP.h>
#elif defined(ESP8266)
#include <ESPAsyncTCP.h>
#endif
#include <ESPAsyncWebSrv.h>
AsyncWebServer server(80);
const char *ssid = "Homestead-LAN_EXT";
const char *password = "********";
const char *PARAM_MESSAGE = "message";
int Initial_Connect_Attempts = 0;
int Try_Count = 0;
void notFound(AsyncWebServerRequest *request) {
request->send(404, "text/plain", "Nope....notta....Not found");
}
int RunLEDState = LOW;
int OutageLEDState = LOW;
unsigned long currentMillis;
unsigned long previous_Blink_Millis = 0;
const long blink_interval = 2000;
unsigned long previous_TimeStamp_Millis = 0;
unsigned long previous_LED_Millis = 0;
const long TimeStamp_interval = 86400000; // milliseconds [1 per day]
const long LED_interval = 200; // Power Outage LED pulsate time period
const int Min_Voltage = 400; // Input range 0 - 1023; 0 = 0 vdc, 1023 = 3 vdc
const int Restore_Voltage = 830;
bool update_clock = false;
bool Pwr_Restore_timestamp = false;
bool Pwr_Out_timestamp = false;
bool Outage_Detected = false;
bool End_Of_Outage = false;
bool Reset_Pressed = false;
const int Outage_LED = D7; // GPIO13 = Bd. Label D7
const int LED_Reset_Button = D8; // GPI15 = Bd. Label D8
int testOR0 = 0; // change to 1000 for testing
const int Vdc_Input = A0; // ADCO = Bd. Label A0
int Voltage_Value = 800; // DC input from power module using voltage divider
void update_time();
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
/* if (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.printf("WiFi Failed!\n");
return;
}
*/
Serial.println("\nConnecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(1000);
}
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
request->send(200, "text/plain", "Enter /power for Outage file.");
});
server.on("/power", HTTP_GET, [](AsyncWebServerRequest *request) {
request->send(LittleFS, "PowerOutageFile.txt", "text/plain");
});
// Send a GET request to <IP>/get?message=<message>
server.on("/get", HTTP_GET, [](AsyncWebServerRequest *request) {
String message;
if (request->hasParam(PARAM_MESSAGE)) {
message = request->getParam(PARAM_MESSAGE)->value();
} else {
message = "What's up?";
}
request->send(200, "text/plain", "Hello, GET: " + message);
});
server.onNotFound(notFound);
server.begin();
// *********************************************************************
Serial.setDebugOutput(true);
configTime(TZ_America_Chicago, "pool.ntp.org", "time.nist.gov");
Serial.println("\nWaiting for time");
while (!time(nullptr)) {
Serial.print(".");
delay(1000);
}
if (!LittleFS.begin()) {
Serial.println();
Serial.println("Crap. An Error has occurred while mounting SPIFFS");
return;
}
pinMode(LED_BUILTIN, OUTPUT); // Processor run indicator
pinMode(Outage_LED, OUTPUT); // RED LED on shield
pinMode(LED_Reset_Button, INPUT); // Pushbutton on 8266 Shield
}
void loop() {
time_t now = time(nullptr);
Serial.println(ctime(&now));
delay(testOR0); // change to 1000 to slow serial output for testing
currentMillis = millis();
if (currentMillis - previous_Blink_Millis >= blink_interval) {
previous_Blink_Millis = currentMillis;
if (RunLEDState == LOW) {
RunLEDState = HIGH;
} else (RunLEDState = LOW);
digitalWrite(LED_BUILTIN, RunLEDState);
}
if (currentMillis - previous_TimeStamp_Millis >= TimeStamp_interval) {
previous_TimeStamp_Millis = currentMillis;
update_clock = true;
}
Voltage_Value = analogRead(Vdc_Input);
Serial.println("Voltage Input: ");
Serial.print(Voltage_Value);
Serial.println();
if (update_clock == true && Voltage_Value >= Restore_Voltage) { // prevent timestamp update attempt
update_time(); // during power outage
update_clock = false;
}
if (Voltage_Value <= Min_Voltage && Outage_Detected == false && Pwr_Out_timestamp == false) {
Serial.print("Outage detected! "); // Low/No voltage detected.
Serial.print("Outage Date/Time: ");
Serial.println(ctime(&now));
Serial.println();
Pwr_Out_timestamp = true;
Outage_Detected = true;
File fileToAppend = LittleFS.open("/PowerOutageFile.txt", "a");
if (!fileToAppend) {
Serial.println("Crap. There was an error opening the file for appending outage detected.");
return;
}
if (fileToAppend.print("Outage Start: "))
; // timestamp outage start time
if (fileToAppend.println(ctime(&now))) {
Serial.println("Yay! Timestamp was added.");
} else {
Serial.println("Crap. File append failed");
}
fileToAppend.close();
}
if (Voltage_Value >= Restore_Voltage && Outage_Detected == true && Pwr_Restore_timestamp == false) // Outage ends : power returns
{
Pwr_Restore_timestamp = true;
File fileToAppend = LittleFS.open("/PowerOutageFile.txt", "a"); // timestamp end of outage to file
if (!fileToAppend) {
Serial.println("Crap. There was an error opening the file for appending power restoration");
return;
}
if (fileToAppend.print("Power Restored: "))
; // timestamp outage restoration time
if (fileToAppend.println(ctime(&now))) {
Serial.println("Yay! Power restored timestamp was appended to file!");
} else {
Serial.println("Crap. File append failed");
}
fileToAppend.close();
End_Of_Outage = true;
Serial.print("End Of Outage = ");
Serial.println(End_Of_Outage);
Serial.println();
}
if (digitalRead(LED_Reset_Button) == HIGH) // reset button pressed to acknowledge outage
{ // and reset boolean flags
End_Of_Outage = false;
Outage_Detected = false;
Pwr_Restore_timestamp = false;
Pwr_Out_timestamp = false;
digitalWrite(Outage_LED, LOW); // Turn off Red LED
Serial.print("End Of Outage = ");
Serial.println(End_Of_Outage);
Serial.println();
Serial.print("Outage Detected = ");
Serial.println(Outage_Detected);
Serial.println();
}
if (Pwr_Restore_timestamp == true) // Pulsate Power Outage LED AFTER power returns
{
if (currentMillis - previous_LED_Millis >= LED_interval) {
previous_LED_Millis = currentMillis;
if (OutageLEDState == LOW) {
OutageLEDState = HIGH;
} else {
OutageLEDState = LOW;
}
digitalWrite(Outage_LED, OutageLEDState);
}
}
}
void update_time() {
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Initial_Connect_Attempts++;
Serial.println("Attempting to Connect To Local Network: ");
Serial.println(ssid);
WiFi.begin(ssid, password);
delay(4000);
if (Initial_Connect_Attempts == 5) return ; // give up after 5 trys and wait for next cycle
Serial.print(".");
}
configTime(TZ_America_Chicago, "pool.ntp.org", "time.nist.gov");
Serial.println("\nWaiting for time");
while (!time(nullptr)) {
Serial.print(".");
delay(1000);
}
}
In file included from c:\Users\Ed\IDE 2.0 Sketches-Libraries\libraries\ESPAsyncWebSrv\src\WebAuthentication.cpp:21:
c:\Users\Ed\IDE 2.0 Sketches-Libraries\libraries\ESPAsyncWebSrv\src\WebAuthentication.h:27:51: error: missing binary operator before token "("
27 | #if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 0)
| ^
In file included from c:\Users\Ed\IDE 2.0 Sketches-Libraries\libraries\ESPAsyncWebSrv\src\WebRequest.cpp:23:
c:\Users\Ed\IDE 2.0 Sketches-Libraries\libraries\ESPAsyncWebSrv\src\WebAuthentication.h:27:51: error: missing binary operator before token "("
27 | #if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 0)
| ^
In file included from c:\Users\Ed\IDE 2.0 Sketches-Libraries\libraries\ESPAsyncWebSrv\src\SPIFFSEditor.cpp:1:
c:\Users\Ed\IDE 2.0 Sketches-Libraries\libraries\ESPAsyncWebSrv\src\SPIFFSEditor.h:16:101: warning: 'SPIFFS' is deprecated: SPIFFS has been deprecated. Please consider moving to LittleFS or other filesystems. [-Wdeprecated-declarations]
16 | SPIFFSEditor(const String& username=String(), const String& password=String(), const fs::FS& fs=SPIFFS);
| ^~~~~~
In file included from c:\Users\Ed\IDE 2.0 Sketches-Libraries\libraries\ESPAsyncWebSrv\src/ESPAsyncWebSrv.h:27,
from c:\Users\Ed\IDE 2.0 Sketches-Libraries\libraries\ESPAsyncWebSrv\src\SPIFFSEditor.h:3,
from c:\Users\Ed\IDE 2.0 Sketches-Libraries\libraries\ESPAsyncWebSrv\src\SPIFFSEditor.cpp:1:
C:\Users\Ed\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2\cores\esp8266/FS.h:286:15: note: declared here
286 | extern fs::FS SPIFFS attribute((deprecated("SPIFFS has been deprecated. Please consider moving to LittleFS or other filesystems.")));
| ^~~~~~
exit status 1
Compilation error: exit status 1