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.

Modbus diconnection (read failed)
#1
Hello,
I would like to send an email when there is a modbus disconnection for 30 minutes, the fact that there is random disconnection any time makes that the sending of the mail can occur while the modbus still works . I wish I could have a return of this defect but if it is continual during 30 minutes ... is it possible?
B. R.



Current Script : 

require('luamodbus')
mb = luamodbus.tcp()

-- IP: xxx.xxx.xxx.xxx, port: 502
mb:open('xxx.xxx.xxx.xxx', 502)
mb:connect()

conectMB = mb:readregisters(5)

mb:close()

-- CREATION DES SUJET ET MESSAGE POUR MAIL

subject = 'subject'
message = 'message'

subject1 = 'subject1'
message1 = 'message1'

-- ENVOI DU MAIL SI ALARME VRAI

defaut_conectMB = storage.get('defaut_conectMB', false)

if conectMB == nil then
  if not defaut_conectMB then
    mail('@', subject, message)
    storage.set('defaut_conectMB', true)
  end
else
  if defaut_conectMB then
    mail('@', subject1, message1)
    storage.set('defaut_conectMB', false)
  end
end
Reply
#2
Hi
If you use profile here is how to check status of modbus device

Code:
function checkrtu(slave)
local res = db:getone('SELECT active FROM modbus_devices WHERE proto="rtu" AND slave=?', slave)
return toboolean(res)
end

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
BR
------------------------------
Ctrl+F5
Reply
#3
(01.02.2019, 09:48)Daniel. Wrote: Hi
If you use profile here is how to check status of modbus device

Code:
function checkrtu(slave)
local res = db:getone('SELECT active FROM modbus_devices WHERE proto="rtu" AND slave=?', slave)
return toboolean(res)
end

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
BR

Thanks Daniel !
Reply


Forum Jump: