mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 16:29:51 +03:00
version 1.4.1
This commit is contained in:
@@ -402,10 +402,8 @@ void MyESP::_consoleShowHelp() {
|
||||
SerialAndTelnet.println(FPSTR("* set"));
|
||||
SerialAndTelnet.println(FPSTR("* set <wifi_ssid | wifi_password | mqtt_host | mqtt_username | mqtt_password> [value]"));
|
||||
SerialAndTelnet.println(FPSTR("* set erase"));
|
||||
SerialAndTelnet.println(FPSTR("* set led <on | off>"));
|
||||
SerialAndTelnet.println(FPSTR("*"));
|
||||
|
||||
// print custom commands if available. Take from progmem
|
||||
// print custom commands if available. Taken from progmem
|
||||
if (_telnetcommand_callback) {
|
||||
// find the longest key length so we can right align it
|
||||
uint8_t max_len = 0;
|
||||
@@ -513,8 +511,8 @@ void MyESP::_changeSetting(uint8_t wc, const char * setting, const char * value)
|
||||
SerialAndTelnet.printf("%s changed to %s\n\r", setting, value);
|
||||
}
|
||||
|
||||
if (_fs_saveConfig()) {
|
||||
SerialAndTelnet.println("Note, some changes will only have effect after a device reboot (use ! command)");
|
||||
if (fs_saveConfig()) {
|
||||
SerialAndTelnet.println("Note, some changes will only have effect after the ESP is restarted (use ! command)");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -811,8 +809,8 @@ bool MyESP::_fs_loadConfig() {
|
||||
// use configFile.readString
|
||||
configFile.readBytes(buf.get(), size);
|
||||
|
||||
StaticJsonBuffer<500> jsonBuffer; // https://arduinojson.org/v5/assistant/
|
||||
JsonObject & json = jsonBuffer.parseObject(buf.get());
|
||||
StaticJsonBuffer<SPIFFS_MAXSIZE> jsonBuffer;
|
||||
JsonObject & json = jsonBuffer.parseObject(buf.get());
|
||||
|
||||
const char * value;
|
||||
|
||||
@@ -831,18 +829,19 @@ bool MyESP::_fs_loadConfig() {
|
||||
value = json["mqtt_password"];
|
||||
_mqtt_password = (value) ? strdup(value) : NULL;
|
||||
|
||||
// callback for custom settings
|
||||
(_fs_callback)(MYESP_FSACTION_LOAD, json);
|
||||
// callback for loading custom settings
|
||||
// ok is false if there's a problem loading a custom setting (e.g. does not exist)
|
||||
bool ok = (_fs_callback)(MYESP_FSACTION_LOAD, json);
|
||||
|
||||
configFile.close();
|
||||
|
||||
return true;
|
||||
return ok;
|
||||
}
|
||||
|
||||
// save settings to spiffs
|
||||
bool MyESP::_fs_saveConfig() {
|
||||
StaticJsonBuffer<500> jsonBuffer; // https://arduinojson.org/v5/assistant/
|
||||
JsonObject & json = jsonBuffer.createObject();
|
||||
bool MyESP::fs_saveConfig() {
|
||||
StaticJsonBuffer<SPIFFS_MAXSIZE> jsonBuffer;
|
||||
JsonObject & json = jsonBuffer.createObject();
|
||||
|
||||
json["wifi_ssid"] = _wifi_ssid;
|
||||
json["wifi_password"] = _wifi_password;
|
||||
@@ -850,8 +849,8 @@ bool MyESP::_fs_saveConfig() {
|
||||
json["mqtt_username"] = _mqtt_username;
|
||||
json["mqtt_password"] = _mqtt_password;
|
||||
|
||||
// callback for custom settings
|
||||
(_fs_callback)(MYESP_FSACTION_SAVE, json);
|
||||
// callback for saving custom settings
|
||||
(void)(_fs_callback)(MYESP_FSACTION_SAVE, json);
|
||||
|
||||
File configFile = SPIFFS.open("/config.json", "w");
|
||||
if (!configFile) {
|
||||
@@ -872,11 +871,12 @@ void MyESP::_fs_setup() {
|
||||
return;
|
||||
}
|
||||
|
||||
// _fs_printConfig(); // for debugging
|
||||
//_fs_printConfig(); // for debugging
|
||||
|
||||
// load the config file. if it doesn't exist create it with anything that was specified
|
||||
// load the config file. if it doesn't exist create it
|
||||
if (!_fs_loadConfig()) {
|
||||
_fs_saveConfig();
|
||||
myDebug_P(PSTR("[FS] Re-creating config file"));
|
||||
fs_saveConfig();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -939,4 +939,4 @@ void MyESP::loop() {
|
||||
yield(); // ...and breath
|
||||
}
|
||||
|
||||
MyESP myESP;
|
||||
MyESP myESP; // create instance
|
||||
|
||||
@@ -61,8 +61,11 @@
|
||||
#define COLOR_CYAN "\x1B[0;36m"
|
||||
#define COLOR_WHITE "\x1B[0;37m"
|
||||
|
||||
// SPIFFS
|
||||
#define SPIFFS_MAXSIZE 500 // https://arduinojson.org/v5/assistant/
|
||||
|
||||
typedef struct {
|
||||
char key[30];
|
||||
char key[40];
|
||||
char description[100];
|
||||
} command_t;
|
||||
|
||||
@@ -72,7 +75,7 @@ typedef std::function<void(unsigned int, const char *, const char *)>
|
||||
typedef std::function<void()> wifi_callback_f;
|
||||
typedef std::function<void(uint8_t, const char *)> telnetcommand_callback_f;
|
||||
typedef std::function<void(uint8_t)> telnet_callback_f;
|
||||
typedef std::function<void(MYESP_FSACTION, JsonObject & json)> fs_callback_f;
|
||||
typedef std::function<bool(MYESP_FSACTION, JsonObject & json)> fs_callback_f;
|
||||
typedef std::function<bool(MYESP_FSACTION, uint8_t, const char *, const char *)> fs_settings_callback_f;
|
||||
|
||||
// calculates size of an 2d array at compile time
|
||||
@@ -113,6 +116,7 @@ class MyESP {
|
||||
|
||||
// FS
|
||||
void setSettings(fs_callback_f callback, fs_settings_callback_f fs_settings_callback);
|
||||
bool fs_saveConfig();
|
||||
|
||||
// general
|
||||
void end();
|
||||
@@ -178,7 +182,6 @@ class MyESP {
|
||||
|
||||
// fs
|
||||
void _fs_setup();
|
||||
bool _fs_saveConfig();
|
||||
bool _fs_loadConfig();
|
||||
void _fs_printConfig();
|
||||
void _fs_eraseConfig();
|
||||
|
||||
Reference in New Issue
Block a user