22.10.2021, 17:43
I trying to integrate the alerts as well. Unfortuantely I getting the following error:
Do you have an idea what might be wrong?
Here is the complete code:
Many thanks for your help!
Best Regards
Steffen
Code:
Openweathermap 22.10.2021 19:39:38
User script:52: attempt to index global 'alerts' (a nil value)
stack traceback:
User script:52: in main chunk
Do you have an idea what might be wrong?
Here is the complete code:
Code:
require('json')
http = require('socket.http')
appid = 'xxx'
lat = 'xxx'
lon ='xxx'
lang = 'de'
units = 'metric'
url = 'http://api.openweathermap.org/data/2.5/onecall?lat=%s&lon=%s&units=%s&lang=%s&appid=%s'
url = string.format(url, lat, lon, units, lang, appid)
res, code, headers, status = http.request(url)
log (code, status, headers)
data = json.pdecode(res)
--Fault messages:
if not data then
alert('Error converting data')
return
end
if not res then
alert('Error collecting data')
return
end
current = data.current
daily = data.daily[1]
alerts = data.alerts
-- current temperature
grp.write('41/1/1', current.temp)
--current Humidity
grp.write('41/1/3', current.humidity)
--current wind speed
grp.write('41/1/6', current.wind_speed)
--daily forecast Temperature min
grp.write('41/1/4', daily.temp.min)
--daily forecast Temperature max
grp.write('41/1/5', daily.temp.max)
-- daily Weather condition
grp.write('41/1/2', daily.weather[1].description)
--daily forecast wind gust
grp.write('41/1/7', daily.wind_gust)
--daily forecast max UV Index
grp.write('41/1/8', daily.uvi)
--daily forecast max UV Index
grp.write('41/1/9', daily.rain)
--alerts
grp.write('41/1/10', alerts.event)
wetterprognose = math.ceil(daily.temp.min).."/"..math.ceil(daily.temp.max).."/"..daily.rain.."/"..math.ceil(daily.wind_gust).."/"..math.ceil(daily.uvi)
--sending daily weather forecast to MDT Taster
grp.write('41/2/1', wetterprognose)
Many thanks for your help!
Best Regards
Steffen