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.

openweather ONE call API
#13
Many thanks for the help! It is working now.

Here my complete script for all other users to continue with it:

Code:
require('json')
http = require('socket.http')

appid = 'xxxx'
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 or 0))
--alerts
if type(alerts) == 'table' and type(alerts[1]) == 'table' then
   alert_event = alerts[1].event
end
grp.write('41/1/10', alert_event or '')


wetterprognose = math.ceil(daily.temp.min).."-"..math.ceil(daily.temp.max).."/"..(daily.rain or 0).."/"..math.ceil(daily.wind_gust).."/"..math.ceil(daily.uvi)

--sending daily weather forecast to MDT Taster
grp.write('7/2/3', wetterprognose)
Reply


Messages In This Thread
openweather ONE call API - by pioneersteffen - 17.10.2021, 11:35
RE: openweather ONE call API - by admin - 18.10.2021, 06:07
RE: openweather ONE call API - by JRP - 19.10.2021, 10:16
RE: openweather ONE call API - by admin - 21.10.2021, 06:22
RE: openweather ONE call API - by admin - 22.10.2021, 06:43
RE: openweather ONE call API - by admin - 25.10.2021, 06:50
RE: openweather ONE call API - by pioneersteffen - 28.10.2021, 03:57
RE: openweather ONE call API - by AlexLV - 30.10.2021, 20:03
RE: openweather ONE call API - by AlexLV - 31.10.2021, 14:30
RE: openweather ONE call API - by admin - 15.01.2024, 09:14
RE: openweather ONE call API - by admin - 15.01.2024, 10:26
RE: openweather ONE call API - by admin - 15.01.2024, 10:32

Forum Jump: