Last active
January 29, 2016 00:32
-
-
Save iddar/6d3e49bd80752eed3794 to your computer and use it in GitHub Desktop.
Crash Json parse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <ArduinoJson.h> | |
| char json_string[512]; | |
| StaticJsonBuffer<512> jsonBuffer; | |
| // "main":"Clear","description":"sky is clear" | |
| // y tal vez temp":20,"pressure":1019,"humidity":19 | |
| char* now; | |
| char* description; | |
| double temp; | |
| double pressure; | |
| double humidity; | |
| void setup() | |
| { | |
| Serial.begin(115200); | |
| Serial.println(F("Press any key to post to IFTTT!")); | |
| getData(); | |
| } | |
| void loop() | |
| { | |
| if (Serial.available()) | |
| { | |
| while (Serial.available()) | |
| Serial.read(); | |
| } | |
| } | |
| void getData() | |
| { | |
| strcpy(json_string, "{\"coord\":{\"lon\":-102.3,\"lat\":21.88},\"weather\":[{\"id\":800,\"main\":\"Clear\",\"description\":\"sky is clear\",\"icon\":\"02n\"}],\"base\":\"cmc stations\",\"main\":{\"temp\":5,\"pressure\":1025,\"humidity\":56,\"temp_min\":5,\"temp_max\":5},\"wind\":{\"speed\":7.7,\"deg\":20},\"clouds\":{\"all\":5},\"dt\":1453956180,\"sys\":{\"type\":1,\"id\":3966,\"message\":0.0026,\"country\":\"MX\",\"sunrise\":1453987717,\"sunset\":1454027754},\"id\":4019233,\"name\":\"Aguascalientes\",\"cod\":200}"); | |
| Serial.println(F("Run...")); | |
| JsonObject& root = jsonBuffer.parseObject(json_string); | |
| if (!root.success()) { | |
| Serial.println("parseObject() failed"); | |
| return; | |
| } | |
| strcpy(now, root["coord"]["lon"]); | |
| Serial.println(now); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment