Detecting iPhone Wi-Fi connection

Posted on
Tue Sep 01, 2009 12:52 pm
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Detecting iPhone Wi-Fi connection

Has anyone found a simple way for Indigo to detect when an iPhone connects to (and disconnects from) the local Wi-Fi network? Being able to do this would enable something like a proximity switch in Indigo. When I arrive home do... and When I leave do...

I figured I can have an applescript continually (say every 5 seconds) ping the device's IP Address (assuming I have it hard-coded on the device or in my DHCP server) and then change an Indigo variable. It would probably also be a good idea to wait for a few failures in a row before assuming the iPhone "has left the building" to avoid false "disconnects."

However, I would really prefer something a little more deterministic. My problem is, I can't figure out anyway a Mac could see, or be told about a Wi-Fi connection between a Wi-Fi hub and an arbitrary device. I know I could trigger on the iPhone client connection, but that is not automatic.

Ideas? Has anyone else tried this?

Richard

Posted on
Tue Sep 01, 2009 3:33 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Detecting iPhone Wi-Fi connection

berkinet wrote:
Has anyone found a simple way for Indigo to detect when an iPhone connects to (and disconnects from) the local Wi-Fi network? Being able to do this would enable something like a proximity switch in Indigo. When I arrive home do... and When I leave do...

I figured I can have an applescript continually (say every 5 seconds) ping the device's IP Address (assuming I have it hard-coded on the device or in my DHCP server) and then change an Indigo variable. It would probably also be a good idea to wait for a few failures in a row before assuming the iPhone "has left the building" to avoid false "disconnects."

However, I would really prefer something a little more deterministic. My problem is, I can't figure out anyway a Mac could see, or be told about a Wi-Fi connection between a Wi-Fi hub and an arbitrary device. I know I could trigger on the iPhone client connection, but that is not automatic.

Ideas? Has anyone else tried this?

Richard


Not sure your idea will work - I don't believe the iphone connects to your local wireless network until you actually wake it up. I'm also not all that positive when the iPhone will release it's connection to the local router. My experience is that it's really not that predictable. What would be really cool is if Apple provided some type of "Where's my iPhone" API (perhaps in conjunction with a mobile me subscription) so that you could know. ;)

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Sep 01, 2009 4:22 pm
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Detecting iPhone Wi-Fi connection

While throwing a bucket of cold water on my idea, jay wrote:
Not sure your idea will work - I don't believe the iphone connects to your local wireless network until you actually wake it up. I'm also not all that positive when the iPhone will release it's connection to the local router. My experience is that it's really not that predictable.
Ah, reality... just when I figured out a way to detect the Wi-Fi connect. If there is a RADIUS or DHCP server involved in the Wi-Fi connection, then the Macintosh could "know" it took place. For trapping the disconnect, pinging would be Ok. Indigo would start a ping script once it knew the phone was "online." Then, if the phone goes out of range from the Wi-Fi hub, it wouldn't answer the pings.

But, if the switch-over timing from 3G to Wi-Fi is not predictable, well then trapping the connection event is not much help.

On the "too bad" front, too bad Apple doesn't support Wi-Fi/Mobile hand-off like some specialty phones do. Then the local area connection would be fairly well controlled.

Posted on
Tue Sep 01, 2009 4:49 pm
lalisingh offline
Posts: 166
Joined: Mar 27, 2007

(No subject)

Have not tried this but...

Use http://www.sustworks.com/site/prod_ipnrx_overview.html to make your 'indigo' mac into a router.


then have the router notify indigo when connection is established.

Posted on
Tue Sep 01, 2009 4:50 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Detecting iPhone Wi-Fi connection

berkinet wrote:
If there is a RADIUS or DHCP server involved in the Wi-Fi connection, then the Macintosh could "know" it took place.


I wonder if switching between Edge/3G and WiFi always results in a request for an address from DHCP. Don't know for sure.

berkinet wrote:
For trapping the disconnect, pinging would be Ok. Indigo would start a ping script once it knew the phone was "online." Then, if the phone goes out of range from the Wi-Fi hub, it wouldn't answer the pings.


Or the phone has decided to shut down the network connection for some reason - I'm not entirely convinced that the network stack stays continuously active when the phone transitions into full sleep mode. Matt did all the Touch work so he might know better, but it seems to me that i get periodic connect messages in the Indigo log when I leave Touch running on my phone. This implies to me that the network connection comes and goes.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Sep 01, 2009 4:58 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

(No subject)

lalisingh wrote:
Have not tried this but...

Use http://www.sustworks.com/site/prod_ipnrx_overview.html to make your 'indigo' mac into a router.


then have the router notify indigo when connection is established.



Now, that's an interesting idea...

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Sep 01, 2009 5:30 pm
Matt offline
Posts: 406
Joined: Aug 13, 2006
Location: Northern Idaho

(No subject)

There's a program called Proximity that monitors Bluetooth, but not wifi.

http://code.google.com/p/reduxcomputing-proximity/

Posted on
Wed Sep 02, 2009 2:36 pm
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

(No subject)

lalisingh wrote:
...http://www.sustworks.com/site/prod_ipnrx_overview.html to make your 'indigo' mac into a router.

then have the router notify indigo when connection is established.

I think this would essentially accomplish the same end as using the DHCP or RADIUS server to detect the connection.

In my case, I use a linux box as my home gateway and it runs my authentication, DHCP and routing services. I thought I might use DHCP as the "detector", since it is the easiest service for me to extend. All I need to do is find some way to send a signal from the Linux box to my Mac running Indigo.

I thought "curl" might be well suited for this task on the Linix end but I am unsure how to implement a listener daemon in AppleScript on the Mac. Does anyone out there in Indigo-land have experience with Linux/OS-X messaging, and if so, what did you do?

BTW, as noted in previous posts, the problem of detecting network disconnect is still unresolved. The connectionless nature of IP is hard to get around. Also, as Jay has pointed out, differentiating a "sleeping" iPhone from an absent iPhone is still an open issue. Still, it seems like there might be enough value here to pursue this idea a bit further.

Posted on
Wed Sep 02, 2009 3:47 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

(No subject)

berkinet wrote:
lalisingh wrote:
...http://www.sustworks.com/site/prod_ipnrx_overview.html to make your 'indigo' mac into a router.

then have the router notify indigo when connection is established.

I think this would essentially accomplish the same end as using the DHCP or RADIUS server to detect the connection.

In my case, I use a linux box as my home gateway and it runs my authentication, DHCP and routing services. I thought I might use DHCP as the "detector", since it is the easiest service for me to extend. All I need to do is find some way to send a signal from the Linux box to my Mac running Indigo.

I thought "curl" might be well suited for this task on the Linix end but I am unsure how to implement a listener daemon in AppleScript on the Mac. Does anyone out there in Indigo-land have experience with Linux/OS-X messaging, and if so, what did you do?

BTW, as noted in previous posts, the problem of detecting network disconnect is still unresolved. The connectionless nature of IP is hard to get around. Also, as Jay has pointed out, differentiating a "sleeping" iPhone from an absent iPhone is still an open issue. Still, it seems like there might be enough value here to pursue this idea a bit further.


Write a Indigo Web Server plugin that just listens for an HTTP GET and insert the data directly into Indigo variables. Check out my LWC IWS plugin that does exactly this with a GET from the LWS software.

Maybe it just executes the triggers that you want rather than feeding variables... ;)

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Sep 02, 2009 7:07 pm
anode offline
Posts: 697
Joined: May 27, 2007
Location: NC

(No subject)

Matt wrote:
There's a program called Proximity that monitors Bluetooth, but not wifi.

http://code.google.com/p/reduxcomputing-proximity/


Finally a use other then a headset for the iPhone's bluetooth. (well almost)

Posted on
Thu Sep 10, 2009 5:19 pm
FaTMax offline
Posts: 134
Joined: Feb 01, 2007
Location: Haugesund, Norway

(No subject)

Just like to confirm that the iPhone drops the WiFi connection after its been asleep for a while. Its to save battery.

EDIT: In apple´s own Remote app (for itunes) there is a force connection option, to prevent it from disconnecting during sleep. Maybe there is a way, but not that I know of...

Posted on
Fri Sep 11, 2009 4:56 am
kenjon offline
Posts: 96
Joined: Dec 04, 2005
Location: Sweden

(No subject)

Matt wrote:
There's a program called Proximity that monitors Bluetooth, but not wifi.

http://code.google.com/p/reduxcomputing-proximity/


That's pretty neat :-)
My Indigo server is in the garage. My Proximity machine is in the house. Can I have the Proximity program run an AppleScript on my server machine (instead of the Proximity machine itself, over LAN)?

Posted on
Wed Sep 16, 2009 3:25 pm
chrisla23 offline
Posts: 97
Joined: Sep 16, 2009

Detecting a wireless client with SNMP

Code: Select all

I do this to detect my blackberry and my wife's iphone by watching for them to login to our airport routers. It's a hacked up version of someone else's script that I found online.

Some caveats:

- The airport extreme seems to not like being polled so often, I have to reboot it once a day (I have a controllable PDU in my rack) to keep it happy. SNMP stops responding, it otherwise is fine. The airport express does not seem to have this problem, I complained to apple.
- The iphone will disable the wireless if not plugged in and the screen lock kicks in
- You would need to work out the SNMP OIDs for the MACs of your devices with snmpwalk.
- You need to do the snmpwalk before the snmpget's or it has stale info (I'd love to know why?)
- The time appears to be an epoch in hundredths of a second since boot.
- I use this to turn on our outside lights at night when we arrive. It's sort of hit or miss whether the clients associate fast enough for this to be helpful.

-- SensorProbe8 SNMP fetch applescript
-- Author of this mess:
--     Daniel Chote (http://www.chote.com)
-- Date: December 1, 2007

-- property sensorProbeIp : "10.0.0.1"

property sensorProbeIps : {¬
   {"10.0.0.1"}, ¬
   {"10.0.0.55"} ¬
      }

property sensorProbes : {¬
   {"blackberryPhoneWirelessTimeAssociated", ".1.3.6.1.4.1.63.501.3.2.2.1.4.17.48.48.58.49.67.58.67.67.58.55.70.58.69.69.58.67.67"}, ¬
   {"iphonePhoneWirelessTimeAssociated", ".1.3.6.1.4.1.63.501.3.2.2.1.4.17.48.48.58.50.51.58.49.50.58.68.48.58.49.68.58.70.57"} ¬
      }

property variableRefreshRate : 3

repeat
   try
      -- LogEvent("Sensorprobe poll started", "", 0)
      SensorProbeAll()
      --LogEvent("Sensorprobe poll finished", "", 0)
   end try
   delay variableRefreshRate
end repeat

on LogEvent(errText, errString, errNum)
   tell application "IndigoServer"
      try
         if errString is not "" then
            log errText & ":" & errString & "(" & (errNum as string) & ")" using type "Sensorprobe"
         else
            log errText using type "Sensorprobe"
         end if
      end try
   end tell
end LogEvent

on SensorProbeAll()
   repeat with thisSensorProbeIp in sensorProbeIps
      try
         set sensorProbeIp to item 1 of thisSensorProbeIp
         repeat with thisProbe in sensorProbes
            try
               set currentVar to item 1 of thisProbe
               set currentOID to item 2 of thisProbe
               tell application "IndigoServer"
                  set oldProbeResponse to the value of variable currentVar
               end tell
               do shell script "snmpwalk -m AIRPORT-BASESTATION-3-MIB -Os -v 2c -c public " & sensorProbeIp & " 1.3.6.1.4.1.63.501.3.2" & " >>/dev/null"
               set probeResponse to (do shell script "snmpget -v1 -c public -O vq " & sensorProbeIp & " " & currentOID)
               -- LogEvent("preprobe " & currentVar & " has value of " & probeResponse & " old was " & --oldProbeResponse, "", 0)
               if length of probeResponse > 0 and probeResponse is not equal to oldProbeResponse then
                  LogEvent("probe " & currentVar & " has value of " & probeResponse, "", 0)
                  tell application "IndigoServer"
                     if not (variable currentVar exists) then make new variable with properties {name:currentVar, value:"0"}
                     set value of variable currentVar to probeResponse
                     -- execute group "cellhome"
                  end tell
               end if
            end try
         end repeat
      end try
   end repeat
end SensorProbeAll

Posted on
Wed Sep 16, 2009 3:55 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Detecting a wireless client with SNMP

chrisla23 wrote:
[code]

I do this to detect my blackberry and my wife's iphone by watching for them to login to our airport routers. It's a hacked up version of someone else's script that I found online........


This script is also now in the file library.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Sep 16, 2009 10:06 pm
bobeast offline
User avatar
Posts: 400
Joined: Apr 16, 2003

Re: Detecting a wireless client with SNMP

jay wrote:
chrisla23 wrote:
[code]

I do this to detect my blackberry and my wife's iphone by watching for them to login to our airport routers. It's a hacked up version of someone else's script that I found online........


This script is also now in the file library.


Thanks Jay. Question for you. If I execute this command;

[code]snmpwalk -m AIRPORT-BASESTATION-3-MIB -Os -v 2c -c public 10.0.1.1 1.3.6.1.4.1.63.501.3.2[/code]

I get a response specific to my iPhone of;

[code]wirelessPhysAddress."00:25:BC:AB:23:93" = STRING: "00:25:BC:AB:23:93"[/code]

However, the script expects something like;

[code]{"bobPhoneWirelessTimeAssociated", ".1.3.6.1.4.1.63.501.3.2.2.1.4.17.48.48.58.49.67.58.67.67.58.55.70.58.69.69.58.67.67"}[/code]

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

Thanks!
Bob E.

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

Who is online

Users browsing this forum: No registered users and 3 guests