Hi
I have a problem to understand why my lua-code not working as i expected.
See first this (properly working) test-lua-scene and the debug-result:
--[[
%% properties
%% globals
--]]
globalmessage = " "
--
function funcSections()
local typename = "Sections"
fibaro:debug(globalmessage .. typename)
end;
function funcRooms()
local typename = "Rooms"
fibaro:debug(globalmessage .. typename)
end;
function funcDevices()
local typename = "Devices"
fibaro:debug(globalmessage .. typename)
end;
--
fibaro:debug("before call function funcDevices--------------------")
globalmessage = "Now call function funcDevices: "
funcDevices();
--
fibaro:debug("before call function funcSections-------------------")
globalmessage = "Now call function funcSections: "
funcSections();
--
fibaro:debug("before call function funcRooms----------------------")
globalmessage = "Now call function funcRooms: "
funcRooms();
As expected first was the function "funcDevices" performed.
Second the function "funcSections".
And then at last the function "funcRooms".
And now for my scene, which does not work as expected (code and result):
--[[
%% properties
%% globals
--]]
globalmessage = " "
doneanswer = " "
selHelpDRS = "{"
Dm, Rm, Sm = 0, 0, 0;
function funcDevices()
local typename = "Devices"
fibaro:debug(globalmessage .. typename)
local http = net.HTTPClient()
local urlIPP = 'http://127.0.0.1:11111'
local urlAPI = '/api/devices'
http:request(urlIPP..urlAPI, {
options = { method = 'GET' },
success = function(jsonraw)
local jssonrawlen = string.len(jsonraw.data)
local jsontab = json.decode(jsonraw.data)
local i1 = 0
local i1m = 0
selHelpDRS = selHelpDRS .. 'D:{'
for k,v in pairs(jsontab) do i1m = i1m + 1 end
for i1 = 1, i1m do
local id = tonumber(jsontab[i1].id)
local roomID = tonumber(jsontab[i1].roomID)
local saveLogs = tostring(jsontab[i1].properties.saveLogs) or nil
if ( roomID > 0 ) then
if ( saveLogs == "true" ) then
Dm = Dm + 1
if Dm > 1 then
selHelpDRS = selHelpDRS .. ','
end
selHelpDRS = selHelpDRS .. Dm ..':'.. jsontab[i1].id
end
end
end
selHelpDRS = selHelpDRS .. '}'
fibaro:debug("selHelpDRS=" .. selHelpDRS)
fibaro:setGlobal("selHelpDRS", selHelpDRS)
end,
error = function(errorcode) fibaro:debug("error=" .. errorcode) end})
http = nil
doneanswer = "yes"
end;
function funcRooms()
local typename = "Rooms"
fibaro:debug(globalmessage .. typename)
local http = net.HTTPClient()
local urlIPP = 'http://127.0.0.1:11111'
local urlAPI = '/api/rooms'
http:request(urlIPP..urlAPI, {
options = { method = 'GET' },
success = function(jsonraw2)
local jssonraw2len = string.len(jsonraw2.data)
local jsontab = json.decode(jsonraw2.data)
local i1 = 0
local i1m = 0
selHelpDRS = selHelpDRS .. ',R:{'
for k,v in pairs(jsontab) do i1m = i1m + 1 end
for i1 = 1, i1m do
local id = tonumber(jsontab[i1].id)
if ( id > 0 ) then
Rm = Rm + 1
if Rm > 1 then
selHelpDRS = selHelpDRS .. ','
end
selHelpDRS = selHelpDRS .. Rm ..':'.. jsontab[i1].id
end
end
selHelpDRS = selHelpDRS .. '}'
fibaro:debug("selHelpDRS=" .. selHelpDRS)
fibaro:setGlobal("selHelpDRS", selHelpDRS)
end,
error = function(errorcode) fibaro:debug("error=" .. errorcode) end})
http = nil
doneanswer = "yes"
end;
function funcSections()
local typename = "Sections"
fibaro:debug(globalmessage .. typename)
local http = net.HTTPClient()
local urlIPP = 'http://127.0.0.1:11111'
local urlAPI = '/api/sections'
http:request(urlIPP..urlAPI, {
options = { method = 'GET' },
success = function(jsonraw3)
local jssonraw3len = string.len(jsonraw3.data)
local jsontab = json.decode(jsonraw3.data)
local i1 = 0
local i1m = 0
selHelpDRS = selHelpDRS .. ',S:{'
for k,v in pairs(jsontab) do i1m = i1m + 1 end
for i1 = 1, i1m do
local id = tonumber(jsontab[i1].id)
if ( id > 0 ) then
Sm = Sm + 1
if Sm > 1 then
selHelpDRS = selHelpDRS .. ','
end
selHelpDRS = selHelpDRS .. Sm ..':'.. jsontab[i1].id
end
end
selHelpDRS = selHelpDRS .. '}'
fibaro:debug("selHelpDRS=" .. selHelpDRS)
fibaro:setGlobal("selHelpDRS", selHelpDRS)
end,
error = function(errorcode) fibaro:debug("error=" .. errorcode) end})
http = nil
doneanswer = "yes"
end;
--
fibaro:debug("before call function funcDevices--------------------")
globalmessage = "Now call function funcDevices: "
doneanswer = "no"
funcDevices()
repeat
fibaro:sleep(100)
until doneanswer == "yes"
;
--
fibaro:debug("before call function funcRooms----------------------")
globalmessage = "Now call function funcRooms: "
doneanswer = "no"
funcRooms()
repeat
fibaro:sleep(100)
until doneanswer == "yes"
;
--
fibaro:debug("before call function funcSections-------------------")
globalmessage = "Now call function funcSections: "
doneanswer = "no"
funcSections()
repeat
fibaro:sleep(100)
until doneanswer == "yes"
;
See the order of statements in the program. I would expected, first the function "funcDevices" was performed. Then, the second function "funcRooms" is performed. And last the function "funcSections".
[DEBUG] 12:20:50: before call function funcDevices--------------------
In principle, the program is working properly. But the wrong order in run the functions de facto can not be explained to me:
Order of call's: D R S = direction de facto: S R D
Order of call's: R S D = direction de facto: S R D
Order of call's: R D S = direction de facto: R S D
Order of call's: S R D = direction de facto: S R D
Here's someone who can tell me why my desired order is not complied with by the Fibaro-LUA-system? What should I do to make it work the way I want it?