29.03.2019, 14:43
You are missing function return value assignment to a variable. And the modbus TCP connect part seems wrong there.
Code:
function checktcp(ip, port)
local settings, res
settings = tostring(ip) .. ':' .. tostring(port)
res = db:getone('SELECT active FROM modbus_devices WHERE proto="tcp" AND settings=?', settings)
return toboolean(res)
end
--Test the DB info of the modbus TCP
res = checktcp('192.168.0.10','502')
log(res)