From 369e1be43fb2863725a377498b0f0e68bfb122af Mon Sep 17 00:00:00 2001 From: Luke Marzen <98473324+lmarzen@users.noreply.github.com> Date: Sat, 2 Mar 2024 12:22:31 -0600 Subject: [PATCH] bumped dependency versions, removed use of deprecated arduinojson functions --- platformio/include/config.h | 1 + platformio/platformio.ini | 11 ++-- platformio/src/api_response.cpp | 91 ++++++++------------------------- platformio/src/main.cpp | 2 +- 4 files changed, 30 insertions(+), 75 deletions(-) diff --git a/platformio/include/config.h b/platformio/include/config.h index 4c7d64f12..c3730d0b5 100644 --- a/platformio/include/config.h +++ b/platformio/include/config.h @@ -241,6 +241,7 @@ // If defined, enables increase verbosity over the serial port. // level 0: basic status information, assists troubleshooting (default) // level 1: increased verbosity for debugging +// level 2: print api responses to serial monitor #define DEBUG_LEVEL 0 // Set the below constants in "config.cpp" diff --git a/platformio/platformio.ini b/platformio/platformio.ini index bfbe1d53b..01eb77078 100644 --- a/platformio/platformio.ini +++ b/platformio/platformio.ini @@ -20,11 +20,12 @@ platform = espressif32 @ 6.5.0 framework = arduino build_flags = '-Wall' lib_deps = - adafruit/Adafruit BME280 Library @ ^2.2.2 - adafruit/Adafruit BusIO @ ^1.11.2 - adafruit/Adafruit Unified Sensor @ ^1.1.5 - bblanchon/ArduinoJson @ ^6.19.3 - zinggjm/GxEPD2 @ ^1.4.5 + adafruit/Adafruit BME280 Library @ ^2.2.4 + adafruit/Adafruit BMP280 Library @ ^2.6.8 + adafruit/Adafruit BusIO @ ^1.15.0 + adafruit/Adafruit Unified Sensor @ ^1.1.14 + bblanchon/ArduinoJson @ ^7.0.3 + zinggjm/GxEPD2 @ ^1.5.6 [env:dfrobot_firebeetle2_esp32e] diff --git a/platformio/src/api_response.cpp b/platformio/src/api_response.cpp index eb0060ad6..8bc780f78 100644 --- a/platformio/src/api_response.cpp +++ b/platformio/src/api_response.cpp @@ -25,7 +25,7 @@ DeserializationError deserializeOneCall(WiFiClient &json, { int i; - StaticJsonDocument<832> filter; + JsonDocument filter; filter["current"] = true; filter["minutely"] = false; filter["hourly"] = true; @@ -33,77 +33,29 @@ DeserializationError deserializeOneCall(WiFiClient &json, #if !DISPLAY_ALERTS filter["alerts"] = false; #else - JsonArray filter_alerts = filter.createNestedArray("alerts"); - // description can be very long so they are filtered out to save on memory // along with sender_name - JsonObject filter_alerts_0 = filter_alerts.createNestedObject(); - filter_alerts_0["sender_name"] = false; - filter_alerts_0["event"] = true; - filter_alerts_0["start"] = true; - filter_alerts_0["end"] = true; - filter_alerts_0["description"] = false; - filter_alerts_0["tags"] = true; - JsonObject filter_alerts_1 = filter_alerts.createNestedObject(); - filter_alerts_1["sender_name"] = false; - filter_alerts_1["event"] = true; - filter_alerts_1["start"] = true; - filter_alerts_1["end"] = true; - filter_alerts_1["description"] = false; - filter_alerts_1["tags"] = true; - JsonObject filter_alerts_2 = filter_alerts.createNestedObject(); - filter_alerts_2["sender_name"] = false; - filter_alerts_2["event"] = true; - filter_alerts_2["start"] = true; - filter_alerts_2["end"] = true; - filter_alerts_2["description"] = false; - filter_alerts_2["tags"] = true; - JsonObject filter_alerts_3 = filter_alerts.createNestedObject(); - filter_alerts_3["sender_name"] = false; - filter_alerts_3["event"] = true; - filter_alerts_3["start"] = true; - filter_alerts_3["end"] = true; - filter_alerts_3["description"] = false; - filter_alerts_3["tags"] = true; - JsonObject filter_alerts_4 = filter_alerts.createNestedObject(); - filter_alerts_4["sender_name"] = false; - filter_alerts_4["event"] = true; - filter_alerts_4["start"] = true; - filter_alerts_4["end"] = true; - filter_alerts_4["description"] = false; - filter_alerts_4["tags"] = true; - JsonObject filter_alerts_5 = filter_alerts.createNestedObject(); - filter_alerts_5["sender_name"] = false; - filter_alerts_5["event"] = true; - filter_alerts_5["start"] = true; - filter_alerts_5["end"] = true; - filter_alerts_5["description"] = false; - filter_alerts_5["tags"] = true; - JsonObject filter_alerts_6 = filter_alerts.createNestedObject(); - filter_alerts_6["sender_name"] = false; - filter_alerts_6["event"] = true; - filter_alerts_6["start"] = true; - filter_alerts_6["end"] = true; - filter_alerts_6["description"] = false; - filter_alerts_6["tags"] = true; - JsonObject filter_alerts_7 = filter_alerts.createNestedObject(); - filter_alerts_7["sender_name"] = false; - filter_alerts_7["event"] = true; - filter_alerts_7["start"] = true; - filter_alerts_7["end"] = true; - filter_alerts_7["description"] = false; - filter_alerts_7["tags"] = true; + for (int i = 0; i < OWM_NUM_ALERTS; ++i) + { + filter["alerts"][i]["sender_name"] = false; + filter["alerts"][i]["event"] = true; + filter["alerts"][i]["start"] = true; + filter["alerts"][i]["end"] = true; + filter["alerts"][i]["description"] = false; + filter["alerts"][i]["tags"] = true; + } #endif - DynamicJsonDocument doc(32 * 1024); + JsonDocument doc; DeserializationError error = deserializeJson(doc, json, DeserializationOption::Filter(filter)); #if DEBUG_LEVEL >= 1 - Serial.println("[debug] doc.memoryUsage() : " - + String(doc.memoryUsage()) + " B"); - Serial.println("[debug] doc.capacity() : " - + String(doc.capacity()) + " B"); // 0 on allocation failure + Serial.println("[debug] doc.overflowed() : " + + String(doc.overflowed())); +#endif +#if DEBUG_LEVEL >= 2 + serializeJsonPretty(doc, Serial); #endif if (error) { return error; @@ -257,14 +209,15 @@ DeserializationError deserializeAirQuality(WiFiClient &json, { int i = 0; - DynamicJsonDocument doc(6 * 1024); + JsonDocument doc; DeserializationError error = deserializeJson(doc, json); #if DEBUG_LEVEL >= 1 - Serial.println("[debug] doc.memoryUsage() : " - + String(doc.memoryUsage()) + " B"); - Serial.println("[debug] doc.capacity() : " - + String(doc.capacity()) + " B"); // 0 on allocation failure + Serial.println("[debug] doc.overflowed() : " + + String(doc.overflowed())); +#endif +#if DEBUG_LEVEL >= 2 + serializeJsonPretty(doc, Serial); #endif if (error) { return error; diff --git a/platformio/src/main.cpp b/platformio/src/main.cpp index 72d41c749..de7b95f9e 100644 --- a/platformio/src/main.cpp +++ b/platformio/src/main.cpp @@ -30,7 +30,7 @@ #include "display_utils.h" #include "icons/icons_196x196.h" #include "renderer.h" -#ifndef USE_HTTP +#if defined(USE_HTTPS_WITH_CERT_VERIF) || defined(USE_HTTPS_WITH_CERT_VERIF) #include #endif #ifdef USE_HTTPS_WITH_CERT_VERIF