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.