-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjson.h
46 lines (34 loc) · 1.08 KB
/
json.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef json_h
#define json_h
#include <ArduinoJson.h>
void json_test(){
char json[] =
"{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";
// Deserialize the JSON document
DeserializationError error = deserializeJson(doc, json);
// deserializeJson(doc, STREAM);
// Test if parsing succeeds.
if (error) {
Serial.print(F("deserializeJson() failed: "));
Serial.println(error.f_str());
return;
}
serializeJsonPretty(json, Serial);
const char* sensor = doc["sensor"];
long time = doc["time"];
double latitude = doc["data"][0];
double longitude = doc["data"][1];
// Print values.
Serial.println(sensor);
Serial.println(time);
Serial.println(latitude, 6);
Serial.println(longitude, 6);
// The filter: it contains "true" for each value we want to keep
// StaticJsonDocument<200> filter;
// filter["list"][0]["dt"] = true;
// filter["list"][0]["main"]["temp"] = true;
// // Deserialize the document
// StaticJsonDocument<400> doc;
// deserializeJson(doc, input_json, DeserializationOption::Filter(filter));
}
#endif