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.

openweathermap doesnt work anymore
#1
I use this script (i didn't make it by myself). in January, it stopped working, but i don't know why.
I tried the script on another location and Logic machine too, it doesn't matter.
The message i got is 'Weather: cannot fetch data. Status code: timeout' (what will generate at rule 55 till 55)  it looks like he cannot connect to the server, but i don't know why.

I think the problem is between rule 11 and 49, but I'm not sure.

Maybe someone knows where i have to look at?
I tried to see what is wrong at https://openweathermap.org/appid, but i don't see it.

Code:
require('json') require('socket.http') require("ltn12") socket.http.TIMEOUT = 10 --********************************************************** -->>>>>>>>>>>>>USER MODIFICATION AREA (BEGIN)<<<<<<<<<<<<<<< --********************************************************** local searchBy = 1 -- 0-search by city name; 1-search by cityID local city = 'Amsterdam, NL' --city name local cityID= '2759794' --city ID (see openweathermap.org) local timezone= 1 --add a timeshift of your timezone (eg. timezone = 2 for Prague) local units = 'metric' --units of measured values: metric/imperial local lang = 'NL' --[[language of weather description English - en, Russian - ru, Italian - it, Spanish - es (or sp), Ukrainian - uk (or ua), German - de, Portuguese - pt, Romanian - ro, Polish - pl, Finnish - fi, Dutch - nl, French - fr, Bulgarian - bg, Swedish - sv (or se), Chinese Traditional - zh_tw, Chinese Simplified - zh (or zh_cn), Turkish - tr, Croatian - hr, Catalan - ca --]] local proxy='http://10.154.24.21:8080/' --set proxy server e.g. 'http://10.10.10.10/'. If no proxy is needed set proxy=nil local apikey='HIDDEN'  --API key can be retrieved after registration on http://openweathermap.org/appid --********************************************************** -->>>>>>>>>>>>>USER MODIFICATION AREA (END)<<<<<<<<<<<<<<<<< --********************************************************** local data,_, code, headers, status, ret local proxyServer="http://10.154.24.21:8080/" local response = {} if searchBy==0 then _, code, headers, status = socket.http.request{     url='http://api.openweathermap.org/data/2.5/weather?q='..city..'&mode=json&units='..units..'&lang='..lang..'&APPID='..apikey,     sink = ltn12.sink.table(response),     proxy=proxy   } elseif searchBy== 1 then   _, code, headers, status = socket.http.request{     url='http://api.openweathermap.org/data/2.5/weather?ID='..cityID..'&mode=json&units='..units..'&lang='..lang..'&APPID='..apikey,     sink = ltn12.sink.table(response),     proxy=proxy   }     end if code==200 then   alert('Fetch OK') else   alert('Weather: cannot fetch data. Status code: '..code)   return end ret = table.concat(response) data = json.pdecode(ret) if not data then   alert('Weather: cannot parse data')   return end log(data) grp.update('12/0/1', (data.main.temp),dt.float16) --Current temperature [Celsius deg] grp.update('12/0/2', (data.main.temp_min),dt.float16) --Minimum temperature at the moment grp.update('12/0/3', (data.main.temp_max),dt.float16) --Maximum temperature at the moment grp.update('12/0/4', (data.main.pressure),dt.float16) --Atmospheric pressure (on the sea level, if there is no sea_level or grnd_level data), hPa grp.update('12/0/5', (data.wind.speed),dt.float16) --Wind speed, mps grp.update('12/0/6', (data.wind.deg),dt.angle) --Wind direction, degrees (meteorological) grp.update('12/0/7', (data.clouds.all),dt.scale) --Cloudiness [%] grp.update('12/0/8', (data.weather[1].id),dt.int16)--Weather condition ID grp.update('12/0/9', (data.weather[1].main),dt.string)--Group of weather parameters (Rain, Snow, Extreme) grp.update('12/0/10', (data.weather[1].description),dt.string)--Weather condition within the group grp.update('12/0/11', (data.weather[1].icon),dt.string)--Weather icon ID grp.update('12/0/12', (data.rain),dt.float16) --Precipitation volume for last 3 hours, [mm] grp.update('12/0/13', (data.snow),dt.float16) --Snow volume for last 3 hours, mm --set time shift base od day saving time if os.date("*t").isdst==false then   dst_timeshift= 0 else   dst_timeshift= 1 end --convert the sunrise time to KNX datatype format sunrise_time_hour=math.floor((data.sys.sunrise%86400)/3600) sunrise_time_min=math.floor(((data.sys.sunrise%86400)%3600)/60) sunrise_time_sec=(((data.sys.sunrise%86400)%3600)%60) sunrise_time={hour=sunrise_time_hour+timezone+dst_timeshift,minute=sunrise_time_min,second=sunrise_time_sec} --convert the sunset time to KNX datatype format sunset_time_hour=math.floor((data.sys.sunset%86400)/3600) sunset_time_min=math.floor(((data.sys.sunset%86400)%3600)/60) sunset_time_sec=(((data.sys.sunset%86400)%3600)%60) sunset_time={hour=sunset_time_hour+timezone+dst_timeshift,minute=sunset_time_min,second=sunset_time_sec} grp.update('12/0/14', (sunrise_time),dt.time) --sunrise time grp.update('12/0/15', (sunset_time) ,dt.time) --sunset time grp.update('12/0/16', data.coord.lon,dt.float16) --longitude grp.update('12/0/17', data.coord.lat,dt.float16) --latitude log("Fetch of current weather data done.")

Sorry I'm just a beginner who will try more with a Logic Machine.
Reply
#2
Yr.no has a smooth API you could look into.

Sent fra min SM-G980F via Tapatalk
Reply
#3
Your script is using a proxy server. Is it really needed? Can LM access the internet directly?
Reply
#4
(24.05.2021, 09:32)admin Wrote: Your script is using a proxy server. Is it really needed? Can LM access the internet directly?

No it isn't needed, yesterday I already tried to use 'local proxy=nil' but it didn't had any effect, it still doesn't work.
Today i did do it again after your message, it works. But I did get 'cannot fetch data. Status code: 400' but i solved this part too today.
Maybe because both problems I didn't see the mistakes.

Thanks.

Simply thinks can have big problems
Reply


Forum Jump: