Compare commits

..

2 Commits

Author SHA1 Message Date
Andrew Bowman 6caf54cea0
Merge 7b8cc9dc34 into bd8422b228 2025-11-03 06:27:11 +00:00
Andrew Bowman 7b8cc9dc34
Update API endpoint and response handling for weather
Updated API to accommodate OpenWeatherMap updated API.
2025-11-02 21:31:49 -05:00
1 changed files with 308 additions and 310 deletions

View File

@ -43,7 +43,7 @@ void OpenWeatherMapClient::updateLanguage(String language) {
void OpenWeatherMapClient::updateWeather() {
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(apiGetData);
@ -106,35 +106,33 @@ void OpenWeatherMapClient::updateWeather() {
}
int count = root["cnt"];
for (int inx = 0; inx < count; inx++) {
weathers[inx].lat = (const char*)root["list"][inx]["coord"]["lat"];
weathers[inx].lon = (const char*)root["list"][inx]["coord"]["lon"];
weathers[inx].dt = (const char*)root["list"][inx]["dt"];
weathers[inx].city = (const char*)root["list"][inx]["name"];
weathers[inx].country = (const char*)root["list"][inx]["sys"]["country"];
weathers[inx].temp = (const char*)root["list"][inx]["main"]["temp"];
weathers[inx].humidity = (const char*)root["list"][inx]["main"]["humidity"];
weathers[inx].condition = (const char*)root["list"][inx]["weather"][0]["main"];
weathers[inx].wind = (const char*)root["list"][inx]["wind"]["speed"];
weathers[inx].weatherId = (const char*)root["list"][inx]["weather"][0]["id"];
weathers[inx].description = (const char*)root["list"][inx]["weather"][0]["description"];
weathers[inx].icon = (const char*)root["list"][inx]["weather"][0]["icon"];
weathers[0].lat = (const char*)root["coord"]["lat"];
weathers[0].lon = (const char*)root["coord"]["lon"];
weathers[0].dt = (const char*)root["dt"];
weathers[0].city = (const char*)root["name"];
weathers[0].country = (const char*)root["sys"]["country"];
weathers[0].temp = (const char*)root["main"]["temp"];
weathers[0].humidity = (const char*)root["main"]["humidity"];
weathers[0].condition = (const char*)root["weather"][0]["main"];
weathers[0].wind = (const char*)root["wind"]["speed"];
weathers[0].weatherId = (const char*)root["weather"][0]["id"];
weathers[0].description = (const char*)root["weather"][0]["description"];
weathers[0].icon = (const char*)root["weather"][0]["icon"];
Serial.println("lat: " + weathers[inx].lat);
Serial.println("lon: " + weathers[inx].lon);
Serial.println("dt: " + weathers[inx].dt);
Serial.println("city: " + weathers[inx].city);
Serial.println("country: " + weathers[inx].country);
Serial.println("temp: " + weathers[inx].temp);
Serial.println("humidity: " + weathers[inx].humidity);
Serial.println("condition: " + weathers[inx].condition);
Serial.println("wind: " + weathers[inx].wind);
Serial.println("weatherId: " + weathers[inx].weatherId);
Serial.println("description: " + weathers[inx].description);
Serial.println("icon: " + weathers[inx].icon);
Serial.println("lat: " + weathers[0].lat);
Serial.println("lon: " + weathers[0].lon);
Serial.println("dt: " + weathers[0].dt);
Serial.println("city: " + weathers[0].city);
Serial.println("country: " + weathers[0].country);
Serial.println("temp: " + weathers[0].temp);
Serial.println("humidity: " + weathers[0].humidity);
Serial.println("condition: " + weathers[0].condition);
Serial.println("wind: " + weathers[0].wind);
Serial.println("weatherId: " + weathers[0].weatherId);
Serial.println("description: " + weathers[0].description);
Serial.println("icon: " + weathers[0].icon);
Serial.println();
}
}
String OpenWeatherMapClient::roundValue(String value) {