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.

Tulikivi sauna heater relay board
#1
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

Attached Files
.pdf   softa mat.pdf (Size: 91.39 KB / Downloads: 10)
Reply
#2
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)
Reply


Forum Jump: