Skip to content

Commit

Permalink
bumped dependency versions, removed use of deprecated arduinojson fun…
Browse files Browse the repository at this point in the history
…ctions
  • Loading branch information
lmarzen committed Mar 2, 2024
1 parent 2dc7ea7 commit 369e1be
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 75 deletions.
1 change: 1 addition & 0 deletions platformio/include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 6 additions & 5 deletions platformio/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
91 changes: 22 additions & 69 deletions platformio/src/api_response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,85 +25,37 @@ DeserializationError deserializeOneCall(WiFiClient &json,
{
int i;

StaticJsonDocument<832> filter;
JsonDocument filter;
filter["current"] = true;
filter["minutely"] = false;
filter["hourly"] = true;
filter["daily"] = true;
#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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion platformio/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <WiFiClientSecure.h>
#endif
#ifdef USE_HTTPS_WITH_CERT_VERIF
Expand Down

0 comments on commit 369e1be

Please sign in to comment.