ArduionJson 6 bits

This commit is contained in:
Paul Warren 2022-12-06 22:41:37 +11:00
parent a8a28f0af2
commit 4b93757d38
1 changed files with 41 additions and 35 deletions

View File

@ -46,7 +46,7 @@ WiFiUDP ntpUDP;
HTTPClient http;
NTPClient timeClient(ntpUDP, "pi.lan", 0, 60000); //use internal ntp server, update every 10 minutes, taking in to account the 9 seconds it takes to update the screen for the current time
//NTPClient timeClient(ntpUDP, "au.pool.ntp.org", 0, 60000); //use internal ntp server, update every 10 minutes
//NTPClient timeClient(ntpUDP, "au.pool.ntp.org", 0, 60000); //use external ntp server, update every 10 minutes
// defined in "credentials.h"
const char* ssid = ssid_name; // The SSID (name) of your Wi-Fi network
@ -250,37 +250,43 @@ void printDateTime(int update_epd)
void weatherUpdate(void) {
char buf[64];
const size_t capacity = 4*JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(4) + 150;
DynamicJsonBuffer jsonBuffer(capacity);
DynamicJsonDocument jsonBuffer(capacity);
http.begin(wfclient, ds_url);
int httpCode = http.GET();
if (httpCode > 0) {
JsonObject& root = jsonBuffer.parseObject(http.getString());
/* ArduinoJson v5 bits JsonObject& root = jsonBuffer.parseObject(http.getString());
if (!root.success()) {
Serial.print(F("parseObject() failed: "));
return; */
auto error = deserializeJson(jsonBuffer, http.getString());
if (error) {
Serial.print("Failed to parse json");
return;
}
http.end();
JsonObject& today = root["today"];
const char* today_day = today["day"]; // "Wednesday"
const char* today_icon = today["icon"]; // "sunny.jpg"
const char* today_max = today["max"]; // "27"
//JsonObject& today = jsonBuffer["today"];
const char* today_day = jsonBuffer["today"]["day"]; // "Wednesday"
const char* today_icon = jsonBuffer["today"]["icon"]; // "sunny.jpg"
const char* today_max = jsonBuffer["today"]["max"]; // "27"
JsonObject& tomorrow = root["tomorrow"];
const char* tomorrow_day = tomorrow["day"]; // "Thursday"
const char* tomorrow_icon = tomorrow["icon"]; // "sunny.jpg"
const char* tomorrow_max = tomorrow["max"]; // "31"
//JsonObject& tomorrow = jsonBuffer["tomorrow"];
const char* tomorrow_day = jsonBuffer["tomorrow"]["day"]; // "Thursday"
const char* tomorrow_icon = jsonBuffer["tomorrow"]["icon"]; // "sunny.jpg"
const char* tomorrow_max = jsonBuffer["tomorrow"]["max"]; // "31"
JsonObject& day_after = root["day_after"];
const char* day_after_day = day_after["day"]; // "Friday"
const char* day_after_icon = day_after["icon"]; // "pcloud.jpg"
const char* day_after_max = day_after["max"]; // "33"
//JsonObject& day_after = jsonBuffer["day_after"];
const char* day_after_day = jsonBuffer["day_after"]["day"]; // "Friday"
const char* day_after_icon = jsonBuffer["day_after"]["icon"]; // "pcloud.jpg"
const char* day_after_max = jsonBuffer["day_after"]["max"]; // "33"
JsonObject& current = root["current"];
current_outside = current["outside"];
current_bedroom = current["bedroom"];
current_lounge = current["lounge"];
//JsonObject& current = jsonBuffer["current"];
current_outside = jsonBuffer["current"]["outside"];
current_bedroom = jsonBuffer["current"]["bedroom"];
current_lounge = jsonBuffer["current"]["lounge"];
Serial.println("Updating EPD with weather");