Skip to content

Commit 43269a1

Browse files
committed
Change to ArduinoJSON
1 parent 3e3a885 commit 43269a1

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"platforms": ["espressif32"],
1818
"dependencies": [
1919
{ "name": "Adafruit GFX Library" },
20-
{ "name": "Arduino_JSON" },
20+
{ "name": "ArduinoJSON" },
2121
{ "name": "DS3232RTC" },
2222
{ "name": "NTPClient" },
2323
{

src/BLE.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
#include "config.h"
1414

15-
class BLE;
16-
1715
class BLE {
1816
public:
1917
BLE(void);

src/Watchy.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -604,13 +604,16 @@ weatherData Watchy::getWeatherData(String cityID, String units, String lang,
604604
http.begin(weatherQueryURL.c_str());
605605
int httpResponseCode = http.GET();
606606
if (httpResponseCode == 200) {
607-
String payload = http.getString();
608-
JSONVar responseObject = JSON.parse(payload);
609-
currentWeather.temperature = int(responseObject["main"]["temp"]);
610-
currentWeather.weatherConditionCode =
611-
int(responseObject["weather"][0]["id"]);
612-
currentWeather.weatherDescription =
613-
responseObject["weather"][0]["main"];
607+
String payload = http.getString();
608+
DynamicJsonDocument doc(1024);
609+
if (auto error = deserializeJson(doc, payload)) {
610+
Serial.println(error.c_str());
611+
} else {
612+
currentWeather.temperature = doc["main"]["temp"].as<int>();
613+
currentWeather.isMetric = settings.weatherUnit == String("metric");
614+
currentWeather.weatherConditionCode = doc["weather"][0]["id"].as<int16_t>();
615+
currentWeather.weatherDescription = doc["weather"][0]["main"].as<String>();
616+
}
614617
} else {
615618
// http error
616619
}

src/Watchy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <HTTPClient.h>
77
#include <NTPClient.h>
88
#include <WiFiUdp.h>
9-
#include <Arduino_JSON.h>
9+
#include <ArduinoJson.h>
1010
#include <GxEPD2_BW.h>
1111
#include <Wire.h>
1212
#include <Fonts/FreeMonoBold9pt7b.h>

0 commit comments

Comments
 (0)