Page 1 of 2

Ping with OSX and Indigo

PostPosted: Tue Oct 27, 2015 9:13 am
by RageDoctor
Dear all,

I was trying to write a script which searches in my wifi-network for my smartphone and in case there is one I would like to receive a "true" and in case my smartphone is not within the network it should state "false".

I would like to use this for letting my smart home know whether I am at home. Unfortunately it works fine on my Win 7 computer but not on the Mac running the script with an action trigger.

Any ideas? Is anyone using this option?

Best regards,
Marcus

...I am looking for the right script...perhaps it is on the Win 7 computer....

Ping with OSX and Indigo

PostPosted: Tue Oct 27, 2015 9:49 am
by durosity
There's a plugin for indigo called FingScan that can do exactly this.


Sent from my iPad using Tapatalk

Re: Ping with OSX and Indigo

PostPosted: Fri Oct 30, 2015 9:31 am
by RageDoctor
Hey, back again from a business trip...

Here is the code, I have used to test the ping call (with an internet source to keep things simple)

import subprocess
p = subprocess.Popen(["ping", "-c", "10", "www.cyberciti.biz"], stdout=subprocess.PIPE)
output, err = p.communicate()
indigo.server.log(str (output))


Errorcode:
[ERRNO 2]

What is wrong with this?

Any ideas?

Marcus

Re: Ping with OSX and Indigo

PostPosted: Fri Oct 30, 2015 9:45 am
by kw123
ping is not known to the shell ( no path to executables defined when you open it with subprocess) you need to use /sbin/ping:

ipn=192.x.x.x.
Code: Select all
ret=subprocess.Popen('/sbin/ping -c3 '+ipn,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
         resp = ret.communicate()


and as the author of FINGscan just look at the plugin and see what else you can do. happy to discuss.
This is not meant to discourage you from developing it yourself -- that is where the fun is..

Karl

also try:
/sbin/ping -c 2 -W2 -o 192.168...

or
Code: Select all
subprocess.Popen("for ((i=0;i<"+str(maxPingsBeforeReset)+";i++)); do /sbin/ping -c 2 -W "+str(pingWait)+" -o "+ipN+" &>/dev/null  && echo up>"+self.fingDataDir+"pings/"+ipN.split(".")[3]+".ping && sleep "+str(sleepT)+" ; done",shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)


will execute ping maxPingsBeforeReset times and will create a file 99.ping 192.168.99) if successful

Re: Ping with OSX and Indigo

PostPosted: Fri Oct 30, 2015 10:21 am
by kw123
Also .. an iPhone goes into sleep mode after some minutes, then you can not ping it anymore..

you need WiFi info from the router: if it is associated it stays associated even it is in PSM (power save mode).
The actual "active" sleep time is only some milliseconds, then it wakes up to just send a quick tickle to the router, on a much lower level than ping, Then it sleeps again.

Karl

Re: Ping with OSX and Indigo

PostPosted: Fri Oct 30, 2015 11:34 am
by RageDoctor
Thank you very much. I am pretty new to coding and therefore Python. But it is fun to play around, as you said. Unfortunately, I am pretty busy at work and I can not play like I would like to.

I am pretty impressed by the possiblities and look and feel of Indigo. However, the support of new hardware is somehow a downside. But...I am going to buy the pro version anyhow :!:

It is pretty tedious (I don't know whether this is the right adjective) to search through all the threads - is there any discussion going on ,on how to make the smart home really smart? I am talking about knowing themselves, that the scene "at home" or "away" needs to be executed.

However, I should start from the scratch...First things first.

Best regards,
Marcus

Re: Ping with OSX and Indigo

PostPosted: Sun Jan 17, 2016 11:46 pm
by zurich
Greetings,

Has anyone got ping to work in a sub process? Using this code:
Code: Select all
import subprocess

ipn = "10.0.1.20"   

ret = subprocess.Popen(["/sbin/ping", "-c", "2", ipn], stdout=subprocess.PIPE)
output =ret.stdout.readlines()

ret.stdout.close()

print output


I get continual output of:
ping: recvmsg: Operation not permitted


kind regards,

Z

Re: Ping with OSX and Indigo

PostPosted: Mon Jan 18, 2016 4:13 am
by kw123
don't know if thats the problem, but I would try:

ret = subprocess.Popen(["/sbin/ping", "-c", "2", ipn], stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate()
print ret[0] prints std out
print ret[1] prints any error message

Karl

Re: Ping with OSX and Indigo

PostPosted: Mon Jan 18, 2016 8:30 am
by durosity
On a side note, it might be nice for a ping functionality to be built into your Utilities plugin, Karl. It's both handy from a 'checking if something is on' point of view and a diagnostics test as well.

Re: Ping with OSX and Indigo

PostPosted: Mon Jan 18, 2016 8:47 am
by kw123
Nice idea.
It's included in a fingscan menu

Will think about how to make it easy to use.




Sent from my iPhone using Tapatalk

Re: Ping with OSX and Indigo

PostPosted: Mon Jan 18, 2016 8:49 am
by kw123
Just to share some exciting news: I am waiting for my colonoscopy but still texting.


Sent from my iPhone using Tapatalk

Re: Ping with OSX and Indigo

PostPosted: Mon Jan 18, 2016 8:54 am
by roussell
kw123 wrote:
Just to share some exciting news: I am waiting for my colonoscopy but still texting.


Sent from my iPhone using Tapatalk


My ex-wife is having one today as well... For some reason the news of you having one upsets me more than the news of her having one. :twisted:

Terry

Re: Ping with OSX and Indigo

PostPosted: Mon Jan 18, 2016 8:59 am
by durosity
roussell wrote:
kw123 wrote:
Just to share some exciting news: I am waiting for my colonoscopy but still texting.


Sent from my iPhone using Tapatalk


My ex-wife is having one today as well... For some reason the news of you having one upsets me more than the news of her having one. :twisted:

Terry


That's the kind of thing you wish upon ex's.. not valued plugin developers ;)

Re: Ping with OSX and Indigo

PostPosted: Mon Jan 18, 2016 9:00 am
by durosity
kw123 wrote:
Just to share some exciting news: I am waiting for my colonoscopy but still texting.


Sent from my iPhone using Tapatalk


And please no pictures during the procedure.. i'm enjoying a chocolate chip brioche roll right now and i don't want to be put off them for life :D

Re: Ping with OSX and Indigo

PostPosted: Mon Jan 18, 2016 5:58 pm
by kw123
I survived.. :P