Script variable - call external lua function with curl

Post Reply
vladacz
Posts: 2
Joined: Sunday 03 June 2018 10:58
Target OS: Raspberry Pi
Domoticz version:
Contact:

Script variable - call external lua function with curl

Post by vladacz » Sunday 03 June 2018 11:22

Hi, I need help, so far I dont know how solve following problem. In script_variable_xxx I call external function, which process data history from counter meter. In this function I use curl function which return result back to script_variable_xxx. But result, which return is still empty. I try call the same function from script_time and result is correct, curl process all history data correctly. But calling from script_variable curl in external function every time return empty result.

curl in externa function:

local config=assert(io.popen('curl --connect-timeout 2 -m 2 -X GET "http://' .. IP_ADDRESS .. '/json.htm?type=graph&sensor=counter&idx=5&range=month"'))

vladacz
Posts: 2
Joined: Sunday 03 June 2018 10:58
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Script variable - call external lua function with curl

Post by vladacz » Monday 04 June 2018 17:33

Script_variable_xxx.lua:
----------------------------
commandArray = {}
ENERGY = (loadfile "/home/pi/domoticz/scripts/lua/energyAPI.lua")()

if ((uservariablechanged['request'] ~= nil)) then
-- call functuin from file energyAPI.lua
result = getEnergyMonth(IDX_COUNTER,month)
end
return commandArray

energyAPI.lua:
------------------------
commandArray = {}
function getEnergyMonth(idx,month)
JSON = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()
local config=assert(io.popen('curl --connect-timeout 2 -m 2 -X GET "http://' .. IP_ADDRESS .. '/json.htm?type=graph&sensor=counter&idx=' .. idx .. '&range=month"'))
local jsonResponse = config:read('*all')
config:close()

local r = JSON:decode(jsonResponse)

....

return energyMonth
end
return commandArray

When I call function getEnergy(a,b) from script_variable, return nil value, when I call the same function for example from script_time, return correct json result.

Post Reply

Who is online

Users browsing this forum: axelbaas and 5 guests