2014-11-03 21:29:55 +01:00
|
|
|
// Copyright Benoit Blanchon 2014
|
|
|
|
// MIT License
|
|
|
|
//
|
|
|
|
// Arduino JSON library
|
|
|
|
// https://github.com/bblanchon/ArduinoJson
|
2014-03-01 12:59:45 +01:00
|
|
|
|
2014-11-03 21:29:55 +01:00
|
|
|
#include <ArduinoJson.h>
|
2014-03-01 12:59:45 +01:00
|
|
|
|
2014-11-03 21:29:55 +01:00
|
|
|
void setup() {
|
|
|
|
Serial.begin(9600);
|
2014-07-03 14:00:51 +02:00
|
|
|
|
2014-11-03 21:29:55 +01:00
|
|
|
StaticJsonBuffer<200> jsonBuffer;
|
2014-03-01 12:59:45 +01:00
|
|
|
|
2014-11-03 21:29:55 +01:00
|
|
|
char json[] =
|
|
|
|
"{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";
|
2014-03-01 12:59:45 +01:00
|
|
|
|
2014-11-03 21:29:55 +01:00
|
|
|
JsonObject& root = jsonBuffer.parseObject(json);
|
2014-03-01 12:59:45 +01:00
|
|
|
|
2014-11-03 21:29:55 +01:00
|
|
|
if (!root.success()) {
|
|
|
|
Serial.println("parseObject() failed");
|
|
|
|
return;
|
|
|
|
}
|
2014-03-01 12:59:45 +01:00
|
|
|
|
2014-11-03 21:29:55 +01:00
|
|
|
const char* sensor = root["sensor"];
|
|
|
|
long time = root["time"];
|
|
|
|
double latitude = root["data"][0];
|
|
|
|
double longitude = root["data"][1];
|
2014-03-01 12:59:45 +01:00
|
|
|
|
2014-11-03 21:29:55 +01:00
|
|
|
Serial.println(sensor);
|
|
|
|
Serial.println(time);
|
|
|
|
Serial.println(latitude, 6);
|
|
|
|
Serial.println(longitude, 6);
|
2014-03-01 12:59:45 +01:00
|
|
|
}
|
|
|
|
|
2014-11-03 21:29:55 +01:00
|
|
|
void loop() {
|
|
|
|
// not used in this example
|
2014-07-05 13:09:46 +02:00
|
|
|
}
|