Ping with OSX and Indigo

Posted on
Tue Oct 27, 2015 9:13 am
RageDoctor offline
Posts: 72
Joined: Oct 03, 2015
Location: Wiesbaden, Germany

Ping with OSX and Indigo

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....

Every beginning is hard...
Software: Indigo 6.1.4
Controller: Z-Stick Gen 5
Devices: Fibaro Wall Plug, Motion Sensor and Door/Window Sensor, Aeon Labs MultiSensor 6, more to come...

Posted on
Tue Oct 27, 2015 9:49 am
durosity offline
User avatar
Posts: 4320
Joined: May 10, 2012
Location: Newcastle Upon Tyne, Ye Ol' England.

Ping with OSX and Indigo

There's a plugin for indigo called FingScan that can do exactly this.


Sent from my iPad using Tapatalk

Computer says no.

Posted on
Fri Oct 30, 2015 9:31 am
RageDoctor offline
Posts: 72
Joined: Oct 03, 2015
Location: Wiesbaden, Germany

Re: Ping with OSX and Indigo

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

Every beginning is hard...
Software: Indigo 6.1.4
Controller: Z-Stick Gen 5
Devices: Fibaro Wall Plug, Motion Sensor and Door/Window Sensor, Aeon Labs MultiSensor 6, more to come...

Posted on
Fri Oct 30, 2015 9:45 am
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: Ping with OSX and Indigo

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
Last edited by kw123 on Mon Jan 18, 2016 4:08 am, edited 1 time in total.

Posted on
Fri Oct 30, 2015 10:21 am
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: Ping with OSX and Indigo

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

Posted on
Fri Oct 30, 2015 11:34 am
RageDoctor offline
Posts: 72
Joined: Oct 03, 2015
Location: Wiesbaden, Germany

Re: Ping with OSX and Indigo

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

Every beginning is hard...
Software: Indigo 6.1.4
Controller: Z-Stick Gen 5
Devices: Fibaro Wall Plug, Motion Sensor and Door/Window Sensor, Aeon Labs MultiSensor 6, more to come...

Posted on
Sun Jan 17, 2016 11:46 pm
zurich offline
Posts: 103
Joined: Aug 11, 2014

Re: Ping with OSX and Indigo

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

Posted on
Mon Jan 18, 2016 4:13 am
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: Ping with OSX and Indigo

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

Posted on
Mon Jan 18, 2016 8:30 am
durosity offline
User avatar
Posts: 4320
Joined: May 10, 2012
Location: Newcastle Upon Tyne, Ye Ol' England.

Re: Ping with OSX and Indigo

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.

Computer says no.

Posted on
Mon Jan 18, 2016 8:47 am
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: Ping with OSX and Indigo

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

Posted on
Mon Jan 18, 2016 8:49 am
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: Ping with OSX and Indigo

Just to share some exciting news: I am waiting for my colonoscopy but still texting.


Sent from my iPhone using Tapatalk

Posted on
Mon Jan 18, 2016 8:54 am
roussell offline
User avatar
Posts: 1108
Joined: Aug 18, 2008
Location: Alabama

Re: Ping with OSX and Indigo

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

Posted on
Mon Jan 18, 2016 8:59 am
durosity offline
User avatar
Posts: 4320
Joined: May 10, 2012
Location: Newcastle Upon Tyne, Ye Ol' England.

Re: Ping with OSX and Indigo

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 ;)

Computer says no.

Posted on
Mon Jan 18, 2016 9:00 am
durosity offline
User avatar
Posts: 4320
Joined: May 10, 2012
Location: Newcastle Upon Tyne, Ye Ol' England.

Re: Ping with OSX and Indigo

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

Computer says no.

Posted on
Mon Jan 18, 2016 5:58 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: Ping with OSX and Indigo

I survived.. :P

Who is online

Users browsing this forum: No registered users and 1 guest

cron