This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Integrate Noark 1F electricity meter and write to M-Bus to change tariff
#2
Try this, make sure that only one script is accessing the serial port at any time moment.
Code:
require('serial')

port, err = serial.open('/dev/RS232', {
  baudrate = 9600,
  parity = 'even',
  duplex = 'full',
})

port:flush()

addr = 0x01 -- short address
tariff = 0x02 -- selected tariff

data = { 0x53, addr, 0x51, 0x09, 0x7C, 0x01, 0x54, tariff }

len = #data

buf = { 0x68, len, len, 0x68 }
cs = 0

for _, char in ipairs(data) do
  buf[ #buf + 1 ] = char
  cs = cs + char
end

buf[ #buf + 1 ] = bit.band(cs, 0xFF)
buf[ #buf + 1 ] = 0x16

data = string.char(unpack(buf))

port:write(data)

res = port:read(1, 0.5)

if res then
  if res:byte(1) == 0xE5 then
    log('write ok')
  else
    log('reply error')
  end
else
  log('no reply')
end

port:close()
Reply


Messages In This Thread
RE: Integrate Noark 1F electricity meter and write to M-Bus to change tariff - by admin - 18.10.2023, 07:05

Forum Jump: