You might not have lost your Android phone or had it stolen, but if you want to prepare for that possibility, here’s how to setup your phone to respond and contact you with its location.
Image by the Comic Shop
We’ve shown you that there are things to do when you’ve lost your smartphone, using Tasker and How to Easily Access your home Network from anywhere… Now lets take all of these disjointed parts and throw them together into one delicious geek cake (which isn’t a lie ).
What we will do is have your Android automatically reach out through the internet back to your home router. Now according to triggers that you specify, the device will react in different ways from sounding an alarm and using the flash light, to silently email you a personalized message that includes the device *location.
*If your device supports this functionality.
A couple of questions that come to mind are: what if the device is never connected to the internet again? Or why wouldn’t I just use one of the programs that were mentioned on the you’ve lost your smartphone guide, that call home over the internet and/or that receive and SMS?
It boils down to this, if you already bought Tasker for one of its other usages, you might as well take full advantage of it. This will enable you to run just one program instead of two or more. In regards to the internet connection, it is highly unlikely that anyone would use a “smartphone” without any sort of connection to the internet. That is what these devices were created for, and if the device was never reconnected, we don’t have to worry about anyone getting our online information, A? As for SMSs, maybe your android device doesn’t even have SMS capabilities, as it is with some tablets? And what if the thief takes out your SIM and puts his own? Besides, with just a couple of little tweaks you could make the trigger be an SMS if you wanted too.
It is highly recommended that you follow the How To Easily Access Your Home Network From Anywhere With DDNS guide, to create your own DNS name. We will use “howtogeek.is-a-geek.com” as an example for this guide.
Our call back functions will rely on the *absence* of open ports on your home network. Ports that will only be opened in case the finding functions need to be invoked. How you get an HTTP server on your home network for said trigger ports, is beyond the scope of this guide. With that said, such a thing can be accomplished with something as simple as temporarily opening your routers management to the internet. While this is something that should be avoided under normal circumstances, when in a pinch, it can serve as a quick and easy way to do it without having to setup/maintain yet another component. Below is an example how this would look like on DD-WRT.
Where depending on the port opened, different actions will be performed by the Android device.
While we will be performing a lot of Tasker configurations, this is by no means a definitive guide for Tasker and a lot of information and ideas for usages can be found on their wiki. In fact the inspiration for this guide was obtained from it. Note that some of the functions we will use in this guide require your device to be “Rooted” at least.
Tasker’s GPS support
Tasker is limited by android (v2.3 and above) to not turn on the GPS automatically. If you are using the Cyanogenmod distribution on your device, this limitation has been lifted for you by the developers. However we’ve found that most other distributions do not lift this limitation, and so even if “Rooted” do not enable Tasker to use the GPS directly. In that case you will need to install the free auxiliary plugin for Tasker called Secure Settings with its service counterpart Secure Settings Helper. Together, they act as a back-end service for Tasker, receiving the requests from it, and executing them as a “root” privileged service. When writing, Cyanogenmod was used, so installing and using Secure Settings is beyond the scope of this guide.
Tasker’s Email support
To support sending email, the SL4A route has been chosen for this guide. The full reference is on the Tasker wiki.
1. While beyond the scope of this guide, It is highly recommended that you setup a new Email account for your device, because the credentials are going to be kept, in the task that uses it, in clear text. Hence, if your device is compromised, you probably don’t want to leave the username + password for your main email account so vulnerable and, potentially, in someone else’s hands. Something like email@example.com with a randomly generated password, should do nicely. Moreover, it will make presentation of these emails more logical, in case you get them, as they will not be coming from “you”.
2. Install SL4A on your Android device.
3. Install the Python interpreter as explained here.
4. Download the Email sending script.
5. Create the Email Task as explained in the section below.
Tasker Profiles and Tasks
Assuming you now have Tasker, SL4A and the Python interpreter installed lets create the Profiles and Tasks that will do the work.
Task – Toggle led loop
This task has been inspired by the “Led On/off” from the first Tasker guide, but adds a play a sound file into the mix and loops the led toggle.
Open Tasker and Create a new “task” by pressing the lightning icon.
Select “New Task” at the top of the list.
Give it a name and approve it.
Add steps by clicking the Plus(+) sign.
Toggle led loop, Steps 1 – 5:
1. Audio –> Music Play: select a sound file – The file you want to play.
2. Audio –> Media Volume: 15 – Set the volume to maximum so that you can hear it better.
3. Plus –> TeslaLED (you may need to install this app): Toggle –> Reverse the state of the LED.
4. Tasker –> Wait: 500ms+ 1s – Set the delay until the next step to 1.5 seconds
5. Tasker –> Go to Action: 2 – Go back to step number 2.
5a. Within the above step, If: %MISSING Is Set – Only take the action of this step, if the %MISSING variable is set.
Task – Emailer
We will create this task so that we can call it from any other task with only the minimal parameter changes. It is highly based on the one from the Tasker’s wiki.
Emailer, steps 1 – 5:
1. Variables –> Variable Set: %EMAIL_USER to “email_user_name” – This script is designed to work with Gmail so this could be either your own Gmail account or as recommended “firstname.lastname@example.org”.
2. Variables –> Variable Set: %EMAIL_PSWD to “the above email’s password” – Again, note that this is in clear text! It is, recommended that this will be a password you don’t rely on, for an email account that you don’t care about.
3. Variables –> Variable Set: %EMAIL_TO to “your_email_address” – The default email recipient.
3a. Within the above step, If: %EMAIL_TO is NOT set – Only set the variable if it isn’t already set. This is in case you have a reason to change the recipient, you can do it from the calling task.
4. Variables –> Variable Set: %EMAIL_NAME to “account display name” – This is just a display name for the email account.
4a. Within the above step, If: %EMAIL_NAME is NOT set – Only set the variable if it isn’t already set. We do this, because if we call the task from another task it is possible we will set this according to the needs of the calling task before we invoke this one.
5. Variables –> Variable Set: %EMAIL_SUBJECT to “Subject of the email being sent”
5a. Within the above step, If: %EMAIL_SUBJECT is NOT set – Same as in 4a.
Emailer, steps 6 – End:
6. Variables –> Variable Set: %EMAIL_BODY to “Subject of the email being sent”
6a. Within the above step, If: %EMAIL_BODY is NOT set – Same as in 4a.
7. Tasker –> Misc –> Run Script: sendemailA.py
8 – End. Variables –> Variable Clear: the_variables_used_in_this_task – While not obligatory, It A. keeps things tidy for later B. Ensures that the variables will be clear the next time we use them so that the defaults can take affect, if required.
Task – Get Location
This task’s job is to *activate the GPS and try to get the device’s location so that we can send it later on with an email.
Note: These steps assume you have the Cyanogenmod distribution on your device.
Get Location, Steps 1 – 5:
1. Misc –> GPS: on – Turn the GPS device on.
2. Misc –> Get Location: GPS + timeout of 240 seconds –> Use the GPS to obtain the device’s location.
3. Tasker –> Wait: 1 second – This is just to make sure that the GPS information has time to be set into the variables.
4. Variable –> Variable Set: %LOCTIME to %LOCTMS – We copy the content of the “Location Fix time Secs” variable so that we can perform an action on it in the next step.
5. Variable –> Variable Convert –> %LOCTIME with function “Seconds to Medium Date Time”. – This will give us the date of the last obtained location fix in a readable format, which we will use when we email the information back to us.
Task – Http call home find me helper(8080)
This task is meant to help you locate the device in case you’ve just misplaced it between the couch cushions, or that a roommate is playing an unpleasant prank on you.
What it does, is checks port 8080 (you may opt to use another one), and does a couple of simple things:
- It locks the device with the requirement that unlocking will be done with the keyguard function (it has been assumed you’ve set one up).
- It calls the “Toggle led loop” task.
Http call home find me helper, Steps 1 – 4:
1. Tasker –> Stop – This will abort the execution of this profile no matter what, in case the %QUIET variable is set.
1a. Within the above step, If: %QUIET Is Set – Only take the action of this step, if the %QUIET variable is set.
2. Net –> HTTP Get: www.d.co.il – This step has been described on the Tasker website, as a way of testing that the device is actually connected. While you may opt to use a different (closer to you) site, this is how we will test that the device is connected before doing anything else.
3. Net –> HTTP Get: howtogeek.is-a-geek.com:8080 – This tells tasker to try and connect to port 8080 on that DDNS address.
3a. Within the above step, If: %HTTPR ~ 200 – Only do the above step if the response from the HTTP Get before it was positive (200).
4. Tasker –> If: %HTTPR matches 200 – Only if the last HTTP response was positive (200) perform the below steps.
Http call home find me helper, Steps 5 – 9:
5. Variable –> Variable Add: %MISSING – Add 1 to the value of %MISSING which will also set it if it wasn’t.
6+7. Tasker –> Profile Status: <name of profile> set to off – Both steps 6 and 7 address the case where, Keyguard is disabled automatically by a tasker profile. While this is great for normal situations, this is not the time for such a “Trust”.
8. Tasker –> Perform Task: “Keyguard on” – This command calls another task I’ve created that just turns keyguard on if it isn’t, and there is no “Trust”. While this task is out of this guide scope you can find examples for it on the Tasker wiki.
9. Plus –> Display –> System Lock – Just to be on the safe side, make the system lock down once.
Http call home find me helper, Steps 10 – 11:
12. Tasker –> Perform Task: “Toggle Led loop + alarm” – This step calls the “Toggle led loop” task.
13. Tasker –> End If – End the “if” from step 4.
Task – http call home and panic(8081)
This task builds on the first one and adds the “email me the location” function. in addition, it will relentlessly lock the device over and over unless you clear the missing variable.
What it does, is checks port 8081, and then:
- Like the 8080 task, it calls the Toggle Led loop” task.
- It calls the “get location” task, so that if possible it will obtain where the phone is.
- It calls the email function to send you the information it was able to gather.
http call home and panic, steps 1 – 4
1. Tasker –> If: %MISSING is NOT set – This condition will make the task skip the “are we missing” test if it is called from another “we’ve been found missing task”.
2. Net –> HTTP Get: www.d.co.il – Same as with the task above, this is how we test that an internet connection exists.
3. Net –> HTTP Get: howtogeek.is-a-geek.com:8081 – This tells tasker to try and connect to port 8080 on that DDNS address.
3a. Within the above step, If: %HTTPR ~ 200 – Only do the above step if the response from the HTTP Get before it was positive (200).
4. Variables –> Variable Set: %MISSING to panic – Actually this is just to “set” the variable, it doesn’t have to be a specific string.
5. Tasker –> End If – Closes the “if” we started on step 1.
http call home and panic, steps 6 – 9:
6. Tasker –> If: %MISSING is set – Only perform the actions below if we’ve been found “missing” as charged.
7. Alerts –> Flash: missing has been set! – While optional, it is nice to know that the system hasn’t gone crazy on us for no reason, rather that it is reacting to the fact that the missing variable has been set.
7a. Within the above step, If: %QUIET is NOT set – Only take the step above if the %QUIET variable is NOT set.
8+9 – 6+7. Tasker –> Profile Status: <name of profile> set to off – Both steps 8 and 9 address the case where, Keyguard is disabled automatically by a tasker profile. While this is great for normal situations, this is not the time for such a “Trust”.
10. Media –> Music Play –> select notification sound – Actually this step is completely unnecessary, but this sound from Doctor Who is so “computer submissive” I had to use it as the “I got your command and I’m executing” notification.
http call home and panic, steps 11 – 9:
11. Tasker –> Perform Task: Toggle led loop – Enter the Led loop
11. Within the above step, If: %QUIET is NOT set – only take the step above if the %QUIET variable is NOT set.
12. Display –> Keyguard: on – set Keyguard to on.
13. Display –> System Lock – Lock the system right NOW.
14. Tasker –> Perform Task: Get Location – Execute the “get location” task we’ve created above.
15. Variable –> Variable Set %EMAIL_SUBJECT to “Find panic from android” – You can set this subject to anything you want…
http call home and panic, steps 16 – 20:
16. Variables –> Variable Set: %MAIL_BODY to:
I am at http://maps.google.com/maps?q=%LOC
The nearby cell is: %CELLID
The last location fix was on: %LOCTIME with accuracy of: %LOCACC
This step is heavily based on a Tasker wiki page, and it sets the Body of the email, to give you a lick to Google-maps to find your phone, with the last seen cellular antenna ID detected and the output of the “get location” task. You may of course customize this to your hearts content.
17. Tasker –> Perform Task: Emailer – Use the “Emailer” task to send this new information to us.
18. Tasker –> Wait: 10 seconds – Give a 10 seconds cool down time.
19. Tasker –> If: %MISSING is set – I know it seems silly to have another check “if we are missing” at this point, but in actuality, this is a breaker point. This is because it is possible we actually want to abort the re-execution of the task by the “go to” command below, and other wise simply wouldn’t have the option.
20. Tasker –> Goto Action: 12 – Go back to step 12, as to re-execute the task from the lockdown section.
20a. Within the above step, If: %QUIET NOT is set – Only perform the step if the %QUIET variable is NOT set.
http call home and panic, steps 21 – 24(end):
21. Tasker –> Wait: 1 minute – If we got to this point, we probably use the silent alarm. so we don’t need to re-execute the lockdown, and we can probably live with an email “just” once per minute.
22. Tasker –> Goto Action: 14 – re-execute the task from the “get location” section.
23. Tasker –> End If – Close the “If” from step 19.
24. Tasker –> End If – Close the “If” from step 6.
Task – http call home and panic silently(8082)
This profile builds on the above two, with the slight difference that the actions will be performed quietly.
What it does, is checks port 8082, and then:
- Sets the QUITE variable we’ve been waiting for all this time.
- Calls the 8081 profile, which will act the same as before, only with all the “if”s for the QUIET variable now active.
http call home and panic silently, steps 1 – 5:
1. Net –> HTTP Get: www.d.co.il – Same as with the task above, this is how we test that an internet connection exists.
2. Net –> HTTP Get: howtogeek.is-a-geek.com:8082 – this tells tasker to try and connect to port 8082 on that DDNS address.
2a. Within the above step, If: %HTTPR ~ 200 – Only do the above step if the response from the HTTP Get before it was positive (200).
3. Tasker –> If: %HTTPR matches 200 – If the response from the “get” above was positive (200) perform the below.
4. Variables –> Variable Add: %MISSING – Add 1 to the “missing” variable, to set it.
5. Variables –> Variable Add: %QUIET – Add 1 to the “quiet” variable, to set it.
http call home and panic silently, steps 6 – 7 (end):
6. Tasker –> Perform Task: “http call home and panic” – Execute the “panic” task, only now that the QUITE variable is set, a lot of the task “if”s will be realized.
7. Tasker –> End If – End the “if” from step 3.
Profile – Display off
It is time to create the profiles (triggers) that will invoke the tasks we created above.
While the trigger selection is completely up to you and your whims, for the purpose of this guide, we will use the “display has turned off” as a trigger. We will also limit said trigger to not execute more then once a minute, because, its too much to have it run every single time the display turns off. You may want to “play” with that value too. Also you could use the “every X minutes”, an SMS trigger, a “when leaving the trusted environment” triggers or all of them, if you wanted too…
1. Create a new profile.
2. Give it a name.
3. Select the type of trigger, in our case it is “Event”.
4. Select the “Display” category.
5. Select the “Display Off” event.
6. Click the green V to create the profile.
7. Select the “task” to be invoked by the trigger.
8. Now that the Profile has been created you can add another task to be invoked by the same trigger.
9. Once you’ve clicked on the task within the profile, you’ll be presented with this menu:
10. Click “Add Task” and select an additional task.
11. Limit the execution of the profile to once a minute, by clicking the “properties” icon.
12. From the menu, choose properties.
13. Change the cooldown counter.
Tasker – Ignore errors
Now that the profile/s are created you may notice, that because the test returns an error, every time it is run and while the port isn’t open, Tasker “flashes” an error message to the screen. While informative, can now become a nuisance.
To turn that off, if you wan too, go to:
1. Menu –> Preferences.
2. Deselect “Flash Problems”.
Anticlimactically, you should now notice that all your hard work is actually not doing anything. That is why it is recommended, that you should probably make some test runs, to see that that the device does indeed react to the triggers, by opening said ports on your network.
If you’ve opted to trigger the profiles, you will probably need a way to turn off the alarm once it has been tripped.
To do this:
1. Close the triggering port on your home network.
2. Enter Tasker – Yes I know its inconvenient right now because the system is locking up… but you can’t have your cake and leave it whole.
3. Turn Tasker off – The Alarm task should stop running.
4. Clear the %MISSING variable by clicking the “luggage tag” icon.
5. Find the %MISSING variable in the list and press it’s row.
6. Click the “Clear” row.
7. Confirm the variable clearing.
That’s it. You should be all set.
Author’s final word: I wish you, that you will never have to use these tasks…
Aviad Raviv, is an agile IT implementer that has reached the level of "Bankai" and is now working on incorporating the "hollow" side. https://www.facebook.com/Hotfortech
- Published 09/27/11