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 api
#21
Post full script code
Reply
#22
Excuse me, here it is.
Code:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
require('json')                                     require('ssl.https')                         appid = 'xxxxxxxxxxxxxxxxxxx'     lat = 'xxxxx'                                                             lon ='xxxxx'                                                             lang = 'es'                                                                     url = 'https://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)                                                                                         JSON_Tiempo, error = ssl.https.request(url)                                                                                                                 log(url, JSON_Tiempo, error)                                                                                                                                             Tabla_tiempo = json.pdecode(JSON_Tiempo)                                                                                                                                                                                                                                                                                                          if type(Tabla_tiempo) ~= 'table' then                                                                                                                       alert('Fallo al cargar la información del tiempo de Openweather')                                                         elseif Tabla_tiempo.cod == 401 then                                                                                                                           alert('Fallo con la llave de la API de Openweather')                                                                                   elseif Tabla_tiempo.cod == 404 then   alert('Fallo en la solicitud de la API de Openweather')   elseif Tabla_tiempo.cod == 429 then   alert('Fallo por exceder el límite de llamadas a la API de Openweather')   return end Tiempo_actual = Tabla_tiempo.current log(Tiempo_actual) grp.write('32/2/10', Tiempo_actual.temp)                                                                                                             grp.write('32/2/11', Tiempo_actual.feels_like) grp.write('32/2/12', Tiempo_actual.dew_point) grp.write('32/2/13', Tiempo_actual.wind_deg) grp.write('32/2/14', Tiempo_actual.wind_speed) grp.write('32/2/15', Tiempo_actual.humidity) grp.write('32/2/16', Tiempo_actual.pressure) grp.write('32/2/17', Tiempo_actual.uvi) grp.write('32/2/18', Tiempo_actual.weather[1].description) amanecer = os.date("%H:%M", Tiempo_actual.sunrise) grp.write('32/2/19', amanecer) ocaso = os.date("%H:%M", Tiempo_actual.sunset) grp.write('32/2/20', ocaso)
Reply
#23
Add return after alert on line 21:
Code:
123
if type(Tabla_tiempo) ~= 'table' then   alert('Fallo al cargar la información del tiempo de Openweather')   return
Reply
#24
Thanks for your quick response.
Isn't the return on line 29 enough?
Reply
#25
No because it belongs to a different if branch. return should be placed after each alert in your code.
Reply
#26
The point is that this part of the code works, after removing a letter from the token and the corresponding text appears in alerts.
Reply
#27
It works up to this line then stops with an error if Tabla_tiempo is not a table:
Code:
1
Tiempo_actual = Tabla_tiempo.current
Reply
#28
I have modified the code so it works shown in the alert log the text Failed to load the Openweather weather information, if you put the return.
Code:
123456789101112
-- Comprobación de errores if type(Tabla_tiempo) == 'table' then                                                                                                                    -- Si el contenido de la variable es distinto a una tabla entonces   alert('Fallo al cargar la información del tiempo de Openweather')         -- Si la llamada devuelve el codigo de error 401, 404 0 429 elseif Tabla_tiempo.cod == 401 then                                                                                                                           alert('Fallo con la llave de la API de Openweather')                                                                                -- Mensajes de error   elseif Tabla_tiempo.cod == 404 then   alert('Fallo en la solicitud de la API de Openweather')   elseif Tabla_tiempo.cod == 429 then   alert('Fallo por exceder el límite de llamadas a la API de Openweather')   return end
The issue is that the error does not appear after successfully executing the script several times. I think only the first time.
Reply
#29
Code:
1234567891011121314151617181920212223242526272829303132333435363738394041
require('json') http = require('socket.http') escape = require('socket.url').escape key = 'xxxx' location = 'xxxx' url = 'http://api.weatherstack.com/current?access_key=%s&query=%s' url = string.format(url, key, escape(location)) res = http.request(url) data = json.pdecode(res) if type(data) ~= 'table' then   alert('no se pudieron cargar los datos del clima')   return end if data.error then   log('error', data.error)   return end current = data.current -- temperature grp.write('32/1/1', current.temperature) -- "feels like" temperature grp.write('32/1/2', current.feelslike) -- humidity as percentage grp.write('32/1/3', current.humidity) -- wind speed in kilometers per hour grp.write('32/1/4', current.wind_speed) -- uv index grp.write('32/1/5', current.uv_index) -- weather condition text grp.write('32/1/6', current.weather_descriptions[1]) -- pressure grp.write('32/1/7', current.pressure) -- precipitation amount grp.write('32/1/8', current.precip)

Hello, I don't know if this script is affected by the latest updates in LM.
Reply
#30
This script works fine in latest fw. You probably exceeded the free limit which is 250 calls a month.
------------------------------
Ctrl+F5
Reply
#31
Hello
Openweather one call, now only allows 1000 calls per day, until now I had it with a resident script that runs every minute, which gives a result of 1440 calls per day and therefore I exceed the current maximum.

The resident script does not support more than 60 seconds, how can I make the script run, for example every 2 minutes?
greeting
Reply
#32
Use a scheduled script instead or add os.sleep(60) to the resident script.
Reply
#33
Thanks, such a simple solution that never crossed my mind.

Greeting
Reply


Forum Jump: