Skip to content

Commit 6a5b142

Browse files
committed
update to json6
1 parent f0de90d commit 6a5b142

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

Hue_Controller/Hue_Controller.ino

+16-15
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Adafruit_MQTT_Publish photocell_feed(&mqtt, AIO_USER "/feeds/hue-controller.hue-
4444
Adafruit_MQTT_Publish motion_feed(&mqtt, AIO_USER "/feeds/hue-controller.hue-motion");
4545
Adafruit_MQTT_Publish control_feed(&mqtt, AIO_USER "/feeds/hue-controller.hue-control");
4646

47-
DynamicJsonBuffer jsonBuffer(8500);
47+
DynamicJsonDocument jsonBuffer(8500);
4848

4949
const char *hue_ip = NULL;
5050
uint8_t *light_numbers = NULL;
@@ -129,16 +129,16 @@ const char *fetch_hue_ip() {
129129
return NULL;
130130
}
131131

132-
JsonArray& root = jsonBuffer.parseArray(client);
132+
auto error = deserializeJson(jsonBuffer, client);
133133
client.stop();
134134

135-
if (!root.success()) {
135+
if (error) {
136136
logln("JSON PARSE ERROR");
137137
display.println("JSON PARSE ERROR");
138138
return NULL;
139139
}
140140

141-
return strdup(root[0][F("internalipaddress")]);
141+
return strdup(jsonBuffer["internalipaddress"]);
142142
}
143143

144144

@@ -183,19 +183,18 @@ boolean fetch_sunrise_sunset(long *sunrise, long *sunset)
183183
return false;
184184
}
185185

186-
JsonObject& root = jsonBuffer.parseObject(client);
186+
auto error = deserializeJson(jsonBuffer, client);
187187
client.stop();
188188

189-
if (!root.success()) {
189+
if (error) {
190190
logln("JSON PARSE ERROR");
191191
display.println("JSON PARSE ERROR");
192-
return false;
192+
return NULL;
193193
}
194194

195-
JsonObject& data = root["daily"]["data"][0];
196-
long start_of_day = data["time"];
197-
long raw_sunrise_time = data["sunriseTime"];
198-
long raw_sunset_time = data["sunsetTime"];
195+
long start_of_day = jsonBuffer["daily"]["data"][0]["time"];
196+
long raw_sunrise_time = jsonBuffer["daily"]["data"][0]["sunriseTime"];
197+
long raw_sunset_time = jsonBuffer["daily"]["data"][0]["sunsetTime"];
199198

200199
*sunrise = raw_sunrise_time - start_of_day;
201200
*sunset = raw_sunset_time - start_of_day;
@@ -263,18 +262,20 @@ uint8_t *lights_for_group(const char *group_number)
263262
return NULL;
264263
}
265264

266-
JsonObject& group = jsonBuffer.parseObject(client);
265+
auto error = deserializeJson(jsonBuffer, client);
267266
client.stop();
268267

269-
if (!group.success()) {
268+
if (error) {
269+
logln("JSON PARSE ERROR");
270270
display.println("JSON PARSE ERROR");
271271
return NULL;
272272
}
273273

274-
JsonArray& lights = group["lights"];
274+
JsonArray lights = jsonBuffer["lights"];
275+
275276
uint8_t *light_numbers = (uint8_t*)malloc(lights.size() + 1);
276277
light_numbers[0] = (uint8_t)lights.size();
277-
for (uint i = 0; i < lights.size(); i++) {
278+
for (uint16_t i = 0; i < lights.size(); i++) {
278279
light_numbers[i+1] = (uint8_t)atoi((const char *)lights[i]);
279280
}
280281
return light_numbers;

Hue_Controller/arduino_secrets.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
#define SECRET_SSID "ssid"
2-
#define SECRET_PASS "password"
1+
#define WIFI_SSID "ssid"
2+
#define WIFI_PASS "password"
3+
#define HUE_USER "foobar"
4+
#define AIO_USER "blinka"
5+
#define AIO_KEY "12345678900aasdfqwerzxvb"
6+
#define DARKSKY_KEY "12345678900aasdfqwerzxvb"

0 commit comments

Comments
 (0)