Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: Can the presence of an iPhone be detected Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 942
Posted: June 19 2013 at 13:10 | IP Logged Quote GadgetGuy

I'm thinking that a nice and reliable way to turn my
alarm system on off automatically using PowerHome would
be to detect the presence of my iPhone in the house.

Since I always have my iPhone with me, if it is
detectable then I am home and the Alarm should be Off.

But if no iPhone is detected then I am away from home and
the alarm should be set.

I discovered that the phone can be pinged on my LAN, but
only if it is on and not asleep. As soon as you tap the
power button or the wake timer times out, the phone goes
into sleep mode and cannot be pinged.

But emails seem to come in, along with alerts so clearly
the phone still has one eye open   

Is there thus any way to determine if the phone is in the
house, via LAN queries or location detection (ie, are the
GPS coordinates=to Home?)

============

Editing this post to get the following results at the top of the thread!!

I have developed code to reliably detect an iPhone (a non-trivial feat as the iPhone is a very different device) on your local LAN is now available here . . .

(08/26/13) The link below is UPDATE v2.4.2 to prior eleases that improves stability and error recovery. It's download is highly recommended.

(08/27/13) Bad bug introduced into v2.4.2. Do NOT download. Working on fixes, will post as soon as fix available.

(08/27/13) So far, so good. Fixes have been stable on my system, so releasing v2.5.0. NOTE that the structure of the findMyPhone.txt file returns contents that have changed in structure. If you are not examining that file to take further actions, then no problem, else, note that extra line feeds were removed.

(08/27/13) Sorry 'bout that but found another bug in testing that prevented always discovering if the phone was not on the LAN. Got that fixed, so the new version is v2.5.1

(10/25/14) My bad in not updating this post. Many improvements added to v2.6.9 to make iPhone finding more reliable.

The latest code is now ...

findMyPhone-v2.6.0

In addition, there is now a findMyDroid, which incorporates many of the reliability features of the iPhone code and works much better than just trying to ping a Droid.

This code can be found at ...
findMyDroid-v3.1.3

The ZIP files for these App contains the raw VB .Net code, a Windows executable, and a User Guide with instructions on how to integrate into PowerHome.

I have found this App useful in a number of manners. I use the presence/absence of my phone to disarm/arm my motion detection facilities on my security system so as to not clutter up the video recording cache with unnecessary video captures when we are home.

It is also very useful in determining if we are HOME or AWAY in order to control nighttime lighting. If we are away for an extended time we generally leave by 9AM in the morning. So at 4:30AM every morning I clear a PH global of {HOME}. I then wait until after 10AM before using the iPhone's presence to set that global. If we are not home anytime after 10AM and before {Sunset} then
at sunset the home lighting scenes are much reduced from what they would be if we were HOME.

Hopefully you will find it as useful as I have.



Edited by GadgetGuy - October 25 2014 at 10:16


__________________
Ken B - Live every day like it's your last. Eventually, you'll get it right!
Back to Top View GadgetGuy's Profile Search for other posts by GadgetGuy
 
lizaoreo
Groupie
Groupie


Joined: February 11 2013
Location: United States
Online Status: Offline
Posts: 75
Posted: June 20 2013 at 08:13 | IP Logged Quote lizaoreo

I think the iPhone shuts of wifi when it's asleep. I know mine always wakes up disconnected and connects
after a second or two. It gets emails and such via the push notification system over the cell network I
believe (but that's a guess).

I have seen where one guy had a router flashed with OpenWRT and used that to execute a CRON job whenever
the phones were detected on the network or detected to have left the network. Throwing out my
understanding above, maybe the iPhone keeps some kind of passive connection to the wifi network, but is
unable to respond to pings and such during the lower state.
Back to Top View lizaoreo's Profile Search for other posts by lizaoreo
 
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 942
Posted: June 20 2013 at 08:28 | IP Logged Quote GadgetGuy

Thanks lizaoreo -

I may have to try the router approach. I've had my phone
in Airplane mode for the last 24 hours but with wi-fi re-
enabled to see if it gets alerts, or email.

If nothing comes in then it is truly asleep with regard to
any LAN connections.

__________________
Ken B - Live every day like it's your last. Eventually, you'll get it right!
Back to Top View GadgetGuy's Profile Search for other posts by GadgetGuy
 
smarty
Super User
Super User
Avatar

Joined: May 21 2006
Location: United States
Online Status: Offline
Posts: 728
Posted: June 20 2013 at 12:38 | IP Logged Quote smarty

Watching this topic.....

__________________
Elk - Insteon - BlueIris - DMC1 - PowerHome - XLobby - HA_Bridge w/Dots - Brultech
Back to Top View smarty's Profile Search for other posts by smarty
 
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 942
Posted: June 20 2013 at 14:27 | IP Logged Quote GadgetGuy

I just checked my phone and I have multiple Notification
alerts as well as email. I have been off the cell
network for almost 24 hours but wi-fi is enabled, so
these messages are coming in thru my wireless LAN.

Therefore it seems the phone is actually listening to som
things, but for some reason does not respond to a ping at
its (LAN) IP address.

Now if I can determine kept alive access method, and it
is two way (not just passively accepting messages) then
perhaps it can be polled to tell when it is on the LAN.   


__________________
Ken B - Live every day like it's your last. Eventually, you'll get it right!
Back to Top View GadgetGuy's Profile Search for other posts by GadgetGuy
 
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 942
Posted: June 22 2013 at 07:40 | IP Logged Quote GadgetGuy

Am getting much, much closer!

Discovered that Apple's "bonjour" which provides "Zero
Configuration Networking" allows one to access iOS
devices (also printers, etc) using the special "local" IP
tag.

Thus my iPhone is always detectable on my wireless LAN
(assuming of course that the phone has wi-fi enabled) as
"Ken-iPhone.local:62078".

A simple browser access to this IP:port address results
in a "No Data Returned" response, versus a "Page Not
Found" error, if the phone is not on the LAN at all.

I installed "bonjour" on my PH computer and verified I
can discover the phone with my browser.

Now I just need to figure out how to get PH to do the
same thing.

I tried ph_geturl(), but get a socketblob error.

Hoping to figure out how to get around that and get this
working.   

Will keep progress posted!


Edited by GadgetGuy - June 22 2013 at 07:42


__________________
Ken B - Live every day like it's your last. Eventually, you'll get it right!
Back to Top View GadgetGuy's Profile Search for other posts by GadgetGuy
 
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 942
Posted: June 22 2013 at 10:40 | IP Logged Quote GadgetGuy

Making more progress.

I found that when my phone is awake it is discoverable
using a browser with an address of . . .
   "Ken-iPhone.local:62078"
(as are all of our other iOS devices in a similar
fashion). I get a "No Data Returned" error, BUT that
indicates the phone was accessed, just that nothing was
returned. If the phone is not present then a "Page Not
Found" error occurs.

That is just a more general way of accessing the phone
versus http://192.168.1.92:62078 which is its actual IP
network address.

If I can discover the phone with a browser I am a long
way towards using it to automate my system.

Unfortunately the ph_geturl() function crashes, but
ph_)getwburl() grabs the html response from the phone
which is a "Navigation Cancelled" message, but that also
causes the IE browser to pop up the same web page and it
then crashes when you close it?

The problem is that the 62078 port only is alive when the
phone is awake. After the Auto-Lock timeout, the phone
goes back to sleep and does not respond.

Dealing in some strange territory here.

All of this "works" only when the phone is alive, but not
when it is asleep. When asleep, there is no response
from port 62078.

Does anyone know if there is an iPhone port that will
allow a connection independent of phone state?

Ken Burkhalter

Aspire to inspire before you expire.

__________________
Ken B - Live every day like it's your last. Eventually, you'll get it right!
Back to Top View GadgetGuy's Profile Search for other posts by GadgetGuy
 
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 942
Posted: June 25 2013 at 07:16 | IP Logged Quote GadgetGuy

Original message DELETED as it referred to a spammers post
here, and Dave removed that!

Edited by GadgetGuy - June 25 2013 at 14:44


__________________
Ken B - Live every day like it's your last. Eventually, you'll get it right!
Back to Top View GadgetGuy's Profile Search for other posts by GadgetGuy
 
MrGibbage
Super User
Super User
Avatar

Joined: October 23 2006
Location: United States
Online Status: Offline
Posts: 513
Posted: June 25 2013 at 07:41 | IP Logged Quote MrGibbage

Are you sure you don't have a way to keep wifi on while the phone is asleep? My android
phone has that as an option (last few phones have all had that option, in fact).

__________________
Skip
Back to Top View MrGibbage's Profile Search for other posts by MrGibbage
 
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 942
Posted: June 25 2013 at 12:31 | IP Logged Quote GadgetGuy

Skip -

Good thought, but to the best of my knowledge the iPhone
offers no such feature. To conserve battery, the phone
auto-locks after a timeout and shuts down all transmission
radios. It ignores everything received except a few wake-
on-lan type TCP messages which will wake it back up.

I'm looking now into the 3-way-handshake protocol (SYN,SYN-
ACK,ACK) to see if I can get a response from a sleeping
phone. I think I'm close, but not there yet.

Edited by GadgetGuy - June 25 2013 at 12:32


__________________
Ken B - Live every day like it's your last. Eventually, you'll get it right!
Back to Top View GadgetGuy's Profile Search for other posts by GadgetGuy
 
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 942
Posted: June 25 2013 at 13:36 | IP Logged Quote GadgetGuy

YES!!!!!

SUCCESS!!!

Using the Wireshark network trace tool, I determined that
the phone awakes (just had to wait for iTunes to query
it) when it sees the standard 3-way handshake TCP
protocol sent to it.

Using the following ph function . . .
Code:
ph_sendsocketdata1 ( "192.168.1.92", 62078, 6, "\x16" )


where 192.168.1.92 is the IP address of my phone and
62078 is the port on the IP that responds to TCP traffic,
6 is the proper FLAG setting to get Control characters
thru, and 16(hex) is the SYNchronize ASCII command, I
find that the phone responds by completing the handshake
sequence.

I sense this success as a null message returned by the
sendsocketdata() function. If the phone is not present,
then the return socket message is "*ERROR* - TIMEOUT
WHILE CONNECTING"

If I don't get the error, the phone is in my home and if
the error occurs then I am gone (with my phone) and the
security system is alarmed.

To minimize phone battery drain from continual
awakenings, I use a Timed Event to poll the phone every
30 minutes.

Talk about being a happy camper!!!

======

Just to show the more general way of addressing your iPhone on the LAN, use this syntax . . .
Code:
ph_sendsocketdata1 ( "ken-iphone.local", 62078, 6, "\x16" )


where "ken-iphone" is just your phone's device name as set in iTunes when you defined the phone. It can be found in the Settings.General>About>Name field.



Edited by GadgetGuy - June 26 2013 at 09:43


__________________
Ken B - Live every day like it's your last. Eventually, you'll get it right!
Back to Top View GadgetGuy's Profile Search for other posts by GadgetGuy
 
MrGibbage
Super User
Super User
Avatar

Joined: October 23 2006
Location: United States
Online Status: Offline
Posts: 513
Posted: June 25 2013 at 13:49 | IP Logged Quote MrGibbage

How can you be sure that the phone's IP address will be the
same every time? If there is a way to go to a fixed IP
address, that will help you at home, but could cause you
trouble if you ever try to join a network outside of your
home.

__________________
Skip
Back to Top View MrGibbage's Profile Search for other posts by MrGibbage
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: June 25 2013 at 13:58 | IP Logged Quote dhoward

Skip,

I can answer that one . I just go into my router configuration and reserve a DHCP address based upon my phone (or other devices) MAC address. That way nothing changes on the phone and it always get the same IP address.

Congratulations Ken!!. Glad to hear you got it working to your satisfaction.

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
lizaoreo
Groupie
Groupie


Joined: February 11 2013
Location: United States
Online Status: Offline
Posts: 75
Posted: June 25 2013 at 14:08 | IP Logged Quote lizaoreo

Awesome, I think I'll set that up just to turn off the
lights if no one is home... doesn't matter how easy it is
to turn everything off, someone always manages to not do
it.

So I assume you just turn the alarm off manually? :)

Yep, DHCP reservations are awesome, everything in my house
has a reservation so I can keep up with what's what, I even
have an address scheme laid out in Excel I use to decide
what types of devices get what range of addresses.
Back to Top View lizaoreo's Profile Search for other posts by lizaoreo
 
MrGibbage
Super User
Super User
Avatar

Joined: October 23 2006
Location: United States
Online Status: Offline
Posts: 513
Posted: June 25 2013 at 14:14 | IP Logged Quote MrGibbage

Great idea, Dave. Ken, I would like to hear the rest of the logic that you
plan to use. For instance, if you are going to use it to auto-arm your
alarm system when you are gone, how will it handle when you are gone, but
other family members are still home. What will you have the HA do when it
detects your presence? What other exceptions do you have to deal with.

I suspect that this is still early in the process, so you probably don't
have answers to all of these. In fact, you probably won't have the logic
all worked out for quite a while as you live with it. So just keep this
thread in mind and come back and tell us what considerations and exceptions
you had to account for, and what cool things you have it doing based on
your presence/lack of presence.

Congrats, Ken!

__________________
Skip
Back to Top View MrGibbage's Profile Search for other posts by MrGibbage
 
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 942
Posted: June 25 2013 at 14:42 | IP Logged Quote GadgetGuy

Re the phone address you can also use the phone's Domain
name when you are on your lan.

My phone, for instance is . . .
    "Ken-iPhone.local"

Where "Ken-iPhone" is the name of my phone as set in
iTunes device config.

This will work no matter what the actual IP address is.
I happen to use the DHCP reservation approach as
suggested by Dave.

Re. Logic. I'm not planning to use the phone presence to
actually turn my alarm system on/off (but if you lived
alone that would work) for the reasons you point out of
"others around".

What I am doing it enabling my camera motion detection
triggering, to keep the clutter out of the captured file
folder. There is no point in capturing motion when we
are home, just when away. Since the wife and I usually
are away together, that works. If I capture video when
I'm gone and she's home, no big deal. Most of the
clutter comes in the evening when we are moving around
the house and I wanted to eliminate as much of that as
possible.


__________________
Ken B - Live every day like it's your last. Eventually, you'll get it right!
Back to Top View GadgetGuy's Profile Search for other posts by GadgetGuy
 
smarty
Super User
Super User
Avatar

Joined: May 21 2006
Location: United States
Online Status: Offline
Posts: 728
Posted: June 26 2013 at 08:34 | IP Logged Quote smarty

Just to clarify....is Bonjour the only additional software you had to install
on your PH machine to make this work?

Is Bonjour a service? Does it affect your PH machine stability? Startup
speed or anything else you may have noticed?

__________________
Elk - Insteon - BlueIris - DMC1 - PowerHome - XLobby - HA_Bridge w/Dots - Brultech
Back to Top View smarty's Profile Search for other posts by smarty
 
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 942
Posted: June 26 2013 at 09:37 | IP Logged Quote GadgetGuy

Actually, after the fact, I don't think Bonjour is needed
at all. I didn't discover that until after I installed
it, and just haven't bothered to remove it yet.

An easy test is without Bonjour just wake up your phone
so the screen is lit and using the Windows Command window
send a ping first to your iPhone's actual IP address. EG,
   ping 192.168.1.92

That should work.

Then ping by name. EG,
   ken-iphone.local

The name of your phone is found in . . .
   Settings>General>About>Name

That should also work.


Edited by GadgetGuy - June 26 2013 at 13:54


__________________
Ken B - Live every day like it's your last. Eventually, you'll get it right!
Back to Top View GadgetGuy's Profile Search for other posts by GadgetGuy
 
smarty
Super User
Super User
Avatar

Joined: May 21 2006
Location: United States
Online Status: Offline
Posts: 728
Posted: June 26 2013 at 12:57 | IP Logged Quote smarty

From the little testing I have done, it appears that from a CMD PROMT (aka a dos window), the "ping" command seems to accomplish the same task.

I can ping "sleeping" devices at home (my ipad and old iphone) and they respond. When I ping the wife's or my iphone (which we have with us at work), the ping does not respond and times out.

I have yet to try this ping approach from within PowerHome, but I would suspect it would work the same.

__________________
Elk - Insteon - BlueIris - DMC1 - PowerHome - XLobby - HA_Bridge w/Dots - Brultech
Back to Top View smarty's Profile Search for other posts by smarty
 
smarty
Super User
Super User
Avatar

Joined: May 21 2006
Location: United States
Online Status: Offline
Posts: 728
Posted: June 26 2013 at 13:03 | IP Logged Quote smarty

Works the same from within PH as well.

Sleeping or On...makes no difference...

As positive number means the device is found, negative means it's not there...

__________________
Elk - Insteon - BlueIris - DMC1 - PowerHome - XLobby - HA_Bridge w/Dots - Brultech
Back to Top View smarty's Profile Search for other posts by smarty
 

Page of 3 Next >>
  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum