diff --git a/json_models/Config JSON.md b/json_models/Config JSON.md index d0a6d9c..92a994d 100644 --- a/json_models/Config JSON.md +++ b/json_models/Config JSON.md @@ -40,7 +40,8 @@ }, "dospiffs1": false, "dospiffs2": false, - "didupdate": false + "didupdate": false, + "nodrd": false } ``` @@ -51,18 +52,24 @@ const size_t capacity = 3*JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3) + 3*JSON_OBJ 512+728 = 1240 ``` -## Parsing: +## Deserializing: ``` -const size_t capacity = 3*JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3) + 3*JSON_OBJECT_SIZE(4) + JSON_OBJECT_SIZE(11) + 810; -DynamicJsonDocument doc(capacity); +// char* input; +// size_t inputLength; (optional) + +StaticJsonDocument<768> doc; -const char* json = "{\"apconfig\":{\"ssid\":\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\",\"passphrase\":\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"},\"hostname\":\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\",\"bubble\":{\"name\":\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\",\"tempinf\":false},\"calibrate\":{\"room\":-999.9999,\"vessel\":-999.9999},\"urltarget\":{\"url\":\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\",\"freq\":999,\"update\":false},\"brewersfriend\":{\"key\":\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\",\"channel\":0,\"freq\":9999,\"update\":false},\"brewfather\":{\"key\":\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\",\"channel\":0,\"freq\":9999,\"update\":false},\"thingspeak\":{\"key\":\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\",\"channel\":999999999,\"freq\":9999,\"update\":false},\"dospiffs1\":false,\"dospiffs2\":false,\"didupdate\":false}"; +DeserializationError error = deserializeJson(doc, input, inputLength); -deserializeJson(doc, json); +if (error) { + Serial.print(F("deserializeJson() failed: ")); + Serial.println(error.f_str()); + return; +} const char* apconfig_ssid = doc["apconfig"]["ssid"]; // "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -const char* apconfig_passphrase = doc["apconfig"]["passphrase"]; // "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" +const char* apconfig_passphrase = doc["apconfig"]["passphrase"]; const char* hostname = doc["hostname"]; // "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" @@ -73,24 +80,24 @@ float calibrate_room = doc["calibrate"]["room"]; // -999.9999 float calibrate_vessel = doc["calibrate"]["vessel"]; // -999.9999 JsonObject urltarget = doc["urltarget"]; -const char* urltarget_url = urltarget["url"]; // "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" +const char* urltarget_url = urltarget["url"]; int urltarget_freq = urltarget["freq"]; // 999 bool urltarget_update = urltarget["update"]; // false JsonObject brewersfriend = doc["brewersfriend"]; -const char* brewersfriend_key = brewersfriend["key"]; // "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" +const char* brewersfriend_key = brewersfriend["key"]; int brewersfriend_channel = brewersfriend["channel"]; // 0 int brewersfriend_freq = brewersfriend["freq"]; // 9999 bool brewersfriend_update = brewersfriend["update"]; // false JsonObject brewfather = doc["brewfather"]; -const char* brewfather_key = brewfather["key"]; // "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" +const char* brewfather_key = brewfather["key"]; int brewfather_channel = brewfather["channel"]; // 0 int brewfather_freq = brewfather["freq"]; // 9999 bool brewfather_update = brewfather["update"]; // false JsonObject thingspeak = doc["thingspeak"]; -const char* thingspeak_key = thingspeak["key"]; // "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" +const char* thingspeak_key = thingspeak["key"]; long thingspeak_channel = thingspeak["channel"]; // 999999999 int thingspeak_freq = thingspeak["freq"]; // 9999 bool thingspeak_update = thingspeak["update"]; // false @@ -98,13 +105,13 @@ bool thingspeak_update = thingspeak["update"]; // false bool dospiffs1 = doc["dospiffs1"]; // false bool dospiffs2 = doc["dospiffs2"]; // false bool didupdate = doc["didupdate"]; // false +bool nodrd = doc["nodrd"]; // false ``` ## Serializing: ``` -const size_t capacity = 3*JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3) + 3*JSON_OBJECT_SIZE(4) + JSON_OBJECT_SIZE(11); -DynamicJsonDocument doc(capacity); +DynamicJsonDocument doc(1536); JsonObject apconfig = doc.createNestedObject("apconfig"); apconfig["ssid"] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; @@ -144,6 +151,7 @@ thingspeak["update"] = false; doc["dospiffs1"] = false; doc["dospiffs2"] = false; doc["didupdate"] = false; +doc["nodrd"] = false; -serializeJson(doc, Serial); +serializeJson(doc, output); ``` diff --git a/src/execota.cpp b/src/execota.cpp index ccb4293..4d5a90d 100644 --- a/src/execota.cpp +++ b/src/execota.cpp @@ -38,6 +38,9 @@ void execfw() ESPhttpUpdate.setLedPin(LED, LOW); // "http://www.brewbubbles.com/firmware/firmware.bin" WiFiClient _client; + Log.verbose(F("Pulling Firmware from: %s" CR), F(FIRMWAREURL)); + config.nodrd = true; + saveConfig(); t_httpUpdate_return ret = ESPhttpUpdate.update(_client, F(FIRMWAREURL), "0"); switch (ret) @@ -48,7 +51,9 @@ void execfw() config.dospiffs1 = false; config.dospiffs2 = false; config.didupdate = false; + config.nodrd = true; saveConfig(); + _delay(100); ESP.restart(); break; @@ -58,7 +63,9 @@ void execfw() config.dospiffs1 = false; config.dospiffs2 = false; config.didupdate = false; + config.nodrd = true; saveConfig(); + _delay(100); ESP.restart(); break; @@ -66,8 +73,10 @@ void execfw() // We should never actually reach this as the controller // resets after OTA Log.notice(F("HTTP Firmware OTA Update complete, restarting." CR)); + config.nodrd = true; + saveConfig(); + _delay(100); ESP.restart(); - _delay(1000); break; } } @@ -80,13 +89,10 @@ void execspiffs() config.dospiffs1 = false; config.dospiffs2 = true; config.didupdate = false; + config.nodrd = true; saveConfig(); - _delay(3000); - if (LittleFS.begin()) - if (LittleFS.remove("/drd.dat")) - Log.notice(F("Deleted DRD semaphore." CR)); + _delay(100); ESP.restart(); - _delay(1000); } else if (config.dospiffs2) { @@ -98,6 +104,7 @@ void execspiffs() ESPhttpUpdate.setLedPin(LED, LOW); // "http://www.brewbubbles.com/firmware/spiffs.bin" WiFiClient client; + Log.verbose(F("Pulling Filesystem from: %s" CR), F(LITTLEFSURL)); t_httpUpdate_return ret = ESPhttpUpdate.updateFS(client, F(LITTLEFSURL), ""); switch (ret) @@ -115,11 +122,11 @@ void execspiffs() config.dospiffs1 = false; config.dospiffs2 = false; config.didupdate = true; - saveConfig(); // This not only saves the flags, it (re)saves the whole config after File System wipes it - _delay(1000); + config.nodrd = true; Log.notice(F("HTTP File System OTA Update complete, restarting." CR)); + saveConfig(); // This not only saves the flags, it (re)saves the whole config after File System wipes it + _delay(100); ESP.restart(); - _delay(1000); break; } } diff --git a/src/jsonconfig.cpp b/src/jsonconfig.cpp index 191133a..c29a226 100644 --- a/src/jsonconfig.cpp +++ b/src/jsonconfig.cpp @@ -25,8 +25,8 @@ SOFTWARE. */ const char *filename = "/config.json"; Config config; -extern const size_t capacitySerial = 3 * JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3) + 3 * JSON_OBJECT_SIZE(4) + JSON_OBJECT_SIZE(11); -extern const size_t capacityDeserial = capacitySerial + 810; +extern const size_t capacitySerial = 1536; +extern const size_t capacityDeserial = 768; bool deleteConfigFile() { @@ -478,6 +478,15 @@ void Config::load(JsonObjectConst obj) { didupdate = obj["didupdate"]; } + + if (obj["nodrd"].isNull()) + { + nodrd = false; + } + else + { + nodrd = obj["nodrd"]; + } } void Config::save(JsonObject obj) const @@ -504,4 +513,6 @@ void Config::save(JsonObject obj) const obj["dospiffs2"] = dospiffs2; // Add dospiffs1 object obj["didupdate"] = didupdate; + // Add nodrd object + obj["nodrd"] = nodrd; } diff --git a/src/jsonconfig.h b/src/jsonconfig.h index af349f9..e2d5531 100644 --- a/src/jsonconfig.h +++ b/src/jsonconfig.h @@ -94,6 +94,7 @@ struct Config bool dospiffs1; bool dospiffs2; bool didupdate; + bool nodrd; void load(JsonObjectConst); void save(JsonObject) const; diff --git a/src/main.cpp b/src/main.cpp index 0875b88..a9e4048 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -44,7 +44,7 @@ void setup() Log.notice(F("%s low, presenting portal." CR), stringify(RESETWIFI)); doWiFi(true); } - else if (drd->detectDoubleReset()) + else if (!config.nodrd && drd->detectDoubleReset()) { Log.notice(F("DRD: Triggered, presenting portal." CR)); doWiFi(true); @@ -52,6 +52,7 @@ void setup() else { Log.verbose(F("DRD: Normal boot." CR)); + config.nodrd = false; doWiFi(); } diff --git a/src/thingSpeakWork.cpp b/src/thingSpeakWork.cpp index f42d7f5..8931933 100644 --- a/src/thingSpeakWork.cpp +++ b/src/thingSpeakWork.cpp @@ -196,7 +196,7 @@ int createChannel( channelJSON = http.getString(); #ifdef PRINT_DEBUG_MESSAGES - Serial.println(F("DEBUG: Create ThingSpeak Channel results:")); + Serial.println(F("Create ThingSpeak Channel results:")); Serial.println(httpCode); //Print HTTP return code Serial.println(channelJSON); //Print request response payload #endif diff --git a/src/tools.cpp b/src/tools.cpp index 189a777..addf8f7 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -42,6 +42,9 @@ void resetController() Log.notice(F("Reboot request - rebooting system." CR)); _delay(5000); saveBpm(); + config.nodrd = true; + saveConfig(); + _delay(100); ESP.restart(); } @@ -137,6 +140,9 @@ void maintenanceLoop() // The ms clock will rollover after ~49 days. To be on the safe side, // restart the ESP after about 42 days to reset the ms clock. Log.warning(F("Maintenance: Six week routine restart.")); + config.nodrd = true; + saveConfig(); + _delay(100); ESP.restart(); } if (lastNTPUpdate > NTPRESET) diff --git a/src/wifihandler.cpp b/src/wifihandler.cpp index d04a50a..e2aa75a 100644 --- a/src/wifihandler.cpp +++ b/src/wifihandler.cpp @@ -125,8 +125,10 @@ void doWiFi(bool dontUseStoredCreds) _delay(3000); digitalWrite(LED, HIGH); Log.warning(F("Restarting." CR)); + config.nodrd = true; + saveConfig(); + _delay(100); ESP.restart(); - _delay(1000); // Just a hack to give it time to reset } else { @@ -178,6 +180,9 @@ void resetWifi() blinker.detach(); // Turn off blinker digitalWrite(LED, LOW); // Turn on LED Log.notice(F("Restarting after clearing WiFi settings." CR)); + config.nodrd = true; + saveConfig(); + _delay(100); ESP.restart(); }