Update API endpoint and response handling for weather

Updated API to accommodate OpenWeatherMap updated API.
pull/168/head
Andrew Bowman 2025-11-02 21:31:49 -05:00 committed by GitHub
parent 40abdb6939
commit 7b8cc9dc34
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 308 additions and 310 deletions

View File

@ -43,7 +43,7 @@ void OpenWeatherMapClient::updateLanguage(String language) {
void OpenWeatherMapClient::updateWeather() { void OpenWeatherMapClient::updateWeather() {
WiFiClient weatherClient; WiFiClient weatherClient;
String apiGetData = "GET /data/2.5/group?id=" + myCityIDs + "&units=" + units + "&cnt=1&APPID=" + myApiKey + "&lang=" + lang + " HTTP/1.1"; String apiGetData = "GET /data/2.5/weather?id=" + myCityIDs + "&units=" + units + "&cnt=1&APPID=" + myApiKey + "&lang=" + lang + " HTTP/1.1";
Serial.println("Getting Weather Data"); Serial.println("Getting Weather Data");
Serial.println(apiGetData); Serial.println(apiGetData);
@ -106,35 +106,33 @@ void OpenWeatherMapClient::updateWeather() {
} }
int count = root["cnt"]; int count = root["cnt"];
for (int inx = 0; inx < count; inx++) { weathers[0].lat = (const char*)root["coord"]["lat"];
weathers[inx].lat = (const char*)root["list"][inx]["coord"]["lat"]; weathers[0].lon = (const char*)root["coord"]["lon"];
weathers[inx].lon = (const char*)root["list"][inx]["coord"]["lon"]; weathers[0].dt = (const char*)root["dt"];
weathers[inx].dt = (const char*)root["list"][inx]["dt"]; weathers[0].city = (const char*)root["name"];
weathers[inx].city = (const char*)root["list"][inx]["name"]; weathers[0].country = (const char*)root["sys"]["country"];
weathers[inx].country = (const char*)root["list"][inx]["sys"]["country"]; weathers[0].temp = (const char*)root["main"]["temp"];
weathers[inx].temp = (const char*)root["list"][inx]["main"]["temp"]; weathers[0].humidity = (const char*)root["main"]["humidity"];
weathers[inx].humidity = (const char*)root["list"][inx]["main"]["humidity"]; weathers[0].condition = (const char*)root["weather"][0]["main"];
weathers[inx].condition = (const char*)root["list"][inx]["weather"][0]["main"]; weathers[0].wind = (const char*)root["wind"]["speed"];
weathers[inx].wind = (const char*)root["list"][inx]["wind"]["speed"]; weathers[0].weatherId = (const char*)root["weather"][0]["id"];
weathers[inx].weatherId = (const char*)root["list"][inx]["weather"][0]["id"]; weathers[0].description = (const char*)root["weather"][0]["description"];
weathers[inx].description = (const char*)root["list"][inx]["weather"][0]["description"]; weathers[0].icon = (const char*)root["weather"][0]["icon"];
weathers[inx].icon = (const char*)root["list"][inx]["weather"][0]["icon"];
Serial.println("lat: " + weathers[inx].lat);
Serial.println("lon: " + weathers[inx].lon); Serial.println("lat: " + weathers[0].lat);
Serial.println("dt: " + weathers[inx].dt); Serial.println("lon: " + weathers[0].lon);
Serial.println("city: " + weathers[inx].city); Serial.println("dt: " + weathers[0].dt);
Serial.println("country: " + weathers[inx].country); Serial.println("city: " + weathers[0].city);
Serial.println("temp: " + weathers[inx].temp); Serial.println("country: " + weathers[0].country);
Serial.println("humidity: " + weathers[inx].humidity); Serial.println("temp: " + weathers[0].temp);
Serial.println("condition: " + weathers[inx].condition); Serial.println("humidity: " + weathers[0].humidity);
Serial.println("wind: " + weathers[inx].wind); Serial.println("condition: " + weathers[0].condition);
Serial.println("weatherId: " + weathers[inx].weatherId); Serial.println("wind: " + weathers[0].wind);
Serial.println("description: " + weathers[inx].description); Serial.println("weatherId: " + weathers[0].weatherId);
Serial.println("icon: " + weathers[inx].icon); Serial.println("description: " + weathers[0].description);
Serial.println("icon: " + weathers[0].icon);
Serial.println(); Serial.println();
}
} }
String OpenWeatherMapClient::roundValue(String value) { String OpenWeatherMapClient::roundValue(String value) {