08.05.2024, 20:56
(This post was last modified: 08.05.2024, 21:00 by manos@dynamitec.)
(08.05.2024, 13:50)admin Wrote: Using bacnet.scandevice() can be more convenient for reading many objects at once.
Code:require('bacnet')
device, objects = bacnet.scandevice(1)
for _, obj in ipairs(objects) do
if obj.type == 'analog input' then
name = obj.description
value = tonumber(obj['present-value'])
grp.checkupdate(name, value)
os.sleep(0.1)
end
end
This script can be modified to create objects automatically using grp.create(). But if you need different data types you will need some extra logic to guess the data type from the name (description).
Thank you Admin. Always glad to have you around for support.
Here the final script which worked nicely. I didn't mind to set datapoints for the temperature objects later manualy using mass edit as this was very easy.
in this script the part which creates the group addresses is commented because we only need this to run one time.
Code:
require('bacnet')
--HVAC BACnet Server Name:AS219, IP: xxx.xxx.xxx.xxx, Device ID:1
device, objects = bacnet.scandevice(1)
for _, obj in ipairs(objects) do
if obj.type == 'analog input' then
index = obj.id
name = obj.description
value = tonumber(obj['present-value'])
--Automaticaly create group addresses based on name and index
--[[
grp.create({name = name, address = '23/0/' .. index, datatype = dt.int32})
]]--
grp.checkwrite(name, value)
os.sleep(0.5)
end
end