Browse Source

fix littefs

pull/425/head^2
lumapu 2 years ago
parent
commit
c44eedb8c7
  1. 2
      src/app.cpp
  2. 1
      src/app.h
  3. 10
      src/config/config.h
  4. 82
      src/config/settings.h
  5. 2
      src/hm/hmSystem.h
  6. 5
      src/web/web.cpp

2
src/app.cpp

@ -249,6 +249,8 @@ void app::getAvailNetworks(JsonObject obj) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void app::resetSystem(void) { void app::resetSystem(void) {
snprintf(mVersion, 12, "%d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH);
mUptimeSecs = 0; mUptimeSecs = 0;
mPrevMillis = 0; mPrevMillis = 0;
mUpdateNtp = false; mUpdateNtp = false;

1
src/app.h

@ -53,7 +53,6 @@ class app {
void getAvailNetworks(JsonObject obj); void getAvailNetworks(JsonObject obj);
void saveSettings(void) { void saveSettings(void) {
DPRINTLN(DBG_INFO, "a");
mSettings.saveSettings(); mSettings.saveSettings();
} }

10
src/config/config.h

@ -44,13 +44,13 @@
// default pinout (GPIO Number) // default pinout (GPIO Number)
#if defined(ESP32) #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_CS_PIN 5
#define DEF_CE_PIN 4 #define DEF_CE_PIN 4
#define DEF_IRQ_PIN 16 #define DEF_IRQ_PIN 16
#else
#define DEF_CS_PIN 15
#define DEF_CE_PIN 2
#define DEF_IRQ_PIN 0
#endif #endif
#define DEF_LED0_PIN 255 // off #define DEF_LED0_PIN 255 // off
#define DEF_LED1_PIN 255 // off #define DEF_LED1_PIN 255 // off
@ -62,7 +62,7 @@
#define PACKET_BUFFER_SIZE 30 #define PACKET_BUFFER_SIZE 30
// number of configurable inverters // number of configurable inverters
#define MAX_NUM_INVERTERS 4 #define MAX_NUM_INVERTERS 10
// default serial interval // default serial interval
#define SERIAL_INTERVAL 5 #define SERIAL_INTERVAL 5

82
src/config/settings.h

@ -157,11 +157,12 @@ class settings {
if(!fp) if(!fp)
DPRINTLN(DBG_WARN, F("failed to load json, using default config")); DPRINTLN(DBG_WARN, F("failed to load json, using default config"));
else { else {
DynamicJsonDocument json(8192); DPRINTLN(DBG_INFO, fp.readString());
DeserializationError err = deserializeJson(json, fp); fp.seek(0, SeekSet);
DynamicJsonDocument root(4096);
DeserializationError err = deserializeJson(root, fp);
if(!err) { if(!err) {
mValid = true; mValid = true;
JsonObject root = json.to<JsonObject>();
jsonWifi(root["wifi"]); jsonWifi(root["wifi"]);
jsonNrf(root["nrf"]); jsonNrf(root["nrf"]);
jsonNtp(root["ntp"]); jsonNtp(root["ntp"]);
@ -187,21 +188,22 @@ class settings {
return false; return false;
} }
DynamicJsonDocument json(8192); DynamicJsonDocument json(4096);
JsonObject root = json.to<JsonObject>(); JsonObject root = json.to<JsonObject>();
jsonWifi(root["wifi"], true); jsonWifi(root.createNestedObject(F("wifi")), true);
jsonNrf(root["nrf"], true); jsonNrf(root.createNestedObject(F("nrf")), true);
jsonNtp(root["ntp"], true); jsonNtp(root.createNestedObject(F("ntp")), true);
jsonSun(root["sun"], true); jsonSun(root.createNestedObject(F("sun")), true);
jsonSerial(root["serial"], true); jsonSerial(root.createNestedObject(F("serial")), true);
jsonMqtt(root["mqtt"], true); jsonMqtt(root.createNestedObject(F("mqtt")), true);
jsonLed(root["led"], true); jsonLed(root.createNestedObject(F("led")), true);
jsonInst(root["inst"], true); jsonInst(root.createNestedObject(F("inst")), true);
if(0 == serializeJson(root, fp)) { if(0 == serializeJson(root, fp)) {
DPRINTLN(DBG_ERROR, F("can't write settings file!")); DPRINTLN(DBG_ERROR, F("can't write settings file!"));
return false; return false;
} }
fp.close();
return true; return true;
} }
@ -235,9 +237,11 @@ class settings {
DPRINTLN(DBG_INFO, F("loadDefaults")); DPRINTLN(DBG_INFO, F("loadDefaults"));
memset(&mCfg, 0, sizeof(settings_t)); memset(&mCfg, 0, sizeof(settings_t));
snprintf(mCfg.sys.stationSsid, SSID_LEN, FB_WIFI_SSID); if(wifi) {
snprintf(mCfg.sys.stationPwd, PWD_LEN, FB_WIFI_PWD); snprintf(mCfg.sys.stationSsid, SSID_LEN, FB_WIFI_SSID);
snprintf(mCfg.sys.deviceName, DEVNAME_LEN, DEF_DEVICE_NAME); 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.sendInterval = SEND_INTERVAL;
mCfg.nrf.maxRetransPerPyld = DEF_MAX_RETRANS_PER_PYLD; mCfg.nrf.maxRetransPerPyld = DEF_MAX_RETRANS_PER_PYLD;
@ -361,41 +365,47 @@ class settings {
void jsonLed(JsonObject obj, bool set = false) { void jsonLed(JsonObject obj, bool set = false) {
if(set) { if(set) {
obj["0"] = mCfg.led.led0; obj[F("0")] = mCfg.led.led0;
obj["1"] = mCfg.led.led1; obj[F("1")] = mCfg.led.led1;
} else { } else {
mCfg.led.led0 = obj["0"]; mCfg.led.led0 = obj[F("0")];
mCfg.led.led1 = obj["1"]; mCfg.led.led1 = obj[F("1")];
} }
} }
void jsonInst(JsonObject obj, bool set = false) { void jsonInst(JsonObject obj, bool set = false) {
if(set) { if(set)
obj["en"] = mCfg.inst.enabled; obj[F("en")] = mCfg.inst.enabled;
} else { else
mCfg.inst.enabled = obj["en"]; 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++) { 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) { if(set) {
obj["en"] = cfg.enabled; obj[F("en")] = cfg->enabled;
obj["name"] = cfg.name; obj[F("name")] = cfg->name;
obj["serial"] = cfg.serial.u64; obj[F("sn")] = cfg->serial.u64;
for(uint8_t i = 0; i < 4; i++) { for(uint8_t i = 0; i < 4; i++) {
obj["chPwr"][i] = cfg.chMaxPwr[i]; obj[F("pwr")][i] = cfg->chMaxPwr[i];
obj["chName"][i] = cfg.chName[i]; obj[F("chName")][i] = cfg->chName[i];
} }
} else { } else {
cfg.enabled = obj["en"]; cfg->enabled = obj[F("en")];
snprintf(cfg.name, MAX_NAME_LENGTH, "%s", obj[F("name")].as<const char*>()); snprintf(cfg->name, MAX_NAME_LENGTH, "%s", obj[F("name")].as<const char*>());
cfg.serial.u64 = obj["serial"]; cfg->serial.u64 = obj[F("sn")];
for(uint8_t i = 0; i < 4; i++) { for(uint8_t i = 0; i < 4; i++) {
cfg.chMaxPwr[i] = obj["chPwr"][i]; cfg->chMaxPwr[i] = obj[F("pwr")][i];
snprintf(cfg.chName[i], MAX_NAME_LENGTH, "%s", obj["chName"][i].as<const char*>()); snprintf(cfg->chName[i], MAX_NAME_LENGTH, "%s", obj[F("chName")][i].as<const char*>());
} }
} }
} }

2
src/hm/hmSystem.h

@ -40,8 +40,8 @@ class HmSystem {
void addInverters(cfgInst_t *config) { void addInverters(cfgInst_t *config) {
Inverter<> *iv; Inverter<> *iv;
for (uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) { for (uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) {
iv = addInverter(&config->iv[i]);
if (0ULL != config->iv[i].serial.u64) { if (0ULL != config->iv[i].serial.u64) {
iv = addInverter(&config->iv[i]);
if (NULL != iv) if (NULL != iv)
DPRINTLN(DBG_INFO, "added inverter " + String(iv->config->serial.u64, HEX)); DPRINTLN(DBG_INFO, "added inverter " + String(iv->config->serial.u64, HEX));
} }

5
src/web/web.cpp

@ -366,7 +366,7 @@ void web::showSave(AsyncWebServerRequest *request) {
// inverter // inverter
/*Inverter<> *iv; Inverter<> *iv;
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) { for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) {
iv = mMain->mSys->getInverterByPos(i, false); iv = mMain->mSys->getInverterByPos(i, false);
// address // 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); request->arg("inv" + String(i) + "ModName" + String(j)).toCharArray(iv->config->chName[j], MAX_NAME_LENGTH);
} }
iv->initialized = true; iv->initialized = true;
}*/ }
if(request->arg("invInterval") != "") if(request->arg("invInterval") != "")
mConfig->nrf.sendInterval = request->arg("invInterval").toInt(); mConfig->nrf.sendInterval = request->arg("invInterval").toInt();
if(request->arg("invRetry") != "") if(request->arg("invRetry") != "")

Loading…
Cancel
Save