20.10.2022, 22:46
I have a function called "commpnPost()" in a common script as below.
I call this function everytime when there's a change in each KNX status object, so that I can let other servers know that there's a status change in the KNX project.
I call it in each event script as the image below. ('9/2/1' is the group address of the status object)
However, when I log the output inside the common script, I can see the first argument '9/2/1' somehow changed to '10/4/5'.
I also made sure that it already changed to '10/4/5' at the first line of the commonPost function.
This happens with other group addresses too.
Am I using common script in a wrong way ? Or maybe there is a chace that I need to clear inside LM ?
I call this function everytime when there's a change in each KNX status object, so that I can let other servers know that there's a status change in the KNX project.
I call it in each event script as the image below. ('9/2/1' is the group address of the status object)
However, when I log the output inside the common script, I can see the first argument '9/2/1' somehow changed to '10/4/5'.
I also made sure that it already changed to '10/4/5' at the first line of the commonPost function.
This happens with other group addresses too.
Am I using common script in a wrong way ? Or maybe there is a chace that I need to clear inside LM ?
Code:
function commonPost(add, value)
local dptString = convertToDptString(add)
local payload = ""
if dptString == "dtDate" then
payload = '{"groupAddress": "' ..add..'","value": {"dtDate": { "year":' ..tostring(value["year"]).. ', "month": '..tostring(value["month"]).. ', "day": '..tostring(value["day"]).. '}}}'
elseif dptString == "dtTime" then
payload = '{"groupAddress": "' ..add..'","value": {"dtTime": { "hour":' ..tostring(value["hour"]).. ', "minute": '..tostring(value["minute"]).. ', "second": '..tostring(value["second"]).. '}}}'
else
payload = '{"groupAddress": "' ..add..'","value": {"'..dptString.. '": ' ..tostring(value).. '}}'
end
log('payload: ', payload)
--**post the payload to a speficic REST endpoint **
end
Code:
function convertToDptString(address)
mapping = {}
for key, value in pairs(dt) do
mapping[ value ] = 'dt' .. string.upper(string.sub(key, 1, 1)) .. string.sub(key, 2)
end
obj = grp.find(address)
dpt = obj.datatype
if dpt then
dtname = mapping[ dpt ]
if not dtname and dpt >= 1000 then
dtname = mapping[ math.floor(dpt / 1000) ]
end
end
return dtname
end