Skip to content

Commit

Permalink
added json deserialization debug info, reduced json allocation size
Browse files Browse the repository at this point in the history
  • Loading branch information
lmarzen committed Sep 10, 2023
1 parent 03926c4 commit d0ce5a7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
17 changes: 15 additions & 2 deletions platformio/src/api_response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <vector>
#include <ArduinoJson.h>
#include "api_response.h"
#include "config.h"

DeserializationError deserializeOneCall(WiFiClient &json,
owm_resp_onecall_t &r)
Expand Down Expand Up @@ -91,10 +92,16 @@ DeserializationError deserializeOneCall(WiFiClient &json,
filter_alerts_7["description"] = false;
filter_alerts_7["tags"] = true;

DynamicJsonDocument doc(48 * 1024);
DynamicJsonDocument doc(32 * 1024);

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
#endif
if (error) {
return error;
}
Expand Down Expand Up @@ -245,9 +252,15 @@ DeserializationError deserializeAirQuality(WiFiClient &json,
{
int i = 0;

DynamicJsonDocument doc(8 * 1024);
DynamicJsonDocument doc(6 * 1024);

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
#endif
if (error) {
return error;
}
Expand Down
8 changes: 4 additions & 4 deletions platformio/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ void beginDeepSleep(unsigned long &startTime, tm *timeInfo)
// add extra delay to compensate for esp32's with fast RTCs.
sleepDuration += 10ULL;

#if DEBUG_LEVEL >= 1
printHeapUsage();
#endif

esp_sleep_enable_timer_wakeup(sleepDuration * 1000000ULL);
Serial.println("Awake for "
+ String((millis() - startTime) / 1000.0, 3) + "s");
Expand Down Expand Up @@ -326,10 +330,6 @@ void setup()
} while (display.nextPage());
display.powerOff();

#if DEBUG_LEVEL >= 1
printHeapUsage();
#endif

// DEEP-SLEEP
beginDeepSleep(startTime, &timeInfo);
} // end setup
Expand Down
4 changes: 2 additions & 2 deletions platformio/src/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ void initDisplay()
display.setTextSize(1);
display.setTextColor(GxEPD_BLACK);
display.setTextWrap(false);
display.fillScreen(GxEPD_WHITE);
// display.fillScreen(GxEPD_WHITE);
display.setFullWindow();
display.firstPage(); // use paged drawing mode
display.firstPage(); // use paged drawing mode, sets fillScreen(GxEPD_WHITE)
} // end initDisplay

/* This function is responsible for drawing the current conditions and
Expand Down

0 comments on commit d0ce5a7

Please sign in to comment.