Detecting iPhone Wi-Fi connection

Posted on
Sun Apr 17, 2011 2:50 pm
anothersphere offline
Posts: 158
Joined: Jul 01, 2009

Re: Detecting iPhone Wi-Fi connection

Hmm, I might have to reenable WebMin which has (I believe) a syslog module!
Webmin is great for all sorts of things, but can be a pig to install.
Perl is involved if I recall correctly.
I am pretty sure that full MacOS dev tools may be required.

http://www.webmin.com

http://www.macupdate.com/app/mac/12262/webmin (added)

Martin Miller

Auckland - New Zealand

Posted on
Sun Apr 17, 2011 3:14 pm
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Detecting iPhone Wi-Fi connection

I wrote:
...I can post a simple example of the shell script if there is interest.

Ok, in response to a PM, here is a rough example that simply looks for log lines matching MAC Addresses from a list. For practical use it needs to be expanded to test for Association/Disassociation. Note you could also add support to look-up a user name/tag for the MAC address and other useful things.

BTW. I could not test this exact code on my Mac because I do not have syslogd running, but a similar script that looked at the Indigo log worked fine. In other words... this may contain bugs.
Code: Select all
#!/bin/sh

LOG_FILE=/var/log/airport.log
MAC_LIST="00:23:df:9d:30:70 00:24:36:ed:19:9e"

/usr/bin/tail -f "$LOG_FILE"|while true
do
        read line foo
        for i in $MAC_LIST
        do
                /bin/echo $foo|/usr/bin/grep -q "$i
                if [ $? -eq 0 ]
                then
                        /bin/echo "SUCCESS: found " $i in $foo
                        #Do something here, like execute an AppleScript with osascript
                        # or use curl to send a RESTful API call to Indigo, etc.
                fi
        done
done

Posted on
Mon Apr 18, 2011 5:17 am
loafbread offline
Posts: 137
Joined: May 25, 2009

Re: Detecting iPhone Wi-Fi connection - using twitter

Thinking about ways to wake up the iPhone to respond to pings, I came across a script to post a twitter message. I modified it to send a directed message. By enabling badge notifications in the iPhone twitter app, it wakes up for about 10 seconds. It only takes about 5 seconds for the badge push to arrive at the iPhone. When I get time, I will be incorporating this into my "who is home" ping scripts. This method is less intrusive than the pushmail method.

You have to define a developer app with twitter to get the authorization keys required for the OAuth login. The process only takes a few minutes.

Here is the place to get the scripts: http://www.internoetics.com/2011/01/12/ ... ing-oauth/

I replaced the last few lines of the example.php script with the syntax to send a directed message instead of a generic status message like this:

$user = "twitter_Username";
$message = "This is a direct test wakeup message.";
$tweet->post('direct_messages/new', array('user' => "$user", 'text' => "$message"));

Posted on
Mon Apr 18, 2011 2:34 pm
jameslitton offline
Posts: 5
Joined: Apr 06, 2011

Re: Detecting iPhone Wi-Fi connection

I use Notifo to send push notifications to my iPhone if my backups fail, if my Dynamic DNS update fails, and for numerous other purposes. Notifo supports a "silent" push and the service may be a viable method for "forcing" the iPhone to a wake state. Pushing a silent message to the phone every five minutes would keep one below the 10,000 message monthly limit which makes the service free.

Using the Mail application with quarter-hour updates has worked flawlessly for me thus far so I have not tested this method but it may be worth a try.

Posted on
Mon Apr 18, 2011 6:27 pm
dstrickler offline
User avatar
Posts: 340
Joined: Oct 08, 2010
Location: Boston, MA

Re: Detecting iPhone Wi-Fi connection

I've started working on a semi-simple "Am I Home" script, and it's working in test mode, all except for the crazy AppleScript. Being that I am trying to make this semi-simple, I am using AppleScript as much as I can, avoiding Bash if possible.

The code below always returns TRUE, regardless of the ip I feed into it. I'm running it as an Attachment in Indigo. Can someone shed some light on what I am doing wrong? If I get it working, I promise to share ;-)

Code: Select all
using terms from application "IndigoServer"
   
   on ping(deviceName)
      log "Trying to Ping device " & deviceName
      try
         (do shell script "/sbin/ping -o -t 4 -c 4 " & deviceName & " &> /dev/null")
         
         tell application "IndigoServer"
            log "Ping found device " & deviceName & " OK"
            return true
         end tell
         
      on error errStatement number errNum --errStatement holds text of error message, errNum the integer code described in either 'man ping' or sysexits.h
         tell application "IndigoServer"
            log "Ping FAILED to find device " & deviceName
            return false
         end tell
         
      end try
   end ping
end using terms from

Dave

Posted on
Mon Apr 18, 2011 8:33 pm
jay (support) offline
Site Admin
User avatar
Posts: 18224
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Detecting iPhone Wi-Fi connection

It has something to do with how shell script errors are returned - I believe with embedded scripts somehow the server ends up swallowing errors returned on standard error. Most people just catch the return text and look for something to indicate a failure:

Code: Select all
set theResult to do shell script "/sbin/ping -o -t 4 -c 4 " & deviceName
if theResult contains "100.0% packet loss" then
   log "Ping FAILED to find device " & deviceName
   return false
end if
log "Ping found device " & deviceName & " OK"
return true


The only downside is if the BSD subsystem gets updated with a new ping command that returns something slightly different - I believe it changed between 10.4 and 10.4.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Apr 18, 2011 9:24 pm
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Detecting iPhone Wi-Fi connection

This is slightly longer than what Jay offered, but, it is independent of the output format. FYI, $? is the result code of the last command executed. 0 = success, non-0 = error.
Code: Select all
ping("192.168.4.243")

on ping(deviceName)
   tell application "IndigoServer"
      log "Trying to Ping device " & deviceName
      set rc to (do shell script "/sbin/ping -o -t 4 -c 4 " & deviceName & " >/dev/null 2>&1; /bin/echo $?") as number
      if rc is 0 then
         log "Ping found device " & deviceName & " OK"
         return true
      else
         log "Ping FAILED to find device " & deviceName
         return false
      end if
   end tell
end ping

Posted on
Mon Apr 18, 2011 9:34 pm
dstrickler offline
User avatar
Posts: 340
Joined: Oct 08, 2010
Location: Boston, MA

Re: Detecting iPhone Wi-Fi connection

Yup, it was eating the error code al right. Weird! Many thanks to both of you on this fix.

I need to turn in for the night, but I should have something ready (and debugged!) in a few days to post here.

Dave

Posted on
Sun Jul 24, 2011 10:29 am
dshj offline
User avatar
Posts: 84
Joined: Jan 16, 2010
Location: San Francisco, CA

Re: Detecting iPhone Wi-Fi connection

dstrickler, any updates on this? I have a setup close to yours, and I'm very curious with what you find here.

Jay, any chance of some kind of a push notification being built into Indigo Touch for this purpose in the near future?

Posted on
Sun Jul 24, 2011 12:26 pm
dstrickler offline
User avatar
Posts: 340
Joined: Oct 08, 2010
Location: Boston, MA

Re: Detecting iPhone Wi-Fi connection

dshj,

Nothing to post I am happy with. While the code I have for a ping is bug free as code, the method is questionable, meaning that if I ping my router it works perfectly. If a ping an iPhone, it works most, but not all, of the time. Even when I am sure the phone is awake, as I have it manually scanning, I can't seem to get a consistant ping.

So while my code is valid, my methods are not. This is clearly a very, very tricky problem to solve.

Dave

Posted on
Thu Aug 18, 2011 3:45 am
bigedison offline
Posts: 14
Joined: Apr 11, 2010

Re: Detecting iPhone Wi-Fi connection

HI,
I use phone Amego to detect bluetooth connection on my iphone, if my iphone is in range I set a indigo variable at_home to true and if my iphone isn't in range I switch the variable value to false.
I use it since few month and it works very well.
Don't hesitate ton contact me if you need more details

Posted on
Sat Feb 01, 2014 3:10 pm
robertgerman offline
Posts: 42
Joined: Dec 14, 2013
Location: Vaxjo, Sweden

Re: Detecting iPhone Wi-Fi connection

Sorry to wake an old thread but if been struggling with detection of who is at home for some time now and want to share some experience. I recently switched from a long time IPhone usage to Android. Excited to get the app Tasker working I have it sending ssh commands to my macmini running Indigo and starting apple scripts to modify variables. All good and it works as good as 100%. I use it to deactivate the Indigo based alarm system and switching of the foscam camera used in the alarm system.

When I got it working good with Android I wanted my girlfriends iPhone to be detected as well. After many tries with pinging the phone I switched to geofence with the app IFTTT. The app sends an email when reaching the preset location to deactivate the alarm system and activates the camera if leaving the geofence (based on an email triggers in Indigo) . I have been testing it for two weeks with good result.

Just wanted to point to IFTTT, give it a try if you're not getting pinging the phone to work as you wanted.
Last edited by robertgerman on Sat Feb 01, 2014 3:29 pm, edited 1 time in total.

Posted on
Sat Feb 01, 2014 3:27 pm
jay (support) offline
Site Admin
User avatar
Posts: 18224
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Detecting iPhone Wi-Fi connection

Yeah, we've discussed IFTTT. The really unfortunate thing is that they don't have an action do to an HTTP GET or POST. That would make is significantly more usable. I believe some others have talked about tasked here.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sat Feb 01, 2014 3:32 pm
robertgerman offline
Posts: 42
Joined: Dec 14, 2013
Location: Vaxjo, Sweden

Re: Detecting iPhone Wi-Fi connection

Not sure what would be improved with HTTP GET and POST but I guess it's like sending ssh commands? Tried to Google it but didn't get much answers ;-)

Tasker is a great app, one of the main reasons for me to switch to Android.

Posted on
Sat Feb 01, 2014 4:15 pm
jay (support) offline
Site Admin
User avatar
Posts: 18224
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Detecting iPhone Wi-Fi connection

An HTTP GET is exactly what you type in the URL bar of your browser and a POST is what happens when you submit a form in a web browser. Using Indigo's RESTful API you could have IFTTT directly update an Indigo variable, execute an action group, turn on a light, etc. No need for the extra overhead of an email and it would likely be considerably more responsive.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Who is online

Users browsing this forum: No registered users and 16 guests