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.

check slave tcp/IP modbus device status
#1
Hello,

big thank for the script in this thread wich work for rtu and gateway check:

https://forum.logicmachine.net/showthrea...6#pid19306



I created another one for all of them:

Code:
function checkAllModbus(resultCheckTemp)
  local retour_modbus = ''
 
  local res = db:getall('SELECT name FROM modbus_devices WHERE active=?', 0)
  if res then
    for _, liste_modbus in ipairs(res) do
       local nomFamille = nomVersFamille(liste_modbus.name)
      retour_modbus=retour_modbus .. '[' ..nomFamille ..']'   
      end
  end
  --log( retour_modbus)
  return retour_modbus
end
-----------------




In order to see the active status !



It works, but my problem is that with tcp modbus (through a smartlink in tcp/ip modbus). When I setup a powertag for exemple, when the powertag is offline, we have error in modbus error table, but the device don't become inactive, it still active (I think because the smartlink still respond). You can easily test by putting a wrong slave adress ! My device still stay active !



So I can only easily have the smartlink defaut but not the slave device (powertag radio), or I need to put a script to check modbus table error (but my problem is that the customer want only one error (not every time the modbus error table display it). So for 150 device it's a little bit Power consumer...



do you have solution ?



Here screenshot:

[Image: attachment.php?aid=1903]   



Here the result:

[Image: attachment.php?aid=1904]   



edit: I don't put the right device on the last screenshot, but it the same for the 24





regards
-----------
FRANCE SMARTHOME & SMARTBUILDING INTEGRATION
SE ECO EXPERT
Reply
#2
This method won't work with TCP-RTU gateway. One solution is to check updatetime value of a linked object periodically and set status if it was not updated for a certain time.
Reply
#3
(23.11.2020, 08:08)admin Wrote: This method won't work with TCP-RTU gateway. One solution is to check updatetime value of a linked object periodically and set status if it was not updated for a certain time.

ok, cool it's a way I could do it !
Maybe, put a tag like 'towatch', and check difference betaween date now and uptime

Something like this:

obj1 = grp.find('x/x/x')
objError= grp.find('x/x/x')

now = os.time() -- current timestamp in seconds
delta1 = now - obj1.updatetime -- last object update relative time

if (delta1 > 240)  then
  objError:write(true)
end


DO you know why it's not implemented ? It works for rtu, and if the gateaway don't respond...


Thank you for helping
TIPS: https://forum.logicmachine.net/showthrea...updatetime
-----------
FRANCE SMARTHOME & SMARTBUILDING INTEGRATION
SE ECO EXPERT
Reply
#4
You should use checkwrite and also send false when there's no error. This will send true when delta is more than 4 minutes, false otherwise:
Code:
grp.checkwrite('1/1/1', delta1 > 240)

Status is not updated because there's a response from the gateway. "Illegal data address" is not a connection error. There's a special error code 11 (Gateway Target Device Failed to Respond) that should have been used for this.
Reply
#5
(23.11.2020, 08:35)admin Wrote: You should use checkwrite and also send false when there's no error. This will send true when delta is more than 4 minutes, false otherwise:
Code:
grp.checkwrite('1/1/1', delta1 > 240)

Status is not updated because there's a response from the gateway. "Illegal data address" is not a connection error. There's a special error code 11 (Gateway Target Device Failed to Respond) that should have been used for this.

ok understood !
Adding a column error in modbus_device or mapping could be a solution...


In my case, if I check every adress, it should be too much cpu load no ??
I was thinking to something like this:
What's your point ?

Code:
function checkSlaveTcpModbus(resultCheckTemp)
  local retour_modbus = ''
  local heartbeat_time = 5 -- Minutes
  local now = os.time() -- current timestamp in seconds
 
  local res = db:getall('SELECT name, updatetime FROM objects WHERE (address>?) AND (address<?)', 39999, 50000)

  if res then
    for _, liste_modbus in ipairs(res) do
      if (now - liste_modbus.updatetime) >= (heartbeat_time * 60) then
          retour_modbus=retour_modbus .. '[' ..liste_modbus.name ..']'
      end
      end
  end
  --log( retour_modbus)
  return retour_modbus
end
-----------
FRANCE SMARTHOME & SMARTBUILDING INTEGRATION
SE ECO EXPERT
Reply
#6
Are you sure you need to test a range of 10000 objects? One object per device is sufficient, no need to check all mapped objects for each device. Just make sure that the value is always updated in the specified period, otherwise you might get false error messages.
Reply
#7
Thank you for your help
-----------
FRANCE SMARTHOME & SMARTBUILDING INTEGRATION
SE ECO EXPERT
Reply


Forum Jump: