19.04.2021, 10:23
Post full script code
Openweather api
|
19.04.2021, 10:23
Post full script code
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)
19.04.2021, 10:33
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
Thanks for your quick response.
Isn't the return on line 29 enough?
19.04.2021, 10:41
No because it belongs to a different if branch. return should be placed after each alert in your code.
19.04.2021, 10:47
The point is that this part of the code works, after removing a letter from the token and the corresponding text appears in alerts.
19.04.2021, 10:53
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
19.04.2021, 11:04
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
21.07.2021, 10:34
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.
21.07.2021, 10:51
This script works fine in latest fw. You probably exceeded the free limit which is 250 calls a month.
------------------------------
Ctrl+F5
30.08.2022, 10:28
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
30.08.2022, 10:29
Use a scheduled script instead or add os.sleep(60) to the resident script.
08.09.2022, 09:47
Thanks, such a simple solution that never crossed my mind.
Greeting |
« Next Oldest | Next Newest »
|