02.08.2022, 16:26
(02.08.2022, 13:48)Daniel Wrote: See the point 4 again, You have to create objects in the sub group '2/1/' based on the instructions. If you want to use different one then change this in line 10.
Okay,
that's what I did.
1 - I have created 4-byte unsigned objects, "32/1/1, 32/1/2, 32/1/3, 32/1/4 ".
2 - Activated the script below
After that I got a value only on the first object 32/1/1 the other once doesn't update at all, and it looks like the 4 ids are writing their value on the 32/1/1
Code:
-- config init
if not meters then
require('mbus')
-- time to wait between each meter read
sleeptime = 10
mbus.init('/dev/RS232', 9600)
-- base address for meter values, meter short address will be added to form the meters group address
base = '32/1/'
-- meter definition
-- addr - short address
-- id - number from data table where value resides
-- div - optional divisor for convertion to the final value
meters = {
{ addr = 1, id = 6},
{ addr = 1, id = 7},
{ addr = 1, id = 8},
{ addr = 1, id = 9},
}
-- reset meter values on first run
for _, meter in ipairs(meters) do
meter.value = 0
end
end
-- read each meter
for _, meter in ipairs(meters) do
res = mbus.getdata(meter.addr)
-- read ok
if type(res) == 'table' then
data = res.data[ meter.id ]
value = nil
-- get current value
if type(data) == 'table' then
value = tonumber(data.value)
end
-- value is valid and different from previous read
if value and meter.value ~= value then
-- apply divisor if set
div = meter.div
dpt = div and dt.float32 or dt.uint32
if div then
value = value / div
end
-- update group address value
grp.update(base .. tostring(meter.addr), value, dpt)
meter.value = value
end
end
-- wait for next read
os.sleep(sleeptime)
end