19.02.2026, 11:37
I've a meter with a P1 port(=serial). To read the data is use this:
Code:
lastchar = '!'
require('serial')
port = serial.open('/dev/ttyUSB1', {
baudrate = 115200, --DSMR 2/3 = 9600 DSMR 4 = 115200
databits = 8, --DSMR 2/3 = 7 DSMR 4 = 8
stopbits = 1, --DSMR 2/3 = 1 DSMR 4 = 1
parity = 'none', --DSMR 2/3 = even DSMR 4 = none
duplex = 'full'
})
function readdata(port)
local char, buf
buf = {}
while true do
char = port:read(1)
-- error (timeout) or newline, stop
if char == nil or char == lastchar then
break
-- ignore cr char
elseif char ~= '\r' then
table.insert(buf, char)
end
end
return table.concat(buf)
end
data = readdata(port)
port:flush()
---------------------------------------------------------------
if data then
AphA = data:match'31.7.0%((%d+.%d+)'
AphA = tonumber(AphA)
grp.update('32/1/74', AphA)
-- "more code"
end