13.09.2019, 16:34
Hello
I have changed the scrip as it has told me and now in registers I have no error but in registration error I have this message:
User script:15: attempt to index global 'http' (a nil value)
stack traceback:
User script:15: in main chunk
Could you help me since it is a scrip that I need in several machines.
Thank you
*********************************************************************************************************
-- https://www.apixu.com/
require('json')
https = require('ssl.https')
escape = require('socket.url').escape
key = 'My_Api_Key' --API KEY despues de realizar el registro
location = 'Alcobendas' -- lugar de clima
url = 'http://api.apixu.com/v1/forecast.json?key=%s&q=%s&days=2'
url = string.format(url, key, escape(location))
res = http.request(url)
data = json.pdecode(res)
if type(data) ~= 'table' then
alert('failed to load weather data')
log('failed to load weather data')
return
end
if data.error then
log('error', data.error)
return
end
current = data.current
today = data.forecast.forecastday[ 1 ].day
tomorrow = data.forecast.forecastday[ 2 ].day
--INFO UTILIZADA
-- temperature in C
grp.write('15/1/2', current.temp_c)
-- weather condition text
grp.write('15/1/1', current.condition.text)
-- minimum temperature in celsius for the day
grp.write('15/1/4', today.mintemp_c)
-- maximum temperature in celsius for the day
grp.write('15/1/5', today.maxtemp_c)
-- weather condition text
grp.write('15/1/3', today.condition.text)
-- maximum temperature in celsius for the day
grp.write('15/1/8', tomorrow.maxtemp_c)
-- weather condition text
grp.write('15/1/6', tomorrow.condition.text)
-- minimum temperature in celsius for the day
grp.write('15/1/7', tomorrow.mintemp_c)
-- "feels like" temperature in C
grp.write('15/1/9', current.feelslike_c)
-- humidity as percentage
grp.write('15/1/12', current.humidity)
-- wind speed in kilometers per hour
grp.write('15/1/11', current.wind_kph)
-- uv index
grp.write('15/1/15', current.uv)
-- pressure in millibars
grp.write('15/1/14', current.pressure_mb)
-- "wind_dir"
grp.write('15/1/10', current.wind_dir)
-- "sunrise"
I have changed the scrip as it has told me and now in registers I have no error but in registration error I have this message:
User script:15: attempt to index global 'http' (a nil value)
stack traceback:
User script:15: in main chunk
Could you help me since it is a scrip that I need in several machines.
Thank you
*********************************************************************************************************
-- https://www.apixu.com/
require('json')
https = require('ssl.https')
escape = require('socket.url').escape
key = 'My_Api_Key' --API KEY despues de realizar el registro
location = 'Alcobendas' -- lugar de clima
url = 'http://api.apixu.com/v1/forecast.json?key=%s&q=%s&days=2'
url = string.format(url, key, escape(location))
res = http.request(url)
data = json.pdecode(res)
if type(data) ~= 'table' then
alert('failed to load weather data')
log('failed to load weather data')
return
end
if data.error then
log('error', data.error)
return
end
current = data.current
today = data.forecast.forecastday[ 1 ].day
tomorrow = data.forecast.forecastday[ 2 ].day
--INFO UTILIZADA
-- temperature in C
grp.write('15/1/2', current.temp_c)
-- weather condition text
grp.write('15/1/1', current.condition.text)
-- minimum temperature in celsius for the day
grp.write('15/1/4', today.mintemp_c)
-- maximum temperature in celsius for the day
grp.write('15/1/5', today.maxtemp_c)
-- weather condition text
grp.write('15/1/3', today.condition.text)
-- maximum temperature in celsius for the day
grp.write('15/1/8', tomorrow.maxtemp_c)
-- weather condition text
grp.write('15/1/6', tomorrow.condition.text)
-- minimum temperature in celsius for the day
grp.write('15/1/7', tomorrow.mintemp_c)
-- "feels like" temperature in C
grp.write('15/1/9', current.feelslike_c)
-- humidity as percentage
grp.write('15/1/12', current.humidity)
-- wind speed in kilometers per hour
grp.write('15/1/11', current.wind_kph)
-- uv index
grp.write('15/1/15', current.uv)
-- pressure in millibars
grp.write('15/1/14', current.pressure_mb)
-- "wind_dir"
grp.write('15/1/10', current.wind_dir)
-- "sunrise"