Make use of SimpleFS to init filesystem.

This commit is contained in:
Dirk Jahnke 2019-06-07 09:43:09 +02:00
parent f4fbd95183
commit d0b0041a40
2 changed files with 11 additions and 25 deletions

View File

@ -5,7 +5,7 @@
// //
// //
#include <DjSimpleFS.h> #include "DjSimpleFS.h"
boolean SimpleFS::_initialized = false; boolean SimpleFS::_initialized = false;
FSInfo SimpleFS::fsInfo; FSInfo SimpleFS::fsInfo;
@ -76,4 +76,3 @@ size_t SimpleFS::getMaxPathLength() {
} }
return fsInfo.maxPathLength; return fsInfo.maxPathLength;
} }

View File

@ -3,12 +3,8 @@
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include <NTPClient.h> //https://github.com/esp8266/Arduino #include <NTPClient.h> //https://github.com/esp8266/Arduino
#include <WiFiUdp.h> #include <WiFiUdp.h>
//needed for library
#include <DNSServer.h> #include <DNSServer.h>
//#include <ESP8266WebServer.h>
#include <WiFiManager.h> #include <WiFiManager.h>
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include <SPI.h> #include <SPI.h>
#include "DjDebug.h" #include "DjDebug.h"
@ -17,6 +13,7 @@
#include "DjDebug.h" #include "DjDebug.h"
#include "ClockClient.h" #include "ClockClient.h"
#include "WebUI.h" #include "WebUI.h"
#include "DjSimpleFS.h"
// NTP // NTP
WiFiUDP ntpUDP; WiFiUDP ntpUDP;
@ -25,7 +22,6 @@ WiFiUDP ntpUDP;
// update interval (in milliseconds, can be changed using setUpdateInterval() ). // update interval (in milliseconds, can be changed using setUpdateInterval() ).
NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 7200, 60000); NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 7200, 60000);
static const char *appName = "FastclockClient7Seg"; static const char *appName = "FastclockClient7Seg";
const char * const PROGMEM mainConfig[] = { const char * const PROGMEM mainConfig[] = {
"appMode:string:" MODE_DEMO, "appMode:string:" MODE_DEMO,
@ -42,6 +38,7 @@ SevenSegmentClock sevenSegmentClock(debug, config);
ClockClient fastclockClient(debug, config); ClockClient fastclockClient(debug, config);
//ESP8266WebServer *server; //ESP8266WebServer *server;
WebUI *webUI; WebUI *webUI;
SimpleFS filesystem(debug);
//flag for saving data //flag for saving data
bool shouldSaveConfig = false; bool shouldSaveConfig = false;
@ -94,22 +91,12 @@ void setup() {
debug.out(F("Reset reason: "), DEBUG_MIN_INFO); debug.out(F("Reset reason: "), DEBUG_MIN_INFO);
debug.outln(ESP.getResetReason(), DEBUG_MIN_INFO); debug.outln(ESP.getResetReason(), DEBUG_MIN_INFO);
//clean FS, for testing filesystem.begin();
//SPIFFS.format(); config.begin("main.cfg", mainConfig, sizeof(mainConfig)/sizeof(mainConfig[0]));
//read configuration from FS json
debug.outln(F("mounting FS..."), DEBUG_MAX_INFO);
if (SPIFFS.begin()) {
debug.outln(F("mounted file system"), DEBUG_MAX_INFO);
config.begin("main.cfg", mainConfig, sizeof(mainConfig)/sizeof(mainConfig[0]));
} else {
debug.outln(F("failed to mount FS"), DEBUG_ERROR);
config.begin("main.cfg", mainConfig, sizeof(mainConfig)/sizeof(mainConfig[0]));
}
setupWifiConnection(); setupWifiConnection();
debug.outln(F("Starting NTP Client"), DEBUG_MAX_INFO); debug.outln(F("Starting NTP Client"), DEBUG_MAX_INFO);
timeClient.begin(); timeClient.begin();
timeClient.setTimeOffset(config.getInt("utcTimeOffsetMinutes") * 60);
debug.outln(F("Have following configuration:"), DEBUG_MAX_INFO); debug.outln(F("Have following configuration:"), DEBUG_MAX_INFO);
debug.out(F(" App Mode: "), DEBUG_MAX_INFO); debug.outln(config.getString("appMode"), DEBUG_MAX_INFO); debug.out(F(" App Mode: "), DEBUG_MAX_INFO); debug.outln(config.getString("appMode"), DEBUG_MAX_INFO);
@ -118,7 +105,6 @@ void setup() {
debug.out(F(" Clock listen port: "), DEBUG_MAX_INFO); debug.outln(config.getString("listenPort"), DEBUG_MAX_INFO); debug.out(F(" Clock listen port: "), DEBUG_MAX_INFO); debug.outln(config.getString("listenPort"), DEBUG_MAX_INFO);
debug.out(F(" Real time UTC offset: "), DEBUG_MAX_INFO); debug.outln(config.getString("utcTimeOffsetMinutes"), DEBUG_MAX_INFO); debug.out(F(" Real time UTC offset: "), DEBUG_MAX_INFO); debug.outln(config.getString("utcTimeOffsetMinutes"), DEBUG_MAX_INFO);
timeClient.setTimeOffset(config.getInt("utcTimeOffsetMinutes") * 60);
debug.outln(F("Starting fastclock ..."), DEBUG_MAX_INFO); debug.outln(F("Starting fastclock ..."), DEBUG_MAX_INFO);
fastclock.begin(); fastclock.begin();
@ -127,14 +113,14 @@ void setup() {
sevenSegmentClock.setBrightness(config.getInt("brightness")); sevenSegmentClock.setBrightness(config.getInt("brightness"));
sevenSegmentClock.setColor(sevenSegmentClock.getColorHandleByName(config.getString("clockColor"))); sevenSegmentClock.setColor(sevenSegmentClock.getColorHandleByName(config.getString("clockColor")));
// setting up web server for clock configuration // setting up web server for clock configuration; intentionally very late
//server = new ESP8266WebServer(80); // as we need the web server during boot to be able to connect to/configure WiFi
webUI = new WebUI(debug, config, timeClient, fastclock, sevenSegmentClock); webUI = new WebUI(debug, config, timeClient, fastclock, sevenSegmentClock);
webUI->begin(); webUI->begin();
} }
int hours = 0, minutes = 0; static int hours = 0, minutes = 0;
uint32_t nextUpdate_ms = 0; static uint32_t nextUpdate_ms = 0;
void loop() { void loop() {
timeClient.update(); timeClient.update();
@ -166,4 +152,5 @@ void loop() {
sevenSegmentClock.displayUpdate(); sevenSegmentClock.displayUpdate();
webUI->loop(); webUI->loop();
filesystem.loop();
} }