This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Weather service not working anymore?
#19
(30.03.2016, 10:45)admin Wrote: Another option is to use forecast from http://yr.no
You have to replace URL with the one that corresponds to your location.

Code:
require('socket.http')

forecast = {}

function parsetag(parser, tag, attributes)
 if tag == 'time' then
   table.insert(forecast, {})
 elseif tag == 'symbol' then
   forecast[ #forecast ].symbol = attributes.name
 elseif tag == 'precipitation' then
   forecast[ #forecast ].precipitation = attributes.value
 elseif tag == 'windDirection' then
   forecast[ #forecast ].wind_direction = attributes.code
 elseif tag == 'windSpeed' then
   forecast[ #forecast ].wind_speed = attributes.mps
 elseif tag == 'temperature' then
   forecast[ #forecast ].temperature = attributes.value
 elseif tag == 'pressure' then
   forecast[ #forecast ].pressure = attributes.value
 end
end

url = 'http://www.yr.no/place/United_Kingdom/England/London/varsel.xml'
data, err = socket.http.request(url)

if data then
 require('lxp').new({
   StartElement = parsetag
 }):parse(data)

 log(forecast)
else
 alert('Fetch failed: ' .. tostring(err))
end

Just made a test of this to get the temperature sent on the bus. It works OK as far as I can see.

But is there a way to ask for the weather for a certain time in the future? I guess there is, but can't really see it... I would like to know what the temperature will be in one hour's time to be able to lower the blinds before the sun starts heating the room.

Trond
There are 10 kinds of people in the world; those who can read binary and those who don't  Cool
Reply


Messages In This Thread
RE: Weather service not working anymore? - by Trond Hoyem - 01.10.2017, 12:48

Forum Jump: