Friday, February 6, 2015

Tasker Remote Wake On Lan

This is a followup to my previous post about setting up remote wol.  This time we will use Tasker on Android to send the request to wake up your computer.  So if you have not already set up your network to allow remote wol the read this post first.

Before We begin:

    Word of Warning:
         Both Tasker and the ssh plugin cost money so expect to spend a few dollars to make this work.  But in my mind Tasker is well worth the money and the plugin is about $0.99

    Hardware needed:
        Android smart phone
        Network set up to allow remote wol

    Software needed:
       Tasker
       SSH Tasker Plugin



I am going to show you how to create the task first and then show a few ways to use it.

1.


 Tap on the plus in the bottom right corner



Give the new task a descriptive name



Tap on the plus in the middle of the screen


Tap on Plugin in the lower left of the screen


Scroll down until you find SSH Plugin and tap on it


Tap on the pencil in the top right of the screen



Type in the user name host url or ip address, port number, password and command


It should look something like this.  Tap the floppy disk icon


Your screen should now look something like this.  Tap the Tasker icon in the top left

You are all set!  You should be able to tap the play button and wake up your remote machine


2.) Application
Now that you have the task up and working there are a few applications that I can think of off the top of my head.  First you can make a home screen shortcut on your phone that just runs the task when you click on it.  So you could modify the task to wait for a minute or so after sending the wake up command and then launch Microsoft Remote Desktop App for you or Plex.  Another idea is to turn on your computer as soon as Tasker detects your home wireless network.  That way your computer is already running by the time you walk in the house.  Or if you want to do a nightly backup and you are out of town Tasker can send the command each day at the same time, wake up the computer so it can run the backup(I have a nightly backup script that shuts the computer down after backing up).  That way you don't have to remember to do the back ups or leave your computer on while you are gone.

Remote wake on lan

There are several ways to remotely turn on a computer and this is what I ended up doing because it was the easiest for me at the time.


Before you get Started:

    Word of warning:
       This will only work if you control the network.  If you don't have access to the router that
       directly connects to the modem or public network then you won't be able to make the changes
       needed to accomplish this task.

    Hardware needed:
        public facing router
        always on machine
        computer you want to remotely turn on

    Hardware used:
        Asus RT-N66U router
        raspberry pi model B running raspbian
        Windows 8.1 desktop using an ASUS P8Z68-V PRO/GEN3 motherboard


Brief Overview
So basically what I did was to ssh into my raspberry pi which is always on and then run a wakeonlan command that would turn on my desktop.

1. Static IP address
each router has it's own user interface so it's impossible for me to explain exactly where to go but I can explain generally what you will need to do.  So first you have to be able to log into your router.  You do this by typing in the local ip address of the router in a browser of your choice.  Generally routers use ip addresses like 192.168.1.1 or 192.168.1.0 if you don't know what it is then you can generally look up online the default ip address for your specific router.  You can also look up the default username and password(which I recommend changing).  After you have logged in you will have to start navigating menus looking for wording like reserve dhcp which will generally be located in the LAN area of the menus.  Here you can reserve a specific ip address for a specific mac address.


Reserve an ip address for your always on machine.
At this point you should also look for the MAC address of the machine you want to remotely turn on and make a not of it.
Having a static ip address is very important for the next step port forwarding.

2. Port forwarding
In order to ssh into your raspberry pi you need to forward the ssh traffic through your router and to the pi.  Generally unsolicited traffic is ignored by a NAT router but in this case we want to be able to reach the router over ssh.  To do this we add an exception to the rule.  This is called port forwarding.  ssh by default uses port 22. Port forwarding needs three pieces of information.
    1.) Public port
    2.) private port
    3.) private ip address
For the public port I would recommend using a random port in the upper range of port numbers like 54623.  For the private port I used 22 because using port 22 internally is just fine and that way you don't have to change anything on the always on machine.  For the private ip address use the static one that you assigned to your always on machine in step one.

At this point you need to make sure that you have ssh enabled on your always on machine.  If you are using a raspberry pi you can follow this quick tutorial
http://www.raspberrypi.org/documentation/remote-access/ssh/

3. Install wakeonlan
on the raspberry pi open a terminal and type "sudo apt-get install wakeonlan" and follow any onscreen directions.

4.Configure computer to Wake On LAN(wol)
This is probably the most difficult part of the entire process and unfortunately the part where I can help the least.  So I apologize in advance for throwing you to the winds but the best I can do is give a general idea of what you will need to do.  The first step is changing the BIOS to allow wol.  I would recommend looking up how to do it for your specific model online.  After you have made the Change in the BIOS boot into your OS.  Now you will have to change settings inside the OS to allow WOL as well.  Again I suggest looking up how to do it for your specific OS and Network Interface Card(NIC).  After you have made all of the changes try and see if you can wake up the computer.  Power it off and go to your always on machine, open the command line and type "wakeonlan <MAC ADDRESS> where MAC ADDRESS is the actual mac address of the computer that you want to turn on.  If you did everything correctly then your computer should power on and start to run.  I spent probably about an hour trying different tutorials and chat with tech support before I could get it to work(make sure your drivers are up to date). So all i can say is Keep the Faith brother!  Keep the faith!

5. Putting it all Together
If you have made it this far congratulations!  Now you can test to see if you did everything correctly.  In order to do this yo have to try sshing into your always on machine from outside your LAN.  you can do this from work or a friends house but if it does not work then you will have to wait until you get home to figure out what went wrong.  If you have a smart phone with a data plan I would recommend tethering to it with another computer and trying to ssh into your always on computer and running the wakeonlan command.  If you did everything correctly your computer should fire right up.  Now you can access your computer with RDP or VNC even if you forgot to turn it on before you left or don't want to leave it on all the time.

6. Other thoughts
If you don't have a machine that you can leave on all the time there is still hope.  You actually already have a machine that you leave on all the time.  Your router.  If your router supports the open source firmware dd-wrt you can install it onto your router, ssh directly into your router and then send the wol command.  For more information on this please refer to the offical dd-wrt guide
http://www.dd-wrt.com/wiki/index.php/WOL