Author Topic: Ping Sensor  (Read 188825 times)

Offline Mike Yeager

  • Hero Member
  • *****
  • Posts: 522
  • Karma: +6/-12
Re: Ping Sensor
« Reply #585 on: April 30, 2017, 11:36:02 am »
Under the advanced settings, set the period variable for the frequency of polling and the allowed failure variable for number of negative polls before untripping. I'm working towards a wasp in the box type setup but I've still got work to do.  :)

Offline MNB

  • Hero Member
  • *****
  • Posts: 689
  • Karma: +4/-9
Re: Ping Sensor
« Reply #586 on: April 30, 2017, 02:17:16 pm »
@Mike Yeager, thanxs for advice, I see that when you enter the number of "AllowedFailure" that it basically multiplies the "Poll Number" value which works for me in other words if your polling your device every 60 sec and enter 2 in the "AllowedFailure" the value that gets populated in "Device Timeout" = 120 (60 sec x 2).
Edge-1.7.2607, VRI06-1LX Dimr (6), VS05-1LX Sw (4), GE ZW3002 Dimr (1), HA01C Outlet (12), HA02C Sw (6), HA04C Sw (4), GE Sw (2), HA05 Sw (3), MiniMote Contr (5), HSM200/100 Sensor (2), ZW100A Sensor (8), Nest thermostat (1) & Protect Fire/CO (6) Kwikset Locks (3), F18918W (1) & IP3M-9 (6) Cam's

Offline ojovilla

  • Sr. Newbie
  • *
  • Posts: 37
  • Karma: +0/-0
Re: Ping Sensor
« Reply #587 on: May 01, 2017, 12:32:35 pm »
You add multiple ping sensors....   :)

 :-\ hmm, forgive me if I am lost , but how exactly do you accomplish this? I do not see any such options, and don't know how to do this . These are the only options I have , but I have seen different screen shots on this forums, do I have a wrong version installed ?


Offline MNB

  • Hero Member
  • *****
  • Posts: 689
  • Karma: +4/-9
Re: Ping Sensor
« Reply #588 on: May 01, 2017, 07:26:07 pm »
@ojovilla you need to go to the advance>Parms tabs there you will be presented with the variables.
Edge-1.7.2607, VRI06-1LX Dimr (6), VS05-1LX Sw (4), GE ZW3002 Dimr (1), HA01C Outlet (12), HA02C Sw (6), HA04C Sw (4), GE Sw (2), HA05 Sw (3), MiniMote Contr (5), HSM200/100 Sensor (2), ZW100A Sensor (8), Nest thermostat (1) & Protect Fire/CO (6) Kwikset Locks (3), F18918W (1) & IP3M-9 (6) Cam's

Offline Mike Yeager

  • Hero Member
  • *****
  • Posts: 522
  • Karma: +6/-12
Re: Ping Sensor
« Reply #589 on: May 01, 2017, 10:04:28 pm »
If you're trying to add another ping sensor, go back to the APPS tab, select the ping sensor plugin and add another instance from there. You don't add another instance from the sensor itself. Sorry if this seems vague, it's been a very long day...

Offline ojovilla

  • Sr. Newbie
  • *
  • Posts: 37
  • Karma: +0/-0
Re: Ping Sensor
« Reply #590 on: May 01, 2017, 11:57:11 pm »
If you're trying to add another ping sensor, go back to the APPS tab, select the ping sensor plugin and add another instance from there. You don't add another instance from the sensor itself. Sorry if this seems vague, it's been a very long day...

Got it! thanks, way more helpful than your last post  :)

Offline Mike Yeager

  • Hero Member
  • *****
  • Posts: 522
  • Karma: +6/-12
Re: Ping Sensor
« Reply #591 on: May 02, 2017, 07:12:34 pm »
Well, I didn't realize you needed to know how to do it, just what to do. :)

Offline twiseva

  • Sr. Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Re: Ping Sensor
« Reply #592 on: May 04, 2017, 07:00:26 pm »
@twiseva, were you successful in getting ping to work for you? I am trying to do something similar with my iPhone but I also seem to be getting erratic results, of those of you who have gotten your ping sensor to work, can you provide what you've solution was e.g. Poll Period and Device Timeout settings are you using virtual switches and are you using PLEG conditions and/or device to monitor. Also for slow witted I'm assuming that a tripped sensor (red running man) = successful IP address pinged. Mike

No, no luck -- I am going to try and debug this some more this upcoming weekend. Not had much time recently. I am also using PLEG to set a virtual switch to avoid the sleep issue. However, the pings is not working right so that's kinda useless right now.

Offline Mike Yeager

  • Hero Member
  • *****
  • Posts: 522
  • Karma: +6/-12
Re: Ping Sensor
« Reply #593 on: May 05, 2017, 09:12:14 pm »
The iPhone has it's own issue with pinging. There are threads here concerning that. Android has a setting that you have to change to prevent wifi sleep, but it doesn't always work as expected either. I'm still tweaking a "wasp in the box" setup to address this, but I haven't worked on it much lately... Too busy with other things...

Offline twiseva

  • Sr. Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Re: Ping Sensor
« Reply #594 on: May 05, 2017, 10:32:35 pm »
@twiseva, were you successful in getting ping to work for you? I am trying to do something similar with my iPhone but I also seem to be getting erratic results, of those of you who have gotten your ping sensor to work, can you provide what you've solution was e.g. Poll Period and Device Timeout settings are you using virtual switches and are you using PLEG conditions and/or device to monitor. Also for slow witted I'm assuming that a tripped sensor (red running man) = successful IP address pinged. Mike

No, no luck -- I am going to try and debug this some more this upcoming weekend. Not had much time recently. I am also using PLEG to set a virtual switch to avoid the sleep issue. However, the pings is not working right so that's kinda useless right now.

So a little more information -- but no solution yet :-(

I basically wrote some LUA code to do the ping thinking that the plugin was buggy. Kicked it off every 30 sec (via a timed scene) or so and it seemed to work well. However, after some time (say 10 or so calls - it varies), the LUA call os.execute started returning -1 and never went back to normal. This command lets you do a 'ping' on the Vera box.  Initially it returns 0 for a SUCCESS and 256 for a FAILURE. A -1 seems to indicate a failure of the os.execute call itself.

I did this in the Vera scenes and also within PLEG -- both had the same issue. This is the behavior I saw with the plugin -- works for a while, then stops. If it is using os.execute I could see it having the same issues.

Now I did in in a command line LUA script on the Vera itself and all was fine and ran as expected for a long period of time. So no issues outside of Vera executable.

Also a LUA Restart fixes it for a while -- again a behavior I saw in the plugin.

All leads me to believe there is some issue within Vera running the os.execute command repeatedly (I tried using 'ls' as the command and there was the same issue). Possibly some resource limitation or exhaustion? Not really sure -- I tried to look at verbose logging and it didn't help. I am wondering about file descriptor limits maybe ... ??

@MNB -- Are you using a VeraLite by any chance?

Anyone have any thoughts or ideas -- either what the issue is or another approach for getting ping to work?

For kicks here is the code I am running (Yes I am no Lua expert for sure :-)):

--------------

pingRtn=os.execute("ping -c 1 -w 1 192.168.2.110")
luup.log ("VIRTUALPING DEBUG: Ping OS cmd: " .. pingCmd .. ", return value is: " .. pingRtn)

-- OS returns a zero on success. Non-zero on other scenarios
if pingRtn == 0 then
   -- Set virtual switch to 'ON'
   luup.log ("VIRTUALPING DEBUG: Ping SUCCESSFUL for IP: " .. targetIP)
   setTargetRtn=luup.call_action("urn:upnp-org:serviceId:VSwitch1", "SetTarget", {newTargetValue = "1"}, targetVirtalSwitch)
   pingSuccess = true
else
   -- Set virtual switch to 'OFF'
   setTargetRtn=luup.call_action("urn:upnp-org:serviceId:VSwitch1", "SetTarget", {newTargetValue = "0"}, targetVirtalSwitch)
   luup.log ("VIRTUALPING DEBUG: Ping FAILED for IP: " .. targetIP)
   pingSuccess = false
end

return (pingSuccess)

-----------

And These are the logs I see:

<Snip> About 10 or so good PINGS prior to these.

50      05/05/17 22:16:21.206   luup_log:132: VIRTUALPING DEBUG: Ping FAILED for IP: 192.168.2.110 <0x2ac92310>
50      05/05/17 22:16:31.264   luup_log:132: VIRTUALPING DEBUG: Ping OS cmd: ping -c 1 -w 1 192.168.2.110, return value is: 0 <0x2ac92310>
50      05/05/17 22:16:31.265   luup_log:132: VIRTUALPING DEBUG: Ping SUCCESSFUL for IP: 192.168.2.110 <0x2ac92310>
50      05/05/17 22:16:42.199   luup_log:132: VIRTUALPING DEBUG: Ping OS cmd: ping -c 1 -w 1 192.168.2.110, return value is: 256 <0x2ac92310>
50      05/05/17 22:16:42.283   luup_log:132: VIRTUALPING DEBUG: Ping FAILED for IP: 192.168.2.110 <0x2ac92310>
50      05/05/17 22:16:53.166   luup_log:132: VIRTUALPING DEBUG: Ping OS cmd: ping -c 1 -w 1 192.168.2.110, return value is: 256 <0x2ac92310>
50      05/05/17 22:16:53.170   luup_log:132: VIRTUALPING DEBUG: Ping FAILED for IP: 192.168.2.110 <0x2ac92310>
50      05/05/17 22:17:03.345   luup_log:132: VIRTUALPING DEBUG: Ping OS cmd: ping -c 1 -w 1 192.168.2.110, return value is: -1 <0x2ac92310>
50      05/05/17 22:17:03.349   luup_log:132: VIRTUALPING DEBUG: Ping FAILED for IP: 192.168.2.110 <0x2ac92310>
50      05/05/17 22:17:14.229   luup_log:132: VIRTUALPING DEBUG: Ping OS cmd: ping -c 1 -w 1 192.168.2.110, return value is: 256 <0x2ac92310>
50      05/05/17 22:17:14.238   luup_log:132: VIRTUALPING DEBUG: Ping FAILED for IP: 192.168.2.110 <0x2ac92310>
50      05/05/17 22:17:25.189   luup_log:132: VIRTUALPING DEBUG: Ping OS cmd: ping -c 1 -w 1 192.168.2.110, return value is: 256 <0x2ac92310>
50      05/05/17 22:17:25.193   luup_log:132: VIRTUALPING DEBUG: Ping FAILED for IP: 192.168.2.110 <0x2ac92310>
50      05/05/17 22:17:36.163   luup_log:132: VIRTUALPING DEBUG: Ping OS cmd: ping -c 1 -w 1 192.168.2.110, return value is: 256 <0x2ac92310>
50      05/05/17 22:17:36.167   luup_log:132: VIRTUALPING DEBUG: Ping FAILED for IP: 192.168.2.110 <0x2ac92310>
50      05/05/17 22:17:46.167   luup_log:132: VIRTUALPING DEBUG: Ping OS cmd: ping -c 1 -w 1 192.168.2.110, return value is: 0 <0x2ac92310>
50      05/05/17 22:17:46.168   luup_log:132: VIRTUALPING DEBUG: Ping SUCCESSFUL for IP: 192.168.2.110 <0x2ac92310>
50      05/05/17 22:17:56.294   luup_log:132: VIRTUALPING DEBUG: Ping OS cmd: ping -c 1 -w 1 192.168.2.110, return value is: 0 <0x2ac92310>
50      05/05/17 22:17:56.295   luup_log:132: VIRTUALPING DEBUG: Ping SUCCESSFUL for IP: 192.168.2.110 <0x2ac92310>
50      05/05/17 22:18:06.175   luup_log:132: VIRTUALPING DEBUG: Ping OS cmd: ping -c 1 -w 1 192.168.2.110, return value is: -1 <0x2ac92310>
50      05/05/17 22:18:06.239   luup_log:132: VIRTUALPING DEBUG: Ping FAILED for IP: 192.168.2.110 <0x2ac92310>
50      05/05/17 22:18:16.202   luup_log:132: VIRTUALPING DEBUG: Ping OS cmd: ping -c 1 -w 1 192.168.2.110, return value is: -1 <0x2ac92310>
50      05/05/17 22:18:16.206   luup_log:132: VIRTUALPING DEBUG: Ping FAILED for IP: 192.168.2.110 <0x2ac92310>
50      05/05/17 22:18:26.185   luup_log:132: VIRTUALPING DEBUG: Ping OS cmd: ping -c 1 -w 1 192.168.2.110, return value is: -1 <0x2ac92310>
50      05/05/17 22:18:26.189   luup_log:132: VIRTUALPING DEBUG: Ping FAILED for IP: 192.168.2.110 <0x2ac92310>
50      05/05/17 22:18:36.175   luup_log:132: VIRTUALPING DEBUG: Ping OS cmd: ping -c 1 -w 1 192.168.2.110, return value is: -1 <0x2ac92310>
50      05/05/17 22:18:36.179   luup_log:132: VIRTUALPING DEBUG: Ping FAILED for IP: 192.168.2.110 <0x2ac92310>

<Snip> Everything after this returns -1.
« Last Edit: May 05, 2017, 10:49:17 pm by twiseva »

Offline twiseva

  • Sr. Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Re: Ping Sensor
« Reply #595 on: May 06, 2017, 08:38:48 pm »
Edit:

WARNING: My Vera lite stopped working a day or so after this script ... I can't think of why but a warning up front if you plan on using this. Possibly remove the logging in the LUA? Not really why my Vera lite stopped working but it may have something to do with this and the logging possibly eating the disk space -- I could not recover it :-( On the other hand I have an excuse to get a VeraPlus!

--------------

Ok, so I didn't find the root cause of the issue I saw BUT have a work around that will get you 'ping' working if you have the same issue. I figured that the os.execute is having some issues so came up with use of a Lua command that is NOT os.execute! I used the io.* set of functions and had a Vera-side script put the status of a ping into these files with the hope the io suite didn't have the same issue.

There are two parts -- one on the Vera itself (you need to log into Vera to do this), and the other through the usual Vera UI.

PART 1: On the Vera (You'll need to understand UNIX somewhat to do this part -- it's pretty easy if you do or even if you are technically minded)

1. Set up a script on the Vera itself and run it via crontab. I have this running every minute. The smallest period possible in crontab. If you need something smaller you could add a sleep and just run this script continuously. I have attached a pingiphones.sh script as an example (this it what I am using). And added this to the crontab as follows (using crontab -e):

* * * * * /root/ping/pingiphones.sh

2. This script outputs the result of the pings to files. One per ping target. In my case, three different iPhones.  The simple .sh file is attached -- it pings three iphones. Change as needed.

PART 2: On the Vera UI

A. Set up a scene to run periodically (I used 15 secs but what ever you need -- remember the script runs only once per minute). Update the attached Lua code's first two variables to the file name you create in pingiphones.sh and the virtual switch device id (find it in Advanced). This Lua code does ONE file only. So I have 1 scene per iPhone and change the file name and virtual switch device IDs in each. Everything else stays the same.

A bit of a pain honestly but I have run it for a couple of hours and it seems to have no issues like os.execute did. Virtual switches are getting set as expected (within a minute or two depending on exact timing of the crontab and scene execution).

I'll run it over night to see if any issues come up ...

Cheers, Tony.

« Last Edit: May 08, 2017, 08:29:38 pm by twiseva »

Offline MNB

  • Hero Member
  • *****
  • Posts: 689
  • Karma: +4/-9
Re: Ping Sensor
« Reply #596 on: May 08, 2017, 07:52:11 pm »
Tony, looking at your LUA file I notice that you have the same local variable called twice "local pingFD" my editor highlighted whilst I was reviewing it. Did you perchance get it working and how successful were you?

I tried a different route using an RPI3 as a Bluetooth and Wifi detector which works great on my iPhone, however the Wifi seemed to be less reliable as it seems to go to sleep (e.g. when the display is off) however BT seemed to work more reliable but it range  limited (depends what's in between the  RPI3 and IPhone). I was having a the RPI3 sending a http data_request command to VERA to run a specific scene Home/Not Home that would turn ON/OFF a virtual switch, I found that the RPI3 log was showing a BT response every minute however VERA was turning the Virtual switch ON initially and then the next minute is turned it OFF as if toggling the first time turned it ON but re-toggling it the second time turns it OFF not sure what to do yet other than every other minute I have Home switch ON.. Mike

Update: It helps if one reads the documentation re "Virtual Switch" the default setting to turn ON a switch is "-1" which implies a toggle action where as "1" keeps the switch ON until a proper "0" is used to turn said switch OFF. thanxs @RexBeckett for your users guide...
« Last Edit: May 09, 2017, 09:29:28 am by MNB »
Edge-1.7.2607, VRI06-1LX Dimr (6), VS05-1LX Sw (4), GE ZW3002 Dimr (1), HA01C Outlet (12), HA02C Sw (6), HA04C Sw (4), GE Sw (2), HA05 Sw (3), MiniMote Contr (5), HSM200/100 Sensor (2), ZW100A Sensor (8), Nest thermostat (1) & Protect Fire/CO (6) Kwikset Locks (3), F18918W (1) & IP3M-9 (6) Cam's

Offline Don Phillips

  • Hero Member
  • *****
  • Posts: 1259
  • Karma: +31/-32
Re: Ping Sensor
« Reply #597 on: May 08, 2017, 08:07:49 pm »
I have had good experience with iPhone locator. It knows when either of our phones are home and sets the Home/Away House Mode reliability. I also have it set a virtual switch that displays on VeraMate only when that person is home. Similarly, I have a No One Home virtual switch that displays in VeraMate only when it is on. We can tell in a glance what is happening.
Vera 3, 1.7.1030, CT101 t-stat, Everspring motion detector, GE/Jasco switch, Leviton outlet, AeonLabs sensor, NuTone garage door, Blue Iris, Sricam SP011, iPhone locator, APCUPSD, VeraMate, VeraAlerts, PLEG, House Modes, Countdown Timer, DVR, Virtual/Multi Switch, Weatherunderground, LB60Z-1 bulb

Offline twiseva

  • Sr. Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Re: Ping Sensor
« Reply #598 on: May 08, 2017, 08:26:39 pm »
So as a possible WARNING -- My Veralite basically went 'bad' a day later after implementing the script (which worked fine -- I'll check the LUA @MNB if I need to redo it on my new VeraPlus). Possibly my logging ran it out of space? Not sure and the processes outlined to bring it back to life do not work unfortunately -- needs a XP emulator or XP. Emulator is only available under Win 7 and didn't work for me on my laptop (everything else is at Win 10 where it also doesn't work).

I am a little upset that the veralite can not be reset to factory defaults via the reset button but needs a convoluted firmware flash via an XP-only toolset. So basically the Veralite is bricked for some reason -- and even if my script did run it out of space, you should be able to reset to factory settings. Hopefully the newer ones do.

I am hoping the ping plugin works on my new vera!

Offline MNB

  • Hero Member
  • *****
  • Posts: 689
  • Karma: +4/-9
Re: Ping Sensor
« Reply #599 on: May 08, 2017, 09:15:29 pm »
Don, I too had used iphone locator, but it also suffers when the iPhone goes to sleep unless you've figured out how to keep Wifi awake rather than wake on Lan that the current IOS seems to have adopted? I noticed that when I ping my phone I get a number of "Request timed out." msgs, when I turn on my RPI3 app I can see how often or not often WiFi returns a ping reply can you confirm? Mike

Tom, my condolences to your Veralite.. To answer your original question, I'm currently using a Vera Edge and am hoping to convert to the latest to VeraSecure when ever it should arrive.. I know "Time is relative especially when its in Vera Time!"
Edge-1.7.2607, VRI06-1LX Dimr (6), VS05-1LX Sw (4), GE ZW3002 Dimr (1), HA01C Outlet (12), HA02C Sw (6), HA04C Sw (4), GE Sw (2), HA05 Sw (3), MiniMote Contr (5), HSM200/100 Sensor (2), ZW100A Sensor (8), Nest thermostat (1) & Protect Fire/CO (6) Kwikset Locks (3), F18918W (1) & IP3M-9 (6) Cam's