Raspberry Pi As Wake on LAN Server

129,527

83

12

Introduction: Raspberry Pi As Wake on LAN Server

First of all, this is an updated revision of my previous tutorial. The Raspbian image has changed, and the old version is no longer valid.

What does it do?

You can wake up any PC linked to the Raspberry Pi remotely. It can be done on the local network as well as from the internet. This means you no longer have to keep your PC on, to access the files remotely. You can wake up the PC within seconds when needed, saving a lot of power in the process.

Why?

Running a LAN cable may not always be a feasible solution. If your PC is connected to the internet via WIFI, and the card does not support Wake on LAN, you have no other options of waking up the PC remotely. RPI as WOL server solves this.

How?

The RPI is constantly awake and is able to receive a request to wake the PC through the LAN interface. When the Magic Packet is received by the PC via LAN cable, it wakes up. Simple as that.

What do I need?

You will need the following:

  • a Raspberry Pi with the ethernet port and WIFI connectivity
  • a Raspbian Jessie image
  • an ethernet cable
  • a PC which has a LAN port with Wake On Lan support (most of them)
  • an ethernet cable
  • 10 min of your time

Love the sound of this setup? Follow the www.notenoughtech.com for more. Feel free to connect via Facebook, Twitter or Google+

Step 1: The Setup

The physical set up

I don't think this could be any easier. LAN cable has 2 ends plug one of them to the PC LAN port with WOL support, the other to the Raspberry Pi! Power everything on.

The software setup

Guide 1

If you never connected a Raspberry Pi to the PC - here is a 4 step guide for you (no keyboard, or screen required)

Guide 2

I would recommend you to assign static IP to both interfaces (wlan and eth0) here is a handy guide. It builds on the 4 step guide above.

OTHERWISE...

If you are already connected to the Raspberry PI and have wlan and eth IP static, go to the next step. I do recommend you to check the Guide 2 from this step before going further.

Step 2: Wake on LAN - ENABLED

Depending on the network card that your PC has there are few ways to check that the option is enabled.

BIOS

When computer boots up, hitting Del will boot it into BIOS mode, this is where some of the network cards have additional settings. Check in BIOS for Wake on LAN settings if you are unable to turn it on from Windows.

NETWORK ADAPTERS

Open Network settings and go to Network Adapters list. Select your LAN adapter and click on properties. In the Power management tab you will find options to allow Windows to wake/put to sleep the device and to enable Magic Packet. Make sure all of this is enabled.

ADVANCED

Additional network card settings can be found in the advanced tab. You may see options in regards to the Wake on LAN and Magic Packet. Make sure these are enabled.

Step 3: Raspberry PI Side of Things

If you configured the RPI in the same way as in the Guide 2 (see step 2) your microcomputer will have a link via LAN with the computer but will use the WIFI to connect to the internet.

This is important because we have to force the Magic Packet to go through the eth0 instead of WIFI. The best way to do this is to use the etherwake:

sudo apt-get install etherwake

Once this is installed, you have to go to the PC and note the MAC address of the LAN adapter the RPI is connected to. (click on the details of that connection to reveal the IP and MAC listed as AA:BB:CC:DD:EE:FF in the example ).

the command to wake your PC up is:

sudo etherwake -i eth0 AA:BB:CC:DD:EE:FF

This method requires sudo, but allows you to specify the interface, which is what we need. You will have to issue this command via SSH (or type in terminal) each time you want to wake up the PC.

You could save it also as a bash file (save it as wol.sh):

#!/bin/bash<br>sudo etherwake-i eth0 AA:BB:CC:DD:EE:FF

And open the file with

sudo bash /path/to/file/wol.sh

Step 4: Booting Up From the Internet

You can skip to the next step if you don't need to wake up your PC from outside of your local network. Otherwise, we will need few more things to take care of.

I stressed the static IP for WIFI and LAN for a reason in step 2. This means we can now expose the SSH port on the router and forward it to the RaspberryPI. Sounds complicated? Not really.

Router

You will need access to your router, nowadays most of them have the port forwarding option. Log in to your router *(see router instructions) and find the settings for port forwarding.

You want to forward port 22 (default for SSH, if you changed the port for SSH act accordingly) and forward it to the WIFI IP (you can check the assigned IP by typing ifconfig in terminal). It's advisable to reserve the IP in DHCP settings to make sure no other device will take it when your RPI is offline, you can find this option in most of the routers.

DNS

If your external IP changes often, you will need a DNS to streamline the process. DNS lets you assign a fixed name to the IP address. If your IP address changes, DNS will update the IP (automatically or manually) and you will be able to connect.

I used www.noip.com it's free but requires you to log in every 30 days to continue use of the DNS. Pick your username

youruniquename.ddns.net


and google ''my ip'' to get the current IP if the system is unable to detect it for some reason.

Step 5: The Magic 'one Button' Wake Up (optional)

The examples from the video give you an idea how you could streamline the wake-up process.

The hard way

Open some sort of SSH terminal client ( putty (PC) JuiceSSH (Android) etc) and either sending the command to wake up the PC, or to open our bash script.

The impressive way

Hey you Android user - (sorry Apple lovers, do your own research) ever heard about Tasker ? In short it's an app that lets you do the hard way automatically. Voice controls, mobile buttons, shake to wake you name it.

A plugin named AutoTools will let you send the SSH command to the raspberry. I have a bunch of tutorials on how to use Tasker for awesome things. Here is the beginner's guide. Watch the video 1 and 2 to feel comfortable with the interface.

Create a Task in Tasker, add an action - plugin AutoTools SSH. In the config screen add the details. If you going to use the WOL on local network use the local IP, otherwise use the DNS. The video with a tutorial shows you this part in detail, I will add the task description here:

Wake up PC (24)	
	A1: AutoTools SSH <br>[ Configuration:Server: yourdns.ddns.net<br>Port: 33<br>Username: pi<br>Password: *******<br>Command: sudo etherwake -i eth0 00:00:00:00:00<br>Command Variable: atsshresult <br>Timeout (Seconds):60 ] 

You dont have to worry about the IF condition unless you feel comfortable with the Tasker. Don't add it. (it wont add by default)

Once the task is created (create one for the local network and one for the internet) assign the icons to each task, and then pick a widget (Tasker Task shortcut) to add the button to the screen.

That's all!

Microcontroller Contest 2017

Participated in the
Microcontroller Contest 2017

Be the First to Share

    Recommendations

    • Big and Small Contest

      Big and Small Contest
    • Game Design: Student Design Challenge

      Game Design: Student Design Challenge
    • Make It Bridge

      Make It Bridge

    12 Comments

    0
    Benjamin Loison
    Benjamin Loison

    Tip 7 weeks ago on Step 3

    It would be nice to use new lines or \n in your `pre` instead of <br>.

    0
    JohnS1470
    JohnS1470

    1 year ago

    Vazeelp
    You are not making sense. as "notenoughtech" says, 'same page"
    1. why ping it., if you want it on, just send WOL to it. turn it on.
    2. we don't know what the point of pinging it is. You will get a response as it's on or it's off. Who cares? if you want it on, just turn it on. If you are not sure if it's on or not, and want it on anyway, just send WOL to it and turn it on.
    3.IF you want to turn it OFF, well that's a different thing, depending on the OS it runs.

    0
    raqeebahmed130
    raqeebahmed130

    1 year ago

    Hi mate

    Im a little new to this so was wandering if you could help me out. Is there anyway using the method you have shown above to get tasker to turn on my plex server through raspberry pi? So the plex app launch through tasker sends a secondary wake on lan request to my pc.

    0
    trebory6
    trebory6

    2 years ago

    It unfortunately doesn’t look like the author is answering questions, but my question is if there’s a way to use this over OpenHAB. I’m thinking having to run it in Sudo each time might be a problem.

    0
    notenoughtech
    notenoughtech

    Reply 2 years ago

    I never used an open hub, but if you apply proper permissions and ownership to the script, you can use is without sudo. I moved the setup to nodeRED recently as its easier to handle.
    https://notenoughtech.com/raspberry-pi/alexa-wake-...
    This is the setup I'm using now

    I do reply to comments haha :) (if i don't miss the notification that is)

    1
    StephenR17
    StephenR17

    Question 4 years ago

    I have multiple computers in my house that I want to wake remotely over the internet. All of the computers don't have wifi, they are connected to my router via Ethernet. I want to connect the raspberry pi to the router via Ethernet as well and send a WOL packet remotely over the internet to any one of my computers.

    I have a Plex server on one PC, that I don't want running all the time. I also have a custom built NAS that I don't want tunning all the time. I was wanting to be able to remote into the raspberry pi with TeamViewer (this would eliminate the need for a DNS) or something similiar and then send the WOL packet from the raspberry pi to whichever computer I specify.

    I have had WOL set up before with a DNS configured on my router so that I could send the WOL packet from my phone over the internet. If a person uses a DNS configured on the router, it is unnecessary to even use the raspberry pi, the router does all of the work. I don't want to use a DNS though. I have used an always on computer to remote into with TeamViewer and then wake up my other computers from it, but I don't like wasting the electricity keeping a computer on all the time, that's why I want to use the raspberry pi.

    Is it possible to set up the raspberry pi the way I want and send the WOL packet over the internet without using a DNS or to remote into the raspberry pi via TeamViewer?

    0
    vazeelp
    vazeelp

    5 years ago

    Hello i have i question, the etherwake command works fine, but i wanted to ping a device (about 2-5minutes loop) to it's ip adres (my streamer) and when the ping is good (device online) i wanted to send the command sudo etherwake -i eth0 xx:xx:xx:xx to my nas so it boots up. Can you help me please?

    0
    notenoughtech
    notenoughtech

    Reply 5 years ago

    it feels like a smart script scheduled to run every x min via crontab should do the job.
    Not sure what would be your language of choice for this but there is plenty of examples in python:

    rough idea is to do
    ping
    if png ok do A
    else do wake up

    WakeOnLan for python: https://pypi.python.org/pypi/wakeonlan/0.2.2
    ping examples:
    https://stackoverflow.com/questions/26468640/python-function-to-test-ping

    0
    notenoughtech
    notenoughtech

    Reply 5 years ago

    I'm really confused. If you want to send the WOL command you can do this regardless of the state, if the device is offline it will power up otherwise there will be no changes. Just link the WOL command to whatever script you have that opens the stream app to wake up the stream server automatically each time (even if the device is online)

    0
    vazeelp
    vazeelp

    Reply 5 years ago

    Hi, thx for feedback. my question is how to make that script on the rpi that pings to the streamer it's internal ip.
    And when the streamer is online (ping ok), the script sends the ehterwake command.

    This ping command has to send every 5 min +- to see if the device is online.

    example:

    ping 192.168.1.3 (streamer ip)
    if ping ok goto ehterwake
    if ping nok repeat ping

    i'm not Familiar with making kind of scrips on the rpi, and google does not find anything like this.

    Greetz

    0
    notenoughtech
    notenoughtech

    Reply 5 years ago

    I don't think we are on the same page here. Streamer in question is the device that hosts the content? (like NAS?) if yes there is no need to ping it. Just wake it when you want to access the files (each time). you have to describe the situation of what are you trying to achieve a little better

    0
    vazeelp
    vazeelp

    Reply 5 years ago

    I wanted a ping command for energy savings, so is it possible to make a script that:

    1) the pi check's every 5 minutes if the lan of the the streamer is on.

    2) When i put the streamer on (lan UP on the streamer)

    3) the pi would wake up the nas by WOL command

    Is this possible?