Skip to content

Commit

Permalink
migrate to LittleFS
Browse files Browse the repository at this point in the history
Note: the configuration will be wiped and needs to be reconfigured afterwards!

SPIFFS is replaced in favor of LittleFS being its successor.
  • Loading branch information
universam1 committed Jun 5, 2021
1 parent 34c4e55 commit d1deba4
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 54 deletions.
35 changes: 19 additions & 16 deletions pio/lib/Globals/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
extern Ticker flasher;

// defines go here
#define FIRMWAREVERSION "6.6.0"
#define FIRMWAREVERSION "7.0.0"

#define API_FHEM true
#define API_UBIDOTS true
Expand All @@ -33,7 +33,7 @@ extern Ticker flasher;
#define API_BLYNK true
#define API_BREWBLOX true
#define API_MQTT_HASSIO true
#define API_AWSIOTMQTT true //AWS
#define API_AWSIOTMQTT true //AWS

//#define BLYNK_DEBUG
//#define APP_DEBUG
Expand All @@ -46,23 +46,26 @@ extern Ticker flasher;
#define DEBUG true
#endif

#define CONSOLE(...) \
do \
{ \
Serial.print(__VA_ARGS__); \
} while (0)
#define CONSOLELN(...) \
do \
{ \
Serial.println(__VA_ARGS__); \
} while (0)
#define CONSOLE(...) \
do \
{ \
Serial.print(__VA_ARGS__); \
} while (0)
#define CONSOLELN(...) \
do \
{ \
Serial.println(__VA_ARGS__); \
} while (0)

#define PORTALTIMEOUT 300

#define ADCDIVISOR 191.8
#define ONE_WIRE_BUS D6 // DS18B20 on ESP pin12
#define OW_PINS \
(const uint8_t[]) { D1, D6 }
#define OW_PINS \
(const uint8_t[]) \
{ \
D1, D6 \
}
#define RESOLUTION 12 // 12bit resolution == 750ms update rate
#define OWinterval (760 / (1 << (12 - RESOLUTION)))
#define CFGFILE "/config.json"
Expand Down Expand Up @@ -90,7 +93,7 @@ extern Ticker flasher;
#define DTTHINGSPEAK 11
#define DTBLYNK 12
#define DTBREWBLOX 13
#define DTAWSIOTMQTT 14 //AWS
#define DTAWSIOTMQTT 14 //AWS
#define DTHTTPS 15

// Number of seconds after reset during which a
Expand All @@ -116,7 +119,7 @@ extern float Volt, Temperatur, Tilt, Gravity;
extern MPU6050 accelgyro;
extern bool saveConfig();
extern bool saveConfig(int16_t Offset[6]);
extern bool formatSpiffs();
extern bool formatLittleFS();
extern void flash();

float scaleTemperature(float t);
Expand Down
49 changes: 29 additions & 20 deletions pio/lib/WiFiManagerKT/WiFiManagerKT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,26 @@ WiFiManagerParameter::WiFiManagerParameter(const char *custom)
_customHTML = custom;
}

WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length)
WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue,
int length)
{
init(id, placeholder, defaultValue, length, "", WFM_LABEL_BEFORE);
}

WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom)
WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue,
int length, const char *custom)
{
init(id, placeholder, defaultValue, length, custom, WFM_LABEL_BEFORE);
}

WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom, int labelPlacement)
WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue,
int length, const char *custom, int labelPlacement)
{
init(id, placeholder, defaultValue, length, custom, labelPlacement);
}

void WiFiManagerParameter::init(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom, int labelPlacement)
void WiFiManagerParameter::init(const char *id, const char *placeholder, const char *defaultValue, int length,
const char *custom, int labelPlacement)
{
_id = id;
_placeholder = placeholder;
Expand Down Expand Up @@ -104,7 +108,7 @@ WiFiManager::~WiFiManager()

void WiFiManager::addParameter(WiFiManagerParameter *p)
{
if(_paramsCount + 1 > WIFI_MANAGER_MAX_PARAMS)
if (_paramsCount + 1 > WIFI_MANAGER_MAX_PARAMS)
{
//Max parameters exceeded!
DEBUG_WM("WIFI_MANAGER_MAX_PARAMS exceeded, increase number (in WiFiManager.h) before adding more parameters!");
Expand Down Expand Up @@ -189,7 +193,8 @@ void WiFiManager::setupConfigPortal()
server->on("/mnt", std::bind(&WiFiManager::handleMnt, this));
server->on("/offset", std::bind(&WiFiManager::handleOffset, this));
server->on("/reset", std::bind(&WiFiManager::handleReset, this));
server->on("/update", HTTP_POST, std::bind(&WiFiManager::handleUpdateDone, this), std::bind(&WiFiManager::handleUpdating, this));
server->on("/update", HTTP_POST, std::bind(&WiFiManager::handleUpdateDone, this),
std::bind(&WiFiManager::handleUpdating, this));
server->onNotFound(std::bind(&WiFiManager::handleNotFound, this));
server->begin(); // Web server start
DEBUG_WM(F("HTTP server started"));
Expand Down Expand Up @@ -943,11 +948,13 @@ void WiFiManager::handleInfo()
page += F("<tr><td><a href=\"/i\">/i</a></td>");
page += F("<td>This page.</td></tr>");
page += F("<tr><td><a href=\"/r\">/r</a></td>");
page += F("<td>Delete WiFi configuration and reboot. ESP device will not reconnect to a network until new WiFi configuration data is entered.</td></tr>");
page += F("<td>Delete WiFi configuration and reboot. ESP device will not reconnect to a network until new WiFi "
"configuration data is entered.</td></tr>");
page += F("<tr><td><a href=\"/state\">/state</a></td>");
page += F("<td>Current device state in JSON format. Interface for programmatic WiFi configuration.</td></tr>");
page += F("<tr><td><a href=\"/scan\">/scan</a></td>");
page += F("<td>Run a WiFi scan and return results in JSON format. Interface for programmatic WiFi configuration.</td></tr>");
page += F("<td>Run a WiFi scan and return results in JSON format. Interface for programmatic WiFi "
"configuration.</td></tr>");
page += F("</table>");
page += F("<p/>");
page += FPSTR(HTTP_END);
Expand Down Expand Up @@ -996,7 +1003,8 @@ void WiFiManager::handleiSpindel()
page += F("</dd>");
page += F("<dd>Date: ");
page += __DATE__ " " __TIME__;
page += F("</dd></dl><br>Firmware update:<br><a href=\"https://github.com/universam1\">github.com/universam1</a><hr>");
page +=
F("</dd></dl><br>Firmware update:<br><a href=\"https://github.com/universam1\">github.com/universam1</a><hr>");
page += F("</dl>");
page += FPSTR(HTTP_END);

Expand All @@ -1017,18 +1025,21 @@ void WiFiManager::handleMnt()
page += FPSTR(HTTP_SCRIPT);
page += FPSTR(HTTP_STYLE);
page += FPSTR(HTTP_HEADER_END);
page += F("<h2>Offset Calibration</h2><br>Before proceeding with calibration make sure the iSpindel is leveled flat, exactly at 0&deg; horizontally and vertically, according to this picture:<br>");
page += F("<h2>Offset Calibration</h2><br>Before proceeding with calibration make sure the iSpindel is leveled flat, "
"exactly at 0&deg; horizontally and vertically, according to this picture:<br>");
page += FPSTR(HTTP_ISPINDEL_IMG);
page += F("<br><form action=\"/offset\" method=\"get\"><button class=\"btn\">calibrate</button></form><br/>");
page += F("<hr><h2>Firmware Update</h2><br>Firmware updates:<br><a href=\"https://github.com/universam1\">github.com/universam1</a>");
page += F("<hr><h2>Firmware Update</h2><br>Firmware updates:<br><a "
"href=\"https://github.com/universam1\">github.com/universam1</a>");
page += F("Current Firmware installed:<br><dl>");
page += F("<dd>Version: ");
page += FIRMWAREVERSION;
page += F("</dd>");
page += F("<dd>Date: ");
page += __DATE__ " " __TIME__;
page += F("</dd></dl><br>");
page += F("<form method='POST' action='/update' enctype='multipart/form-data'><input type='file' name='update'><br><input type='submit' class=\"btn\" value='update'></form>");
page += F("<form method='POST' action='/update' enctype='multipart/form-data'><input type='file' "
"name='update'><br><input type='submit' class=\"btn\" value='update'></form>");
page += F("<hr><h2>Factory Reset</h2><br>All settings will be removed");
page += F("<br><form action=\"/reset\" method=\"get\"><button class=\"btn\">factory reset</button></form><br/>");
page += FPSTR(HTTP_END);
Expand Down Expand Up @@ -1166,7 +1177,7 @@ void WiFiManager::handleReset()
delay(1000);
WiFi.disconnect(true); // Wipe out WiFi credentials.
resetSettings();
formatSpiffs();
formatLittleFS();
ESP.reset();
delay(2000);
}
Expand Down Expand Up @@ -1203,8 +1214,9 @@ boolean WiFiManager::captivePortal()
DEBUG_WM(F("Request redirected to captive portal"));
server->sendHeader("Location", ("http://") + String(myHostname), true);
server->setContentLength(0);
server->send(302, "text/plain", ""); // Empty content inhibits Content-length header so we have to close the socket ourselves.
// server->client().stop(); // Stop is needed because we sent no content length
server->send(302, "text/plain",
""); // Empty content inhibits Content-length header so we have to close the socket ourselves.
// server->client().stop(); // Stop is needed because we sent no content length
return true;
}
return false;
Expand Down Expand Up @@ -1262,9 +1274,7 @@ int WiFiManager::scanWifiNetworks(int **indicesptr)
indices[i] = i;
}

std::sort(indices, indices + n, [](const int &a, const int &b) -> bool {
return WiFi.RSSI(a) > WiFi.RSSI(b);
});
std::sort(indices, indices + n, [](const int &a, const int &b) -> bool { return WiFi.RSSI(a) > WiFi.RSSI(b); });
// remove duplicates ( must be RSSI sorted )
if (_removeDuplicateAPs)
{
Expand Down Expand Up @@ -1302,8 +1312,7 @@ int WiFiManager::scanWifiNetworks(int **indicesptr)
}
}

template <typename Generic>
void WiFiManager::DEBUG_WM(Generic text)
template <typename Generic> void WiFiManager::DEBUG_WM(Generic text)
{
if (_debug)
{
Expand Down
36 changes: 18 additions & 18 deletions pio/src/iSpindel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ All rights reserverd by S.Lang <[email protected]>
#include "DallasTemperature.h"
#include "DoubleResetDetector.h" // https://github.com/datacute/DoubleResetDetector
#include "RunningMedian.h"
#include "Sender.h"
#include "WiFiManagerKT.h"
#include "secrets.h" //AWS - Currently a file for Keys, Certs, etc - Need to make this a captured variable for iSpindle
#include "tinyexpr.h"
Expand All @@ -24,8 +25,7 @@ All rights reserverd by S.Lang <[email protected]>
#include <ESP8266WebServer.h>
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
#include <FS.h> //this needs to be first

#include "Sender.h"
#include <LittleFS.h>
// !DEBUG 1

// definitions go here
Expand Down Expand Up @@ -152,15 +152,15 @@ bool readConfig()
{
CONSOLE(F("mounting FS..."));

if (!SPIFFS.begin())
if (!LittleFS.begin())
{
CONSOLELN(F(" ERROR: failed to mount FS!"));
return false;
}
else
{
CONSOLELN(F(" mounted!"));
if (!SPIFFS.exists(CFGFILE))
if (!LittleFS.exists(CFGFILE))
{
CONSOLELN(F("ERROR: failed to load json config"));
return false;
Expand All @@ -169,7 +169,7 @@ bool readConfig()
{
// file exists, reading and loading
CONSOLELN(F("reading config file"));
File configFile = SPIFFS.open(CFGFILE, "r");
File configFile = LittleFS.open(CFGFILE, "r");
if (!configFile)
{
CONSOLELN(F("ERROR: unable to open config file"));
Expand Down Expand Up @@ -476,13 +476,13 @@ bool startConfiguration()
return false;
}

bool formatSpiffs()
bool formatLittleFS()
{
CONSOLE(F("\nneed to format SPIFFS: "));
SPIFFS.end();
SPIFFS.begin();
CONSOLELN(SPIFFS.format());
return SPIFFS.begin();
CONSOLE(F("\nneed to format LittleFS: "));
LittleFS.end();
LittleFS.begin();
CONSOLELN(LittleFS.format());
return LittleFS.begin();
}

bool saveConfig(int16_t Offset[6])
Expand All @@ -499,11 +499,11 @@ bool saveConfig()
{
CONSOLE(F("saving config...\n"));

// if SPIFFS is not usable
if (!SPIFFS.begin())
// if LittleFS is not usable
if (!LittleFS.begin())
{
Serial.println("Failed to mount file system");
if (!formatSpiffs())
if (!formatLittleFS())
{
Serial.println("Failed to format file system - hardware issues!");
return false;
Expand Down Expand Up @@ -543,11 +543,11 @@ bool saveConfig()
array.add(i);
}

File configFile = SPIFFS.open(CFGFILE, "w");
File configFile = LittleFS.open(CFGFILE, "w");
if (!configFile)
{
CONSOLELN(F("failed to open config file for writing"));
SPIFFS.end();
LittleFS.end();
return false;
}
else
Expand All @@ -558,8 +558,8 @@ bool saveConfig()
#endif
configFile.flush();
configFile.close();
SPIFFS.gc();
SPIFFS.end();
LittleFS.gc();
LittleFS.end();
CONSOLELN(F("\nsaved successfully"));
return true;
}
Expand Down

0 comments on commit d1deba4

Please sign in to comment.