|
|
@ -29,10 +29,23 @@ |
|
|
|
#include <HTTPClient.h> |
|
|
|
#include <HTTPClient.h> |
|
|
|
#define GET_CHIPID() ((uint16_t)(ESP.getEfuseMac()>>32)) |
|
|
|
#define GET_CHIPID() ((uint16_t)(ESP.getEfuseMac()>>32)) |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
#include <FS.h> |
|
|
|
|
|
|
|
#include <PubSubClient.h> |
|
|
|
#include <PubSubClient.h> |
|
|
|
#include <AutoConnect.h> |
|
|
|
#include <AutoConnect.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
AC_USE_SPIFFS indicates SPIFFS or LittleFS as available file systems that |
|
|
|
|
|
|
|
will become the AUTOCONNECT_USE_SPIFFS identifier and is exported as showng |
|
|
|
|
|
|
|
the valid file system. After including AutoConnect.h, the Sketch can determine |
|
|
|
|
|
|
|
whether to use FS.h or LittleFS.h by AUTOCONNECT_USE_SPIFFS definition. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
#ifdef AUTOCONNECT_USE_SPIFFS |
|
|
|
|
|
|
|
#include <FS.h> |
|
|
|
|
|
|
|
FS& FlashFS = SPIFFS; |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
#include <LittleFS.h> |
|
|
|
|
|
|
|
FS& FlashFS = LittleFS; |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#define PARAM_FILE "/param.json" |
|
|
|
#define PARAM_FILE "/param.json" |
|
|
|
#define AUX_MQTTSETTING "/mqtt_setting" |
|
|
|
#define AUX_MQTTSETTING "/mqtt_setting" |
|
|
|
#define AUX_MQTTSAVE "/mqtt_save" |
|
|
|
#define AUX_MQTTSAVE "/mqtt_save" |
|
|
@ -110,7 +123,7 @@ int getStrength(uint8_t points) { |
|
|
|
|
|
|
|
|
|
|
|
String loadParams(AutoConnectAux& aux, PageArgument& args) { |
|
|
|
String loadParams(AutoConnectAux& aux, PageArgument& args) { |
|
|
|
(void)(args); |
|
|
|
(void)(args); |
|
|
|
File param = SPIFFS.open(PARAM_FILE, "r"); |
|
|
|
File param = FlashFS.open(PARAM_FILE, "r"); |
|
|
|
if (param) { |
|
|
|
if (param) { |
|
|
|
aux.loadElement(param); |
|
|
|
aux.loadElement(param); |
|
|
|
param.close(); |
|
|
|
param.close(); |
|
|
@ -144,7 +157,7 @@ String saveParams(AutoConnectAux& aux, PageArgument& args) { |
|
|
|
// The entered value is owned by AutoConnectAux of /mqtt_setting.
|
|
|
|
// The entered value is owned by AutoConnectAux of /mqtt_setting.
|
|
|
|
// To retrieve the elements of /mqtt_setting, it is necessary to get
|
|
|
|
// To retrieve the elements of /mqtt_setting, it is necessary to get
|
|
|
|
// the AutoConnectAux object of /mqtt_setting.
|
|
|
|
// the AutoConnectAux object of /mqtt_setting.
|
|
|
|
File param = SPIFFS.open(PARAM_FILE, "w"); |
|
|
|
File param = FlashFS.open(PARAM_FILE, "w"); |
|
|
|
portal.aux("/mqtt_setting")->saveElement(param, { "mqttserver", "channelid", "userkey", "apikey", "period", "uniqueid", "hostname" }); |
|
|
|
portal.aux("/mqtt_setting")->saveElement(param, { "mqttserver", "channelid", "userkey", "apikey", "period", "uniqueid", "hostname" }); |
|
|
|
param.close(); |
|
|
|
param.close(); |
|
|
|
|
|
|
|
|
|
|
@ -205,17 +218,17 @@ void handleClearChannel() { |
|
|
|
webServer.client().stop(); |
|
|
|
webServer.client().stop(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Load AutoConnectAux JSON from SPIFFS.
|
|
|
|
// Load AutoConnectAux JSON from the flash on the board.
|
|
|
|
bool loadAux(const String auxName) { |
|
|
|
bool loadAux(const String auxName) { |
|
|
|
bool rc = false; |
|
|
|
bool rc = false; |
|
|
|
String fn = auxName + ".json"; |
|
|
|
String fn = auxName + ".json"; |
|
|
|
File fs = SPIFFS.open(fn.c_str(), "r"); |
|
|
|
File fs = FlashFS.open(fn.c_str(), "r"); |
|
|
|
if (fs) { |
|
|
|
if (fs) { |
|
|
|
rc = portal.load(fs); |
|
|
|
rc = portal.load(fs); |
|
|
|
fs.close(); |
|
|
|
fs.close(); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
Serial.println("SPIFFS open failed: " + fn); |
|
|
|
Serial.println("Filesystem open failed: " + fn); |
|
|
|
return rc; |
|
|
|
return rc; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|