Hi, I'm struggling with a problem. I use an esp8266 to recieve weather information from an api, this data is send over serial to my arduino. The data gets to the arduino, but I can't parse it in to the json library. Can someone help me out? thanks in advance!
my code:
#include <ArduinoJson.h>
StaticJsonBuffer<1600> jsonBuffer;
void setup() {
Serial.begin(115200);
}
void loop() {
if (Serial.available()>0)
{
String s = Serial.readStringUntil("#"); // Until CR (Carriage Return)
s.replace("#", "");
Serial.println(s);
JsonObject& root = jsonBuffer.parseObject(s);
// Test if parsing succeeds.
if (!root.success()) {
Serial.println("parseObject() failed");
return;
} else {
Serial.println("done");
}
const char* naam = root["location"]["name"];
Serial.println(naam);
Serial.println("done");
}
}
The arduino recieves this data over the serial monitor:
{"location":{"name":"Paris","region":"Ile-de-France","country":"France","lat":48.87,"lon":2.33,"tz_id":"Europe/Paris","localtime_epoch":1535570599,"localtime":"2018-08-29 21:23"},"current":{"last_updated_epoch":1535569210,"last_updated":"2018-08-29 21:00","temp_c":17.0,"temp_f":62.6,"is_day":0,"condition":{"text":"Partly cloudy","icon":"//cdn.apixu.com/weather/64x64/night/116.png","code":1003},"wind_mph":8.1,"wind_kph":13.0,"wind_degree":310,"wind_dir":"NW","pressure_mb":1019.0,"pressure_in":30.6,"precip_mm":0.0,"precip_in":0.0,"humidity":63,"cloud":75,"feelslike_c":17.0,"feelslike_f":62.6,"vis_km":10.0,"vis_miles":6.0}}