LogicMachine Forum
Tulikivi sauna heater relay board - Printable Version

+- LogicMachine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Tulikivi sauna heater relay board (/showthread.php?tid=3417)



Tulikivi sauna heater relay board - MikeBrignate - 10.06.2021

Hello

Could somebody help me with Tulikivi relay board for the sauna heater, trying to read sauna temperature with CMD 11, but the result always 0. When I connecting my touch panel, then pannel starts asking for data from the relay board and a log is showing some values. So the connection is established, but the request is wrong.
Code:
require('serial') port, err = serial.open('/dev/RS485', {   baudrate = 9600,   databits = 8,   stopbits = 1,   parity = 'none',   duplex = 'half' }) port:flush() port:write(0xB) data = port:read(2,3) byte = string.byte(data) log(string.format("%o, %x, %d", byte,byte,byte)) port:close()

protocol attached

Thank you


RE: Tulikivi sauna heater relay board - admin - 11.06.2021

Try this:
Code:
require('serial') port, err = serial.open('/dev/RS485', {   baudrate = 9600,   databits = 8,   stopbits = 1,   parity = 'none',   duplex = 'half' }) function send(cmd, data)   local msg, res, err, b1, b2   data = data or 0   msg = string.char(     bit.band(cmd, 0xFF),     bit.band(bit.rshift(data, 8), 0xFF),     bit.band(data, 0xFF)   )   port:flush()   port:write(msg)   res, err = port:read(2, 3)   if type(res) == 'string' then     if #res == 2 then       b1, b2 = res:byte(1, 2)       return bit.bor(bit.lshift(b1, 8), b2)     else       return nil, 'invalid reply'     end   else     return nil, err   end end -- turn on res, err = send(1, 1) log(res, err) -- turn off res, err = send(1, 0) log(res, err) -- read current temperature res, err = send(15) log(res, err)