-->
Page 1 of 3

Can anyone help?

PostPosted: Fri Apr 07, 2017 8:03 am
by lew247
I'm trying to get the info from Wunderground to show on a weather station I'm building
I can get it to work fine using openweathermap.org but I can't get Wunderground to work
Anyone able to help?

This is what works with openweathermap
Code: Select alltimesetup(1)
print time()
delay 1000
print time()
timer 10 * 1000, [RUNPROGRAM]
wait
[RUNPROGRAM]
cls
PRINT "TIME" & "," & time()
serialprintln "TIME" & "," & time()
let query = "api.openweathermap.org/data/2.5/weather?q=Denton,uk&lang=en&units=metric&appid=API_KEY_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(main.speed + 0.5)
let dir = json(ret,"main.deg")
let icon = json(ret,"main.icon")
let desc = json(ret,"description")
println "Today," & desc & "," & icon & "," & temp & "," & press &"," & speed1 & "," & dir & "," & humid


This is my code for Wunderground but it fails on LINE 22

Code: Select alltimesetup(1)
print time()
delay 1000
print time()
timer 10 * 1000, [RUNPROGRAM]
wait
[RUNPROGRAM]
cls
PRINT "TIME" & "," & time()
'println "TIME" & "," & time()
let query = "api.wunderground.com/api/API_KEY_HERE/conditions/q/UK/Audenshaw.json"
delay 10
let ret = wget(query)
let temp = json(ret,"temp_c")
let press = json(ret,"pressure_mb")
let humid = json(ret,"relative_humidity")
let speed = json(ret,"main.speed")
speed1 = int(wind_mph)
let dir = json(ret,"wind_degrees")
let icon = json(ret,"icon")
let desc = json(ret,"wind_string")
println "Today," & desc & "," & icon & "," & temp & "," & press &"," & speed1 & "," & dir & "," & humid


Image


This is the actual full return from the API call that I'm trying to parse


{
"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":"Audenshaw, United Kingdom",
"city":"Audenshaw",
"state":"TAM",
"state_name":"United Kingdom",
"country":"UK",
"country_iso3166":"GB",
"zip":"00000",
"magic":"71",
"wmo":"03334",
"latitude":"53.45000076",
"longitude":"-2.11999989",
"elevation":"79.9"
},
"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 April 7, 4:51 PM BST",
"observation_time_rfc822":"Fri, 07 Apr 2017 16:51:29 +0100",
"observation_epoch":"1491580289",
"local_time_rfc822":"Fri, 07 Apr 2017 16:52:09 +0100",
"local_epoch":"1491580329",
"local_tz_short":"BST",
"local_tz_long":"Europe/London",
"local_tz_offset":"+0100",
"weather":"Clear",
"temperature_string":"61.3 F (16.3 C)",
"temp_f":61.3,
"temp_c":16.3,
"relative_humidity":"46%",
"wind_string":"From the SSW at 7.2 MPH Gusting to 14.3 MPH",
"wind_dir":"SSW",
"wind_degrees":202,
"wind_mph":7.2,
"wind_gust_mph":"14.3",
"wind_kph":11.6,
"wind_gust_kph":"23.0",
"pressure_mb":"1026",
"pressure_in":"30.30",
"pressure_trend":"0",
"dewpoint_string":"40 F (5 C)",
"dewpoint_f":40,
"dewpoint_c":5,
"heat_index_string":"NA",
"heat_index_f":"NA",
"heat_index_c":"NA",
"windchill_string":"NA",
"windchill_f":"NA",
"windchill_c":"NA",
"feelslike_string":"61.3 F (16.3 C)",
"feelslike_f":"61.3",
"feelslike_c":"16.3",
"visibility_mi":"6.2",
"visibility_km":"10.0",
"solarradiation":"--",
"UV":"3","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/clear.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":""
}
}


I'd like to get this working so I can then work on the forecast which again works fine in openweathermap*
Thanks in advance

Re: Can anyone help?

PostPosted: Fri Apr 07, 2017 3:18 pm
by Mmiscool
try splitting your println up across a couple of lines.

Re: Can anyone help?

PostPosted: Sat Apr 08, 2017 8:42 am
by lew247
I did try that but it made no difference

Re: Can anyone help?

PostPosted: Sat Apr 08, 2017 11:55 am
by PhilTilson
I don't know why it is falling over in line 22 (but then I don't always trust the error reporting!), but there are a couple of things that might be causing your problems.

The elements temp_c, pressure_mb, relative_humidity, wind_degrees, icon and wind_string are all present in the raw output from the site. However, I can't see main.speed anywhere. And your assignment statement speed1 = int(wind_mph) should surely be speed1 = int(json(ret,"wind_mph")), shouldn't it?

Let me know if these changes make any difference! ;)

Phil