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.

Resident script - IP watchdog
#1
Hi, 
I need a resident script that ping an IP , and if does not receive any reply to open a actuator.
Please help  Idea
Thanks a lot!
Reply
#2
(09.10.2017, 14:06)sorin Wrote: Hi, 
I need a resident script that ping an IP , and if does not receive any reply to open a actuator.
Please help  Idea
Thanks a lot!

Here you are:

Code:
function socketping(ip, port, timeout)
 port = port or 80
 local sock = require('socket').tcp()
 sock:settimeout(timeout or 2)
 local res, err = sock:connect(ip, port)
 sock:close()
 
 return res, err
end


ip = '192.168.2.1'

if not socketping(ip) then grp.write('1/2/3', true) end
Reply
#3
Thanks for quick reply.
I'll check  and come back with a feedback.
Reply
#4
Hi

I have tried using this script to ping an Iphone but I always get back the same result regardless of it's presence in the network or not. The Iphone have a static IP.

Any  ideas?

/K
Reply
#5
(17.12.2017, 08:08)kenjirosama Wrote: Hi

I have tried using this script to ping an Iphone but I always get back the same result regardless of it's presence in the network or not. The Iphone have a static IP.

Any  ideas?

/K

Hi, The script is good, working.
Here mine looks:
Code:
function socketping(ip, port, timeout)
 port = 80
 local sock = require('socket').tcp()
 sock:settimeout(2)
 local res, err = sock:connect(ip, port)
 sock:close()
 
 return res, err
end


ip1 = '192.168.10.151'
ip2 = '192.168.10.152'
ip3 = '192.168.10.153'
ip4 = '192.168.10.154'
ip5 = '192.168.10.155'
ip6 = '192.168.10.156'
ip7 = '192.168.10.157'

if not socketping(ip1) then grp.write('10/5/1', true)
end
if not socketping(ip2) then grp.write('10/5/2', true)
end
if not socketping(ip3) then grp.write('10/5/3', true)
end
if not socketping(ip4) then grp.write('10/5/4', true)
end
if not socketping(ip5) then grp.write('10/5/5', true)
end
if not socketping(ip6) then grp.write('10/5/6', true)
end
if not socketping(ip7) then grp.write('10/5/7', true)
end

I have an IPAD an I have tried to ping from windows. If it is looked, doesn't reply to ping, if I unlocked start to reply.
Maybe it is a issue of replying to ping of the Iphone.
Reply
#6
Hi,

This will never work as the iOS device is not reachable when lock is enabled, also for power saving the wifi is not always available. 

There is a script from admin on this forum that seeks the iOS devices by multiple trigger on a port, but this script is also facing issues with unreachable state of iOS devices.

Maybe IFTTT with geofencing can give you more trustfull input for your task..

BR,

Erwin
Reply
#7
Hi,
I use LM as supervisor for a Wago PLC in modbus TCP-IP.
I would like to establish a modbus watchdog connection as security. From LM side what do you suggest?
Thanks
Reply
#8
You can use socketping function but with port set to 502 (default ModBus TCP port):
Code:
function socketping(ip, port, timeout)
  port = port or 80
  local sock = require('socket').tcp()
  sock:settimeout(timeout or 2)
  local res, err = sock:connect(ip, port)
  sock:close()
  
  return res, err
end

ip = '192.168.10.150'
if not socketping(ip, 502) then
  alert('device is offline')
end
Reply
#9
Hi. Nice feature. Works perfect as always.
Is it possible to make the same watchdog for RTU modbus connection?
Reply
#10
It can also be checked like this
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
------------------------------
Ctrl+F5
Reply
#11
I have two json modbus profiles on a LM5 lite. One rtu 9600 baud and one tcp. Tcp working great but rtu sometimes failing. (Red in modbus window)
I am using pts cable. About 30 meters.
Has the LM built in eol resistors?
Will try to put in this tommorow and not sure if i have to have in both ends.
Does the new rc of firmware have improvements in modbus rtu?

And the scripts above to check TCP and RTU status. Can they make the RTU connection go bad.
Reply
#12
My script is just checking internal LM state of connection, when it becomes red. Do you have any errors in modbus tab?
GND connected?
------------------------------
Ctrl+F5
Reply
#13
Yes. I have error/red color in modbus tab from time to tine. But not sure why. I think it is better when the script is not running but only had a day to test.
Gnd connected. But slow connection with modbus40 from nibe. 3 sek read delay and 3 sek timeout in script

Should I have a resistor at the eol with the equipment and by the LM? Or just in end?

I can see that the error reason is operation timed out and there have been no change when disabling script.
Reply
#14
Do you have a script running together with the mapper sharing the same RS485 port? This will cause a lot of errors. If you want to use script then you should switch to modbus proxy: https://forum.logicmachine.net/showthrea...53#pid1953

Which LM model do you have? Some of them have EOL on-board though it's higher than 120ohm. EOL should be placed on both line ends.
Reply
#15
Lm5 lite

No script. I had the ip ping from the posts on this page pinging ip modbut earlier but no difference in disabling it

Lm5Lp2
Should i use resistors in both ends or just at the slave?
Reply
#16
LM5 don't have EOL resistors, so you need to put 120ohm at both ends of your RS485 line. Do you have GND connected between LM and slave device?
Reply
#17
Ok. Then I will connect the 150 ohm resistors at both ends.
The gnd is connected at both ends. To increase mm2 i doubled the pair. Is this ok? I thought it didnt go any data on this? Or can that make problem?
Reply


Forum Jump: