Hello, iam implementing automated heating which would consider weather temperature forecast for heating. Unfortunatelly although everything works fine iam not able to get forecast from ope weather. Everything works when i send same request using browser but as soon as i send it through Lua. API returns 401 Invalid API key. See yourself:
local openWeatherAPIKey = "xyxyxy" -- You need to fill this out
function process_heating()
-- inside here i have implementation of heating itself, not interesting...
end
local location = api.get("/settings/location")
local lat = location.latitude or 0
local lon = location.longitude or 0
local locStr = "lat="..lat.."&lon="..lon
local opts = "&units=metric&cnt=1&appid="..openWeatherAPIKey
local fullRequestUrl = "http://api.openweathermap.org/data/2.5/forecast?"..locStr..opts
fibaro.debug("topeni", fullRequestUrl)
local http = net.HTTPClient()
http:request(fullRequestUrl, {
options = {
checkCertificate = false,
method = "GET",
timeout = 5000
},
success = function(res)
local openWeatherData = res.status == 200 and json.decode(res.data)
local max_temp = 0
if openWeatherData then
max_temp = openWeatherData.list[0].main.temp_max
fibaro.debug("topeni", "Today max temp: "..temp_max.."C")
elseif res.status == 401 then
local resp = json.decode(res.data)
fibaro.debug("topeni", "Unable to load weather data 401: "..resp.message)
fibaro.debug("topeni", fullRequestUrl)
else
fibaro.debug("topeni", "Unable to load weather data "..res.status)
end
process_heating(max_temp)
end,
error = function(res)
fibaro.debug("topeni", "Unable to load weather data: "..res)
process_heating(0)
end
})
Script outputs final request URL in case of failure to console. When i run this it fails, when i copy that final URL to web browser i get data as expected. Any idea what could be wrong?