Все отлично работает и показывает , за исключением пары моментов. Первый - время сервер отдает в формате strftime , то есть готовое (год, месяц, день, час, минуты и секунды).Так вот на экране отображается время по Гринвичу , хотя в ответе есть местное время. И вторая главная проблема - как этот код вставить в AMS ?
Вот полный ответ сервиса в JSON
Код: Выделить всё
{
"response": {
"version":"0.1",
"termsofService":"http://www.wunderground.com/weather/api/d/terms.html",
"features": {
"conditions": 1
}
}
, "current_observation": {
"image": {
"url":"http://icons.wxug.com/graphics/wu2/logo_130x80.png",
"title":"Weather Underground",
"link":"http://www.wunderground.com"
},
"display_location": {
"full":"Chisinau, Republic of Moldova",
"city":"Chisinau",
"state":"CU",
"state_name":"Republic of Moldova",
"country":"M1",
"country_iso3166":"MD",
"zip":"00000",
"magic":"1",
"wmo":"33815",
"latitude":"47.02999878",
"longitude":"28.82999992",
"elevation":"24.1"
},
"observation_location": {
"full":"Kisinev, ",
"city":"Kisinev",
"state":"",
"country":"Moldova",
"country_iso3166":"MD",
"latitude":"47.01666641",
"longitude":"28.98333359",
"elevation":"591 ft"
},
"estimated": {
},
"station_id":"33815",
"observation_time":"Last Updated on October 18, 9:00 PM EEST",
"observation_time_rfc822":"Wed, 18 Oct 2017 21:00:00 +0300",
"observation_epoch":"1508349600",
"local_time_rfc822":"Wed, 18 Oct 2017 22:10:22 +0300",
"local_epoch":"1508353822",
"local_tz_short":"EEST",
"local_tz_long":"Europe/Chisinau",
"local_tz_offset":"+0300",
"weather":"Clear",
"temperature_string":"63 F (17 C)",
"temp_f":63,
"temp_c":17,
"relative_humidity":"51%",
"wind_string":"From the SSW at 4 MPH",
"wind_dir":"SSW",
"wind_degrees":210,
"wind_mph":4,
"wind_gust_mph":0,
"wind_kph":7,
"wind_gust_kph":0,
"pressure_mb":"1018",
"pressure_in":"30.08",
"pressure_trend":"+",
"dewpoint_string":"49 F (10 C)",
"dewpoint_f":49,
"dewpoint_c":10,
"heat_index_string":"NA",
"heat_index_f":"NA",
"heat_index_c":"NA",
"windchill_string":"NA",
"windchill_f":"NA",
"windchill_c":"NA",
"feelslike_string":"63 F (17 C)",
"feelslike_f":"63",
"feelslike_c":"17",
"visibility_mi":"12.0",
"visibility_km":"20.0",
"solarradiation":"--",
"UV":"-1","precip_1hr_string":"0.00 in (0 mm)",
"precip_1hr_in":"0.00",
"precip_1hr_metric":"0",
"precip_today_string":"0.00 in (0 mm)",
"precip_today_in":"0.00",
"precip_today_metric":"0",
"icon":"clear",
"icon_url":"http://icons.wxug.com/i/c/k/nt_clear.gif",
"forecast_url":"http://www.wunderground.com/global/stations/33815.html",
"history_url":"http://www.wunderground.com/history/airport/33815/2017/10/18/DailyHistory.html",
"ob_url":"http://www.wunderground.com/cgi-bin/findweather/getForecast?query=47.01666641,28.98333359",
"nowcast":""
}
}
- Connecting to: mega
..WiFi connected
IP address: 192.168.2.103
Connecting to api.wunderground.com
Requesting URL: http://api.wunderground.com/api/4...... ... sinau.json
Receiving API weather data.................
Closing connection
Wed Oct 18 20:09:11 2017
Wed Oct 18 20:09:16 2017
Creating object...
root object created...
CurrentObservation object created...
Wed Oct 18 20:09:16 2017
Код: Выделить всё
"observation_time_rfc822":"Wed, 18 Oct 2017 21:00:00 +0300",
"observation_epoch":"1508349600",
"local_time_rfc822":"Wed, 18 Oct 2017 22:10:22 +0300" // правильное местное
Полный код для ESP32 Чтобы научить AMS работать с JSON в сервер-ажакс добавить пару строк
Код: Выделить всё
void sendJsonAnswer (WiFiClient cl) {
cl.println(makeAnswer("text/json"));
}
//========================
else if (StrContains(HTTP_req, "GET /") && StrContains(HTTP_req, ".json")) {
fileName = strtok(HTTP_req, "GET /");
webFile = SD.open("/" + (String)fileName);
if (webFile) {
sendJsonAnswer(cl);
}
else {
sendErrorAnswer(fileName, cl);
}
}