mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-25 14:56:11 +02:00
fix littefs
This commit is contained in:
parent
faa28ce1a8
commit
c44eedb8c7
6 changed files with 57 additions and 45 deletions
|
@ -249,6 +249,8 @@ void app::getAvailNetworks(JsonObject obj) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app::resetSystem(void) {
|
||||
snprintf(mVersion, 12, "%d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH);
|
||||
|
||||
mUptimeSecs = 0;
|
||||
mPrevMillis = 0;
|
||||
mUpdateNtp = false;
|
||||
|
|
|
@ -53,7 +53,6 @@ class app {
|
|||
void getAvailNetworks(JsonObject obj);
|
||||
|
||||
void saveSettings(void) {
|
||||
DPRINTLN(DBG_INFO, "a");
|
||||
mSettings.saveSettings();
|
||||
}
|
||||
|
||||
|
|
|
@ -44,13 +44,13 @@
|
|||
|
||||
// default pinout (GPIO Number)
|
||||
#if defined(ESP32)
|
||||
#define DEF_CS_PIN 15
|
||||
#define DEF_CE_PIN 2
|
||||
#define DEF_IRQ_PIN 0
|
||||
#else
|
||||
#define DEF_CS_PIN 5
|
||||
#define DEF_CE_PIN 4
|
||||
#define DEF_IRQ_PIN 16
|
||||
#else
|
||||
#define DEF_CS_PIN 15
|
||||
#define DEF_CE_PIN 2
|
||||
#define DEF_IRQ_PIN 0
|
||||
#endif
|
||||
#define DEF_LED0_PIN 255 // off
|
||||
#define DEF_LED1_PIN 255 // off
|
||||
|
@ -62,7 +62,7 @@
|
|||
#define PACKET_BUFFER_SIZE 30
|
||||
|
||||
// number of configurable inverters
|
||||
#define MAX_NUM_INVERTERS 4
|
||||
#define MAX_NUM_INVERTERS 10
|
||||
|
||||
// default serial interval
|
||||
#define SERIAL_INTERVAL 5
|
||||
|
|
|
@ -157,11 +157,12 @@ class settings {
|
|||
if(!fp)
|
||||
DPRINTLN(DBG_WARN, F("failed to load json, using default config"));
|
||||
else {
|
||||
DynamicJsonDocument json(8192);
|
||||
DeserializationError err = deserializeJson(json, fp);
|
||||
DPRINTLN(DBG_INFO, fp.readString());
|
||||
fp.seek(0, SeekSet);
|
||||
DynamicJsonDocument root(4096);
|
||||
DeserializationError err = deserializeJson(root, fp);
|
||||
if(!err) {
|
||||
mValid = true;
|
||||
JsonObject root = json.to<JsonObject>();
|
||||
jsonWifi(root["wifi"]);
|
||||
jsonNrf(root["nrf"]);
|
||||
jsonNtp(root["ntp"]);
|
||||
|
@ -187,21 +188,22 @@ class settings {
|
|||
return false;
|
||||
}
|
||||
|
||||
DynamicJsonDocument json(8192);
|
||||
DynamicJsonDocument json(4096);
|
||||
JsonObject root = json.to<JsonObject>();
|
||||
jsonWifi(root["wifi"], true);
|
||||
jsonNrf(root["nrf"], true);
|
||||
jsonNtp(root["ntp"], true);
|
||||
jsonSun(root["sun"], true);
|
||||
jsonSerial(root["serial"], true);
|
||||
jsonMqtt(root["mqtt"], true);
|
||||
jsonLed(root["led"], true);
|
||||
jsonInst(root["inst"], true);
|
||||
jsonWifi(root.createNestedObject(F("wifi")), true);
|
||||
jsonNrf(root.createNestedObject(F("nrf")), true);
|
||||
jsonNtp(root.createNestedObject(F("ntp")), true);
|
||||
jsonSun(root.createNestedObject(F("sun")), true);
|
||||
jsonSerial(root.createNestedObject(F("serial")), true);
|
||||
jsonMqtt(root.createNestedObject(F("mqtt")), true);
|
||||
jsonLed(root.createNestedObject(F("led")), true);
|
||||
jsonInst(root.createNestedObject(F("inst")), true);
|
||||
|
||||
if(0 == serializeJson(root, fp)) {
|
||||
DPRINTLN(DBG_ERROR, F("can't write settings file!"));
|
||||
return false;
|
||||
}
|
||||
fp.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -235,9 +237,11 @@ class settings {
|
|||
DPRINTLN(DBG_INFO, F("loadDefaults"));
|
||||
|
||||
memset(&mCfg, 0, sizeof(settings_t));
|
||||
snprintf(mCfg.sys.stationSsid, SSID_LEN, FB_WIFI_SSID);
|
||||
snprintf(mCfg.sys.stationPwd, PWD_LEN, FB_WIFI_PWD);
|
||||
snprintf(mCfg.sys.deviceName, DEVNAME_LEN, DEF_DEVICE_NAME);
|
||||
if(wifi) {
|
||||
snprintf(mCfg.sys.stationSsid, SSID_LEN, FB_WIFI_SSID);
|
||||
snprintf(mCfg.sys.stationPwd, PWD_LEN, FB_WIFI_PWD);
|
||||
snprintf(mCfg.sys.deviceName, DEVNAME_LEN, DEF_DEVICE_NAME);
|
||||
}
|
||||
|
||||
mCfg.nrf.sendInterval = SEND_INTERVAL;
|
||||
mCfg.nrf.maxRetransPerPyld = DEF_MAX_RETRANS_PER_PYLD;
|
||||
|
@ -361,41 +365,47 @@ class settings {
|
|||
|
||||
void jsonLed(JsonObject obj, bool set = false) {
|
||||
if(set) {
|
||||
obj["0"] = mCfg.led.led0;
|
||||
obj["1"] = mCfg.led.led1;
|
||||
obj[F("0")] = mCfg.led.led0;
|
||||
obj[F("1")] = mCfg.led.led1;
|
||||
} else {
|
||||
mCfg.led.led0 = obj["0"];
|
||||
mCfg.led.led1 = obj["1"];
|
||||
mCfg.led.led0 = obj[F("0")];
|
||||
mCfg.led.led1 = obj[F("1")];
|
||||
}
|
||||
}
|
||||
|
||||
void jsonInst(JsonObject obj, bool set = false) {
|
||||
if(set) {
|
||||
obj["en"] = mCfg.inst.enabled;
|
||||
} else {
|
||||
mCfg.inst.enabled = obj["en"];
|
||||
}
|
||||
if(set)
|
||||
obj[F("en")] = mCfg.inst.enabled;
|
||||
else
|
||||
mCfg.inst.enabled = obj[F("en")];
|
||||
|
||||
JsonArray ivArr;
|
||||
if(set)
|
||||
ivArr = obj.createNestedArray(F("iv"));
|
||||
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) {
|
||||
jsonIv(obj["iv"][i], mCfg.inst.iv[i], set);
|
||||
if(set)
|
||||
jsonIv(ivArr.createNestedObject(), &mCfg.inst.iv[i], true);
|
||||
else
|
||||
jsonIv(obj[F("iv")][i], &mCfg.inst.iv[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void jsonIv(JsonObject obj, cfgIv_t cfg, bool set = false) {
|
||||
void jsonIv(JsonObject obj, cfgIv_t *cfg, bool set = false) {
|
||||
if(set) {
|
||||
obj["en"] = cfg.enabled;
|
||||
obj["name"] = cfg.name;
|
||||
obj["serial"] = cfg.serial.u64;
|
||||
obj[F("en")] = cfg->enabled;
|
||||
obj[F("name")] = cfg->name;
|
||||
obj[F("sn")] = cfg->serial.u64;
|
||||
for(uint8_t i = 0; i < 4; i++) {
|
||||
obj["chPwr"][i] = cfg.chMaxPwr[i];
|
||||
obj["chName"][i] = cfg.chName[i];
|
||||
obj[F("pwr")][i] = cfg->chMaxPwr[i];
|
||||
obj[F("chName")][i] = cfg->chName[i];
|
||||
}
|
||||
} else {
|
||||
cfg.enabled = obj["en"];
|
||||
snprintf(cfg.name, MAX_NAME_LENGTH, "%s", obj[F("name")].as<const char*>());
|
||||
cfg.serial.u64 = obj["serial"];
|
||||
cfg->enabled = obj[F("en")];
|
||||
snprintf(cfg->name, MAX_NAME_LENGTH, "%s", obj[F("name")].as<const char*>());
|
||||
cfg->serial.u64 = obj[F("sn")];
|
||||
for(uint8_t i = 0; i < 4; i++) {
|
||||
cfg.chMaxPwr[i] = obj["chPwr"][i];
|
||||
snprintf(cfg.chName[i], MAX_NAME_LENGTH, "%s", obj["chName"][i].as<const char*>());
|
||||
cfg->chMaxPwr[i] = obj[F("pwr")][i];
|
||||
snprintf(cfg->chName[i], MAX_NAME_LENGTH, "%s", obj[F("chName")][i].as<const char*>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,8 +40,8 @@ class HmSystem {
|
|||
void addInverters(cfgInst_t *config) {
|
||||
Inverter<> *iv;
|
||||
for (uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) {
|
||||
iv = addInverter(&config->iv[i]);
|
||||
if (0ULL != config->iv[i].serial.u64) {
|
||||
iv = addInverter(&config->iv[i]);
|
||||
if (NULL != iv)
|
||||
DPRINTLN(DBG_INFO, "added inverter " + String(iv->config->serial.u64, HEX));
|
||||
}
|
||||
|
|
|
@ -366,7 +366,7 @@ void web::showSave(AsyncWebServerRequest *request) {
|
|||
|
||||
|
||||
// inverter
|
||||
/*Inverter<> *iv;
|
||||
Inverter<> *iv;
|
||||
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) {
|
||||
iv = mMain->mSys->getInverterByPos(i, false);
|
||||
// address
|
||||
|
@ -390,7 +390,8 @@ void web::showSave(AsyncWebServerRequest *request) {
|
|||
request->arg("inv" + String(i) + "ModName" + String(j)).toCharArray(iv->config->chName[j], MAX_NAME_LENGTH);
|
||||
}
|
||||
iv->initialized = true;
|
||||
}*/
|
||||
}
|
||||
|
||||
if(request->arg("invInterval") != "")
|
||||
mConfig->nrf.sendInterval = request->arg("invInterval").toInt();
|
||||
if(request->arg("invRetry") != "")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue