General area when it fits no where else

Moderator: Mmiscool

User avatar
By lew247
#55008 Can anyone help me to figure out how to parse the JSON information from Wunderground please?
I can do it using the ESP8266 from Openweather but the output from Wunderground is different and I've no idea how to parse it

I want to get the info from THIS section "current_observation":

I "Tried" this code but it fails
it sits waiting for the query to return
Code: Select alltimesetup(1)
print time()
delay 1000
print time()
timer 15 * 1000, [RUNPROGRAM]
wait

[RUNPROGRAM]
serialflush
cls
let query="api.wunderground.com/api/API-KEY-HERE/geolookup/conditions/q/UK/Denton.json"
delay 500
let ret = wget(query)
let temp = json(ret,"current_observation.temp_c")
let press = json(ret,"pressure_mb" )
let humid = json(ret,"relative_humidity")
let speed = json(ret,"wind_mph")
'speed1 = int(speed + 0.5)
let dir = json(ret,"wind_degrees")
let icon = json(ret,"icon")
let desc = json(ret,"weather")
print "Today," & desc & "," & icon & "," & temp & "," & press &"," & speed & "," & dir & "," & humid
[return]


Her's where the debug says it got as far as

Image
User avatar
By bugs
#55029 Suggest look at post 55019 by MMISCOOL this afternoon - try the prog with the "lets" removed.

I copied your code, did the removals and got a reply - obviously it said:-

ret = " { "response": { "version":"0.1", "termsofService":"http://www.wunderground.com/weather/api/d/terms.html", "features": { } , "error": { "type": "keynotfound" ,"description": "this key does not exist" } } } "
User avatar
By bugs
#55032 I signed up and got a key - but with the key inserted, the program fails with debug on the "get" line and the ESP throws an exception and reboots!
Strange that it gets a response and runs ok with a duff key (/API-KEY-HERE/).
Sorry - out of my depth here...

Unrelated - but the timer routine should end in "wait" according to the docs so suggest replace your [return] with wait.
User avatar
By bugs
#55037 Ok - I think the problem is that when you have a good key and a valid query wunderground sends back a string of characters that is too big for the BASIC program - so ESP crashes.
I could not find the limit for a BASIC string in the docs so made a program loop increasing a string by 10 characters each time round the loop. When it reached 270 characters this message appeared:-
"BUFFER TOO BIG! PROGRAM STOPPED"

I found this post 10898 in the lua section:-
"Getting data from Wunderground API"
viewtopic.php?f=24&t=1815&start=8&hilit=WUNDERGROUND

The author gives several example queries and the number of charactes returned - varying from 557 to 30541.
The only answer seems to be dump wunderground and use openweathermap.org.