09.11.2018, 09:46
If you want to query status periodically then things get more complicated. You need to have a single resident script which will handle both reading and writing because you cannot have multiple scripts accessing serial port at the same time.
You also need to parse the response because the reply will contain some additional characters.
This should log raw response of temperature value.
You also need to parse the response because the reply will contain some additional characters.
This should log raw response of temperature value.
Code:
function readack()
local line = {}
while true do
local char, err = port:read(1, 5)
if char == nil then
return nil, err
elseif char == ';' then
break
else
line[ #line + 1 ] = char
end
end
return table.concat(line)
end
port:write('get sauna val\r')
res, err = readack()
log(res, err)