![]() |
Forum Index : Microcontroller and PC projects : Wunderground
Author | Message | ||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Can anyone help me to Parse the JSON calls from Wunderground please? I can do it easily from Openweathermap but Wunderground supplies much more information but it's in such a format I can't work out how to call specific things with the JSON This is what the local weather to me returns when I do the API call THIS is the section I'd like to Parse [quote]"current_observation":[/quote] Anyone able to help me with an example so I can see how to do it please? [code]{ "response": { "version":"0.1", "termsofService":"http://www.wunderground.com/weather/api/d/terms.html", "features": { "geolookup": 1 , "conditions": 1 } } , "location": { "type":"INTLCITY", "country":"UK", "country_iso3166":"GB", "country_name":"United Kingdom", "state":"", "city":"Denton", "tz_short":"BST", "tz_long":"Europe/London", "lat":"53.45000076", "lon":"-2.11666703", "zip":"00000", "magic":"19", "wmo":"03334", "l":"/q/zmw:00000.19.03334", "requesturl":"global/stations/03334.html", "wuiurl":"https://www.wunderground.com/global/stations/03334.html", "nearby_weather_stations": { "airport": { "station": [ { "city":"Manchester", "state":"", "country":"UK", "icao":"EGCC", "lat":"53.35374451", "lon":"-2.27495003" } ,{ "city":"Liverpool", "state":"", "country":"UK", "icao":"EGGP", "lat":"53.33333206", "lon":"-2.84999990" } ,{ "city":"Hawarden", "state":"", "country":"UK", "icao":"EGNR", "lat":"53.17468643", "lon":"-2.98725104" } ] } , "pws": { "station": [ { "neighborhood":"Towncroft", "city":"Denton", "state":"", "country":"GB", "id":"IDENTON3", "lat":53.458984, "lon":-2.106644, "distance_km":1, "distance_mi":0 }, { "neighborhood":"Denton", "city":"Denton", "state":"", "country":"GB", "id":"IDENTON2", "lat":53.441669, "lon":-2.149535, "distance_km":2, "distance_mi":1 }, { "neighborhood":"Woodley", "city":"Stockport", "state":"", "country":"GB", "id":"ISTOCKPO25", "lat":53.429802, "lon":-2.098587, "distance_km":2, "distance_mi":1 }, { "neighborhood":"Apethorn Lane", "city":"Hyde", "state":"", "country":"GB", "id":"IHYDE6", "lat":53.437691, "lon":-2.082155, "distance_km":2, "distance_mi":1 }, { "neighborhood":"Stockport", "city":"Stockport", "state":"", "country":"UK", "id":"ISTOCKPO24", "lat":53.427097, "lon":-2.100027, "distance_km":2, "distance_mi":1 }, { "neighborhood":"Hyde Manchester UK", "city":"Tameside", "state":"", "country":"GB", "id":"ITAMESID3", "lat":53.465546, "lon":-2.078892, "distance_km":3, "distance_mi":1 }, { "neighborhood":"Finsbury Road", "city":"Stockport", "state":"", "country":"UK", "id":"ISTOCKPO11", "lat":53.441963, "lon":-2.160971, "distance_km":3, "distance_mi":1 }, { "neighborhood":"Bredbury", "city":"Stockport", "state":"CHESHIRE", "country":"GB", "id":"ICHESHIR65", "lat":53.420250, "lon":-2.119626, "distance_km":3, "distance_mi":1 }, { "neighborhood":"Eastcote Road", "city":"Stockport", "state":"", "country":"GB", "id":"ISTOCKPO15", "lat":53.428875, "lon":-2.158185, "distance_km":3, "distance_mi":2 }, { "neighborhood":"Reddish", "city":"Stockport", "state":"ENGLAND", "country":"UNITED KINGDOM", "id":"IENGLAND412", "lat":53.425323, "lon":-2.159382, "distance_km":3, "distance_mi":2 }, { "neighborhood":"Broadstone Road", "city":"Manchester", "state":"", "country":"GB", "id":"IMANCHES10", "lat":53.430836, "lon":-2.169936, "distance_km":4, "distance_mi":2 }, { "neighborhood":"Woodcock Close", "city":"Ashton-under-Lyne", "state":"", "country":"GB", "id":"IASHTONU4", "lat":53.490543, "lon":-2.132578, "distance_km":4, "distance_mi":2 }, { "neighborhood":"Manchester", "city":"Manchester", "state":"", "country":"UK", "id":"IMANCHES49", "lat":53.476425, "lon":-2.173348, "distance_km":4, "distance_mi":2 }, { "neighborhood":"Firwood Close", "city":"Stockport", "state":"", "country":"GB", "id":"ISTOCKPO18", "lat":53.403332, "lon":-2.135916, "distance_km":5, "distance_mi":3 }, { "neighborhood":"Villdale Avenue", "city":"Stockport", "state":"", "country":"GB", "id":"ISTOCKPO20", "lat":53.398346, "lon":-2.130025, "distance_km":5, "distance_mi":3 }, { "neighborhood":"Heaton Moor", "city":"Stockport", "state":"", "country":"GB", "id":"ISTOCKPO26", "lat":53.417065, "lon":-2.188900, "distance_km":6, "distance_mi":3 }, { "neighborhood":"Ashton-Under-Lyne", "city":"Ashton-Under-Lyne", "state":"LANCASHIRE", "country":"GB", "id":"ILANCASH37", "lat":53.499050, "lon":-2.074900, "distance_km":6, "distance_mi":3 }, { "neighborhood":"Edgeley Park", "city":"Stockport", "state":"", "country":"UNITED KINGDOM", "id":"ISTOCKPO22", "lat":53.397301, "lon":-2.168726, "distance_km":6, "distance_mi":4 }, { "neighborhood":"Garners Lane", "city":"Stockport", "state":"", "country":"GB", "id":"ISTOCKPO9", "lat":53.391678, "lon":-2.155832, "distance_km":6, "distance_mi":4 }, { "neighborhood":"Edwards Way", "city":"Marple", "state":"", "country":"GB", "id":"IMARPLE7", "lat":53.392960, "lon":-2.072259, "distance_km":6, "distance_mi":4 }, { "neighborhood":"Ley Lane", "city":"Marple Bridge", "state":"", "country":"GB", "id":"IMARPLEB2", "lat":53.406174, "lon":-2.039175, "distance_km":7, "distance_mi":4 }, { "neighborhood":"The Crescent", "city":"Bramhall", "state":"", "country":"GB", "id":"IBRAMHAL6", "lat":53.389488, "lon":-2.151884, "distance_km":7, "distance_mi":4 }, { "neighborhood":"Roman Gardens, Failsworth.", "city":"Failsworth", "state":"ENGLAND", "country":"GB", "id":"IENGLAND935", "lat":53.512917, "lon":-2.149370, "distance_km":7, "distance_mi":4 }, { "neighborhood":"Millbrook", "city":"Stalybridge", "state":"", "country":"UNITED KINGDOM", "id":"ISTALYBR3", "lat":53.496193, "lon":-2.035935, "distance_km":7, "distance_mi":4 }, { "neighborhood":"Crowswood Drive", "city":"Stalybridge", "state":"", "country":"GB", "id":"ISTALYBR2", "lat":53.496265, "lon":-2.033594, "distance_km":7, "distance_mi":4 }, { "neighborhood":"Munday Street", "city":"Manchester", "state":"", "country":"GB", "id":"IMANCHES19", "lat":53.481438, "lon":-2.219390, "distance_km":7, "distance_mi":4 }, { "neighborhood":"Highfield Road", "city":"Hazel Grove", "state":"", "country":"GB", "id":"IHAZELGR2", "lat":53.379089, "lon":-2.105580, "distance_km":7, "distance_mi":4 }, { "neighborhood":"Withington", "city":"Manchester", "state":"", "country":"GB", "id":"IMANCHES25", "lat":53.427906, "lon":-2.231003, "distance_km":7, "distance_mi":4 }, { "neighborhood":"Earle Road", "city":"Cheadle", "state":"", "country":"GB", "id":"ICHEADLE3", "lat":53.381977, "lon":-2.160445, "distance_km":8, "distance_mi":4 }, { "neighborhood":"Cheadle", "city":"Cheadle", "state":"", "country":"GB", "id":"ICHEADLE2", "lat":53.392021, "lon":-2.191796, "distance_km":8, "distance_mi":4 }, { "neighborhood":"Ruabon Road", "city":"Manchester", "state":"", "country":"GB", "id":"IMANCHES26", "lat":53.412403, "lon":-2.224951, "distance_km":8, "distance_mi":4 }, { "neighborhood":"Blossom Street", "city":"Manchester", "state":"", "country":"GB", "id":"IMANCHES34", "lat":53.484833, "lon":-2.228398, "distance_km":8, "distance_mi":5 } ] } } } , "current_observation": { "image": { "url":"http://icons.wxug.com/graphics/wu2/logo_130x80.png", "title":"Weather Underground", "link":"http://www.wunderground.com" }, "display_location": { "full":"Denton, United Kingdom", "city":"Denton", "state":"", "state_name":"United Kingdom", "country":"UK", "country_iso3166":"GB", "zip":"00000", "magic":"19", "wmo":"03334", "latitude":"53.45000076", "longitude":"-2.11666703", "elevation":"97.00000000" }, "observation_location": { "full":"Denton, Denton, ", "city":"Denton, Denton", "state":"", "country":"GB", "country_iso3166":"GB", "latitude":"53.441669", "longitude":"-2.149535", "elevation":"256 ft" }, "estimated": { }, "station_id":"IDENTON2", "observation_time":"Last Updated on September 12, 7:51 PM BST", "observation_time_rfc822":"Mon, 12 Sep 2016 19:51:49 +0100", "observation_epoch":"1473706309", "local_time_rfc822":"Mon, 12 Sep 2016 19:52:00 +0100", "local_epoch":"1473706320", "local_tz_short":"BST", "local_tz_long":"Europe/London", "local_tz_offset":"+0100", "weather":"Mostly Cloudy", "temperature_string":"69.8 F (21.0 C)", "temp_f":69.8, "temp_c":21.0, "relative_humidity":"79%", "wind_string":"From the North at 3.6 MPH Gusting to 10.7 MPH", "wind_dir":"North", "wind_degrees":0, "wind_mph":3.6, "wind_gust_mph":"10.7", "wind_kph":5.8, "wind_gust_kph":"17.2", "pressure_mb":"1010", "pressure_in":"29.83", "pressure_trend":"0", "dewpoint_string":"63 F (17 C)", "dewpoint_f":63, "dewpoint_c":17, "heat_index_string":"NA", "heat_index_f":"NA", "heat_index_c":"NA", "windchill_string":"NA", "windchill_f":"NA", "windchill_c":"NA", "feelslike_string":"69.8 F (21.0 C)", "feelslike_f":"69.8", "feelslike_c":"21.0", "visibility_mi":"6.2", "visibility_km":"10.0", "solarradiation":"--", "UV":"0","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":"mostlycloudy", "icon_url":"http://icons.wxug.com/i/c/k/nt_mostlycloudy.gif", "forecast_url":"http://www.wunderground.com/global/stations/03334.html", "history_url":"http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=IDENTON2", "ob_url":"http://www.wunderground.com/cgi-bin/findweather/getForecast?query=53.441669,-2.149535", "nowcast":"" } }[/code] This is from Openweathermap and its dead simple to parse [code]{"coord":{"lon":-2.12,"lat":53.46},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],"base":"cmc stations","main":{"temp":20.31,"pressure":1010,"humidity":73,"temp_min":19.44,"temp_max":21.11},"wind":{"speed":5.1,"deg ":170},"clouds":{"all":75},"dt":1473706572,"sys":{"type":1,"id":5060,"message":0.0036,"country":"GB","sunrise":147365872 6,"sunset":1473704926},"id":2651357,"name":"Denton","cod":200} [/code] To Parse it I use this [quote]let ret = wget(query) let temp = json(ret,"main.temp") let press = json(ret,"main.pressure") let humid = json(ret,"main.humidity") let speed = json(ret,"main.speed") speed1 = int(speed + 0.5) let dir = json(ret,"main.deg") let icon = json(ret,"main.icon") let desc = json(ret,"description")[/quote] |
||||
jman![]() Guru ![]() Joined: 12/06/2011 Location: New ZealandPosts: 711 |
Hi Try and specify your location as per their example http://api.wunderground.com/api/79bbc6541de5877f/conditions/q/CA/San_Francisco.json this returns Francisco.jsonHide Response { "response": { "version": "0.1", "termsofService": "http://www.wunderground.com/weather/api/d/terms.html", "features": { "conditions": 1 } }, "current_observation": { "image": { "url": "http://icons-ak.wxug.com/graphics/wu2/logo_130x80.png", "title": "Weather Underground", "link": "http://www.wunderground.com" }, "display_location": { "full": "San Francisco, CA", "city": "San Francisco", "state": "CA", "state_name": "California", "country": "US", "country_iso3166": "US", "zip": "94101", "latitude": "37.77500916", "longitude": "-122.41825867", "elevation": "47.00000000" }, "observation_location": { "full": "SOMA - Near Van Ness, San Francisco, California", "city": "SOMA - Near Van Ness, San Francisco", "state": "California", "country": "US", "country_iso3166": "US", "latitude": "37.773285", "longitude": "-122.417725", "elevation": "49 ft" }, "estimated": {}, "station_id": "KCASANFR58", "observation_time": "Last Updated on June 27, 5:27 PM PDT", "observation_time_rfc822": "Wed, 27 Jun 2012 17:27:13 -0700", "observation_epoch": "1340843233", "local_time_rfc822": "Wed, 27 Jun 2012 17:27:14 -0700", "local_epoch": "1340843234", "local_tz_short": "PDT", "local_tz_long": "America/Los_Angeles", "local_tz_offset": "-0700", "weather": "Partly Cloudy", "temperature_string": "66.3 F (19.1 C)", "temp_f": 66.3, "temp_c": 19.1, "relative_humidity": "65%", "wind_string": "From the NNW at 22.0 MPH Gusting to 28.0 MPH", "wind_dir": "NNW", "wind_degrees": 346, "wind_mph": 22.0, "wind_gust_mph": "28.0", "wind_kph": 35.4, "wind_gust_kph": "45.1", "pressure_mb": "1013", "pressure_in": "29.93", "pressure_trend": "+", "dewpoint_string": "54 F (12 C)", "dewpoint_f": 54, "dewpoint_c": 12, "heat_index_string": "NA", "heat_index_f": "NA", "heat_index_c": "NA", "windchill_string": "NA", "windchill_f": "NA", "windchill_c": "NA", "feelslike_string": "66.3 F (19.1 C)", "feelslike_f": "66.3", "feelslike_c": "19.1", "visibility_mi": "10.0", "visibility_km": "16.1", "solarradiation": "", "UV": "5", "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": "partlycloudy", "icon_url": "http://icons-ak.wxug.com/i/c/k/partlycloudy.gif", "forecast_url": "http://www.wunderground.com/US/CA/San_Francisco.html", "history_url": "http://www.wunderground.com/history/airport/KCASANFR58/2012/6/27/DailyHistory.html", "ob_url": "http://www.wunderground.com/cgi-bin/findweather/getForecast?query=37.773285,-122.417725" } } |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
I already specified my location in the call I did (http://api.wunderground.com/api/6865d2e101980329/geolookup/conditions/q/UK/Denton.json) which gave the above response. It's how to Parse the information it sends that I need help with Specifically I want to be able to Parse the following From the section ""current_observation":" I want to Parse "local_time_rfc822": "weather": "temp_c": "relative_humidity": "wind_dir": "wind_degrees": "wind_mph": "pressure_mb": "precip_today_metric": "icon": I'm going to Parse it on an ESP8266 and this is the code I use to Parse the info from Openweathermap [code]cls let query = "api.openweathermap.org/data/2.5/weather?q=Denton,uk&lang=en&units=metric&appid=APP ID HERE" delay 500 let ret = wget(query) let temp = json(ret,"main.temp") let press = json(ret,"main.pressure") let humid = json(ret,"main.humidity") let speed = json(ret,"main.speed") speed1 = int(speed + 0.5) let dir = json(ret,"main.deg") let icon = json(ret,"main.icon") let desc = json(ret,"description") serialprintln "Today," & desc & "," & icon & "," & temp & "," & press &"," & speed1 & "," & dir & "," & humid[/code] |
||||
MicroBlocks![]() Guru ![]() Joined: 12/05/2012 Location: ThailandPosts: 2209 |
I guess you could use this: [code] let temp = json(ret, "current_observation.temp_c") [/code] Microblocks. Build with logic. |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Unfortunately it doesn't work, I tried several versions and couldn't get any to work. Hopefully "someone" has figured out how to Parse Wunderground |
||||
Bizzie Senior Member ![]() Joined: 06/07/2014 Location: AustraliaPosts: 192 |
I'm intrigued! All the code examples are in languages other that Basic. see Can you show us the subroutine json() so I can understand how this works. Rob White |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6269 |
A variation worth trying is let temp = json(ret, "temp_c")
If we can see what a full return of your Openweathermap query we might be able to work out what is needed. I have not played with the ESP's for a long time and know little about JSON queries. What I do know is, the string you query must be identical to an existing string so the Openweathermap field names will not work for you. Jim VK7JH MMedit |
||||
Bizzie Senior Member ![]() Joined: 06/07/2014 Location: AustraliaPosts: 192 |
I'll answer my own question:- This is part of ESP basic! this is from the reference manual json(): Will parse a json string for the articular named data element within it. json({string or var name for data to be parsed},{string or var name for key name in data}) The key can have the following syntax : “Key.subkey.innerkey…..” . Array can also be included such as “weather[5].description” Example with OpenWeatherAPI : let apid = “xxxxx” ‘ place your APP_ID here let query = "api.openweathermap.org/data/2.5/weather?&units=metric&q=Miami,us&appid=" & appid let ret = wget(query) serialprintln ret let desc = json(ret,"weather.description") let temp = json(ret,"main.temp") let press = json(ret,"main.pressure") let humid = json(ret,"main.humidity") Rob White |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Bizzie, if you look at post #1 I already put the code I use to parse Openweathermap There is no problem with Openweathermap The problem is the same code will not work with Wunderground. The response from Wunderground is also in post 1. I can't work out how to Parse the info I need from it. |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
I found the problem Wunderground has too much info returned, the ESP can't handle the number of characters, the returned info is 9139 characters I guess it's back to Openweathermap |
||||
Bizzie Senior Member ![]() Joined: 06/07/2014 Location: AustraliaPosts: 192 |
Try this :- http://api.wunderground.com/api/6865d2e101980329/conditions/q/UK/Denton.json Rob White |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |