Detecting iPhone Wi-Fi connection

Posted on
Thu Sep 17, 2009 2:10 pm
chrisla23 offline
Posts: 97
Joined: Sep 16, 2009

(No subject)

There are two parts to the snmp oid string, OIDFORTHEINFOYOUWANT.MAC.

If you do an snmp walk wihtout the mib info you'll see the raw OID info.

snmpwalk -Os -v 2c -c public 10.0.0.1 1.3.6.1.4.1.63.501.3.2

You could then grep for either your mac address (in the normal format) or do it with the mib, figure out the integer for your current association, and then without, and grep for that (that's what I did).

Your mac is the information after: 1.3.6.1.4.1.63.501.3.2.2.1.4.

The SNMP OID is somehow derived from some sort of hexidicimal conversion of part of the mac address. If some clever person figures it out, it would be a good addition to the script. I just went with trial and error as I only needed a couple of them.

Posted on
Thu Sep 17, 2009 2:13 pm
chrisla23 offline
Posts: 97
Joined: Sep 16, 2009

(No subject)

Oh and also wirelessTimeAssociated is what it is keying off of.

Also I found this website very useful in learning all of this:

http://support.ipmonitor.com/mibs/AIRPO ... /info.aspx

-Chris

Posted on
Thu Sep 17, 2009 2:56 pm
jay (support) offline
Site Admin
User avatar
Posts: 16025
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Detecting a wireless client with SNMP

bobeast wrote:
Any insight as to how (or if) wirelessPhysAddress returned from snmpwalk correlates to the OID the script is looking for?


No idea - I haven't used the script, I just approved it when it was posted into the lib. Sorry...

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Sep 17, 2009 6:29 pm
bobeast offline
User avatar
Posts: 400
Joined: Apr 16, 2003

(No subject)

chrisla23 wrote:
Oh and also wirelessTimeAssociated is what it is keying off of.

Also I found this website very useful in learning all of this:

http://support.ipmonitor.com/mibs/AIRPO ... /info.aspx

-Chris


Thanks Chris! That helped a lot.

Bob E.

Choose to chance the rapids.
Dare to dance the tide.

Posted on
Thu Sep 17, 2009 8:54 pm
bobeast offline
User avatar
Posts: 400
Joined: Apr 16, 2003

Re: Detecting a wireless client with SNMP

jay wrote:
bobeast wrote:
Any insight as to how (or if) wirelessPhysAddress returned from snmpwalk correlates to the OID the script is looking for?


No idea - I haven't used the script, I just approved it when it was posted into the lib. Sorry...


I got it working with my iPhone thanks to some help from Chris. Now the bad news. The iPhone drops off WiFi when it goes to sleep. So unless the phone is awake when you arrive home, the script does not see it.

Anyone know if there is a way around this?

Bob E.

Choose to chance the rapids.
Dare to dance the tide.

Posted on
Thu Sep 17, 2009 9:57 pm
chrisla23 offline
Posts: 97
Joined: Sep 16, 2009

(No subject)

Is it doing that when the phone is plugged into power? My wife's seems to keep the wifi up as long as it is plugged in.

Posted on
Thu Sep 17, 2009 10:09 pm
bobeast offline
User avatar
Posts: 400
Joined: Apr 16, 2003

(No subject)

chrisla23 wrote:
Is it doing that when the phone is plugged into power? My wife's seems to keep the wifi up as long as it is plugged in.


Same here. When plugged in, it doesn't drop off of the network. It must be a battery saving thing. I'm running 3.1. Unfortunately, it never occurred to me to check this prior to the update.

Choose to chance the rapids.
Dare to dance the tide.

Posted on
Thu Sep 17, 2009 10:21 pm
chrisla23 offline
Posts: 97
Joined: Sep 16, 2009

(No subject)

My wife's does it on 3.0 so I don't think it's an update thing.

I've vaguely thought of avoiding the whole issue by say putting an old router in client mode in the car and keying off of that instead.

Posted on
Thu Sep 17, 2009 11:28 pm
bobeast offline
User avatar
Posts: 400
Joined: Apr 16, 2003

(No subject)

chrisla23 wrote:
I've vaguely thought of avoiding the whole issue by say putting an old router in client mode in the car and keying off of that instead.


That's not a bad idea at least for keeping track of the comings and goings of cars. Around my house though there's is no fixed pattern as to who is driving which vehicle.

I saw a thread a while back regarding a script to poll you're iPhone's position by spoofing MobileMe's Find My iPhone" feature. Maybe I'll take another look in that direction.

Choose to chance the rapids.
Dare to dance the tide.

Posted on
Fri Sep 18, 2009 4:14 am
bschollnick2 offline
Posts: 1324
Joined: Oct 17, 2004
Location: Rochester, Ny

(No subject)

bobeast wrote:
chrisla23 wrote:
I've vaguely thought of avoiding the whole issue by say putting an old router in client mode in the car and keying off of that instead.


That's not a bad idea at least for keeping track of the comings and goings of cars. Around my house though there's is no fixed pattern as to who is driving which vehicle.

I saw a thread a while back regarding a script to poll you're iPhone's position by spoofing MobileMe's Find My iPhone" feature. Maybe I'll take another look in that direction.


I wrote a python wrapper around the perl code, and did start working on a plugin for it.... I'll have to check to see how far I got, I believe I was at the point of trying to figure out the best way to integrate it into a display in indigo...

Posted on
Fri Sep 18, 2009 11:11 am
bobeast offline
User avatar
Posts: 400
Joined: Apr 16, 2003

(No subject)

bschollnick2 wrote:
I wrote a python wrapper around the perl code, and did start working on a plugin for it.... I'll have to check to see how far I got, I believe I was at the point of trying to figure out the best way to integrate it into a display in indigo...


That would be most welcome! I played around with it yesterday, and was able to get it to work from the command line. Very cool! Of course it will be interesting to see Apple's reaction, should they catch on to the fact that the service is being polled, as opposed to ad hoc usage. If we had the ability to specify the distance threshold beyond 1 mile, we could decrease the poll rate accordingly.

Choose to chance the rapids.
Dare to dance the tide.

Posted on
Tue Jun 29, 2010 2:47 am
screen offline
Posts: 25
Joined: Feb 19, 2009

Re: Detecting iPhone Wi-Fi connection

Sorry to awaken an old topic however with the release of iOS4 I think there are some new options. It seems that the new iOS, especially with iPhone4, changes how WIFI is handled when the phone is in sleep mode. Although I'm a big fan of Proximity and have used it in the past, keeping bluetooth on when at home is a battery drain and not 100% reliable.

So the current state of things seems to be that while plugged in iOS4 is always connected to WIFI when asleep. When not plugged it the phone will wake up wifi to connect at the interval it is set to for fetching mail, for me this is 15 minutes. In this configuration I can see the phone connecting for approximately 15 seconds every 14.5 minutes, plenty enough to detect it on my network if I ping it's static IP (important detail) every 5 seconds.

I've installed the following cron job on my mac mini:

Code: Select all
# detect iPhone on network
*/1 * * * * ~/bin/iphonecron &> /dev/null


iphonecron loops 12 times since cron cannot schedule in under 1 minute intervals, each loop interval will take about 5 seconds total:

Code: Select all
#!/bin/bash

for((i=1; $i<=12; i=$(($i+1)))); do
  ~/bin/iphonecheck
  sleep 4
done


iphone check performs the ping and updates my iphone presence variable only when it changes:

Code: Select all
#!/bin/bash
IPHONELASTONLINE=`cat /tmp/iphonestate 2>/dev/null`
ISONLINE="false"
/sbin/ping -t 1 -c 1 192.168.1.117 &>/dev/null && ISONLINE="true" && sleep 1

if [[ "$ISONLINE" != "$IPHONELASTONLINE" ]]; then
  osascript -e "tell application \"IndigoServer\" to set value of variable \"PresenceiPhone\" to \"$ISONLINE\""
fi

echo $ISONLINE > /tmp/iphonestate


In Indigo I'm using a trigger action to detect the PresenceiPhone value change to ensure my home mode is set to 'home'. My modes are set automatically by inspecting the value of PresenceLastMinSince which is incremented every minute and reset anytime a typical 'being home' action is detected in Indigo. This could be almost any insteon message, IR control, camera motion detection etc. Away and vacation modes are automatically set when PresenceLastMinSince becomes greater than 60 minutues and 18 hours respectively.

This is a new implementation and I'll update here if I experince any problems. I hope these details are useful to other Indigo users.

Posted on
Tue Jun 29, 2010 6:42 am
jay (support) offline
Site Admin
User avatar
Posts: 16025
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Detecting iPhone Wi-Fi connection

Clever, thanks for sharing!

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Oct 27, 2010 3:45 am
anothersphere offline
Posts: 154
Joined: Jul 01, 2009

Re: Detecting iPhone Wi-Fi connection

Code: Select all
osascript -e "tell application \"IndigoServer\" to set value of variable \"PresenceiPhone\" to \"$ISONLINE\""


I keep getting command not found when this line executes. Any ideas why?

Martin Miller

Auckland - New Zealand

Posted on
Wed Oct 27, 2010 7:12 am
matt (support) offline
Site Admin
User avatar
Posts: 19739
Joined: Jan 27, 2003
Location: Texas

Re: Detecting iPhone Wi-Fi connection

Maybe try the absolute path to osascript instead?

/usr/bin/osascript

Image

Who is online

Users browsing this forum: No registered users and 1 guest