Detecting my mobile phone

I am experimenting with code to detect my Android phone, as I have seen people use their phones as a convenient way to detect when they are at home.

I am doing this by pinging the IP address. This assumes that Wifi is permanently on. The phone seems to connect to Wifi when any button is pressed – you don’t have to unlock the phone. It does not disconnect immediately it turns off, but waits several minutes.

I have currently put the address of the phone in my hosts file so I can change it easily if DHCP allocates a different address, but I will need to allocate a fixed IP address if I am going to stick with this, and make it a feature of my system.

Pinging from Java in a way that works on both Linux (for the Raspberry Pi) and on Windows (for development on my laptop) is not particularly easy. InetAddress.getByName(address).isReachable(timeout) does not seem to work on Windows 7, so the method I have chosen is to execute the ping command and parse the output. Currently I look for the word “unreachable”. This works but is not very efficient, and may have to change a bit for Linux.

I plan to add this to OpenRemote as a sensor, so OpenRemote will know if my phone is on and in range. I might have to add separate sensors to detect switching on and switching off.

How useful will this be? It won’t be able to detect the difference between the phone being out of range or being switched off.

Also to use it to detect arriving home, I would need to remember to press a button on my phone. It won’t be able to detect the difference between the phone switching off, and me going out.

So, with these restrictions, what rules could I use it to fire? I suppose I could combine it with time of day to try to distinguish arriving home from just turning the phone on, but now that I am not working, I don’t have very regular habits, so that is not going to work.

I will probably add it to OpenRemote and see if I get inspiration on how to use it.

Advertisements
This entry was posted in Electronics, Home automation. Bookmark the permalink.

2 Responses to Detecting my mobile phone

  1. One approach you can use is to cycle through every IP on the local subnet, ping each device, get the Mac address and then match that to your phone. This will also find anyone or anything else that connects to your home network. You can ping from C# without launching an .EXE.

    • Geek Grandad says:

      Thanks for the suggestion. I could check for multiple phones that way without having to use fixed IP addresses, as well as check for intruders. I have been reading your blog recently and have got some ideas for future developments from it. I have written ,NET applications in the past, but I am mainly using Java for my home automation project. This is partly because I am using one or more Raspberry Pis for the production servers, and partly because I like the OpenRemote project which is written in Java.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s