01.10.2017, 12:48
(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