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?
#49
I made (partially found) a quick and dirty integration with met.no for a weather service a while back. Met.no is the same instance as YR.no.

Maybe someone can use (and improve, its messy) it. This version only collects the temperature and sends it to 1/1/0. Temperature is correct for the locations I have tried it. Loads of other information available in the output file. Also, you need to specify the correct longitude and latitude on the LM/SL for it to work.

Code:
require('uci')

forecast = {}


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

latitude = uci.get('genohm-scada.core.latitude')
latitude = tonumber(latitude)

longitude = uci.get('genohm-scada.core.longitude')
longitude = tonumber(longitude)

url = 'https://api.met.no/weatherapi/locationforecast/1.9/?lat='..latitude..'&lon='..longitude..''



data, err = require('ssl.https').request(url)

if data then
 require('lxp').new({
   StartElement = parsetag
   }):parse(data)
 grp.write('1/1/0/', forecast[1].temperature)
else
 log('Weather fetch failed: ' .. tostring(err))
end
Reply


Messages In This Thread
RE: Weather service not working anymore? - by FatMax - 26.02.2019, 10:25

Forum Jump: