Hi,
um Weatherapi zu nutzen, bediene ich mich ArduinoJason. Jetzt stehe ich bei dem Problem, das ich z.B. die Wetter Kondition auslese, aber ich für LVGL einen String
benötige:
const char text1 = doc["current"]["condition"]["text"];
lv_label_set_text(ui_kondition, text1);
Da der Text nur von ArduinoJson als const char übergeben wird, komme
ich da nicht weiter.
void loop(void)
{
if ((millis() - lastTime) > timerDelay1) {
lv_timer_handler(); /* let the GUI do its work */
lastTime1 = millis();
}
if ((millis() - lastTime) > timerDelay) {
// Check WiFi connection status
if(WiFi.status()== WL_CONNECTED){
HTTPClient http; //Declare an object of class HTTPClient
http.begin("http://api.weatherapi.com/v1/forecast.json?key=xxxxxxx&q=Gelsenkirchen&days=3&aqi=yes&alerts=yes&lang=de");
int httpCode = http.GET(); // send the request
if (httpCode > 0) { // check the returning code
String payload = http.getString(); //Get the request response payload
Serial.println(payload);
DynamicJsonDocument doc(32768);
DeserializationError error = deserializeJson(doc, payload);
if (error) {
Serial.print("Error parsing JSON: ");
Serial.println(error.c_str());
} else {
// Access individual items
Serial.println("Parsed Data:");
temp_f =doc["current"]["temp_c"];
sprintf(lvglstring,"%3.2f°C",temp_f);
lv_label_set_text(ui_tempc, lvglstring);
temp_f =doc["current"]["feelslike_c"];
sprintf(lvglstring,"%3.2f°C",temp_f);
lv_label_set_text(ui_tempfeelslike, lvglstring);
const char text1 = doc["current"]["condition"]["text"];
lv_label_set_text(ui_kondition, text1);
}
}
}
lastTime = millis();
}
}
Gruß Sascha