JeremyBlum.com

v3.1

Raspberry Pi Remote Wake/Sleep-On-LAN Server

| 331 Comments

A Wake/Sleep-on-LAN Server Powered by a Pi!

A Wake/Sleep-on-LAN Server Powered by a Pi!

Note: This post and the accompanying software packages have been updated several times since this was originally posted. The most up-to-date releases and instructions can always be found in the GitHub Repo. Update notes are appended to the end of this blog post.

I have a very power hungry desktop computer that I use for video editing and large file storage. When I’m travelling with my laptop, I obviously can’t carry all my files and data with me, so I occasionally use “remote desktop” to access my desktop from the road. I also use a Plex Media Server to stream content from my desktop computer. However, the computer has to be on for me to be able to do this. This means I need to leave the computer on all the time, just in case I need to access it. This wastes power, costs me money, and harms the environment. My Raspberry Pi, on the other hand, consumes a minuscule amount of power, and is always on anyways, serving other purposes. In this tutorial, I’ll show you how to run a simple mobile-friendly website from your Raspberry Pi that will allow you to remotely wake up your power-hungry computer, so you can remotely access it. When you’re done, just put it back to sleep from within the remote desktop service (or use the mobile app plus a small background server running on your desktop to put it back to sleep – this is described in the instructions). The app pings the computer from the Raspberry Pi to inform you of when the computer has woken up and established network connectivity. Follow along after the break…

Once you’re done setting up your Pi-Powered Wake/Sleep on LAN Server, here’s how it will work…

  1. From wherever you are in the world, navigate to your unique, dynamically updating URL (wol.example.com)
  2. You’ll be presented with a screen that looks like the one below (note, you may get a security popup first, if you choose to use a self-signed certificate to enable HTTPS – this is described in the instructions). From this screen, you can select which machine you want to control, and you can view its state (awake or asleep). You can add as many machines that you want to control. Here, you can see that “Phoenix Desktop” is currently awake, and I have the option to put it to sleep:
  3. Next, you’ll enter a passphrase that you’ve pre-chosen. If the wrong phrase is entered, a “denial” note will pop up, and you’ll be able to try again. If you enter the right phrase, the Raspberry Pi can send a “Wake Up” or “Sleep” command to the remote machine. It will then ping that computer and display the results in real-time, so that you know when the computer has finished booting or when it has finished going to sleep. Here, you can see what that screen looks like when I put “Phoenix Desktop” to sleep remotely:
  4. You’ll receive a confirmation message when the computer has finished waking up or going to sleep. If you just woke it up, you can now perform normal remote access tasks, like SSH, FTP, or Windows Remote Desktop.

Ready to set this up for yourself? Visit the GitHub Project Wiki to follow the detailed installation instructions.

Updates:

  • 7/20/2013: Added the ability to put the computer back to sleep using the mobile webapp. Instructions updates on the Wiki.
  • 12/15/2013: The app now includes a dropdown that allows you to pick a computer. You can now Wake/Sleep as many computers as you want! Thanks to GitHub user ahodgey for submitting a Pull Request with most of this functionality (I made some updates to his pull request, and merged it into the master repository branch).
  • 09/14/2015: The Raspberry Pi WOL software now supports SSL encryption, meaning you can connect over HTTPS using a self-signed certificate. Additional security measures have also been implemented to reduce the risk of XSS vulnerabilities. Thanks to GitHub user felixrr for the Pull Request! You can still use ordinary HTTP if desired, and updated instructions can be found on the Wiki.
  • 01/24/2015: Software bumped to v2.0. Fixed lots of bugs, and confirmed working latest Raspbian Jessie release, with Apache 2.4.x (which had a bunch of breaking changes).

Supporting Documentation and Code

This project is licensed the GNU GPL v3. Please Attribute and Share-Alike. You can download the source directly from the GitHub Repository linked below.

Get it on GitHub

331 Comments

  1. Doesn’t help…

    • What do the Apache error logs say? They should be located in:
      /var/log/apache2/access.log
      /var/log/apache2/error.log

      Check debug settings in php.ini

      • I’m having the same problems as Ville. Both with or whit out SSL support, I’m getting an empty webpage.

        /var/log/apache2/access.log show no login attempts
        /var/log.apacht2/error.log showed an error (typo I made in /var/www/html/config.php). Fixed the error.

        I searched for php.ini, but that doesn’t exist on my RaspberryPi

        Help is much appreciated being a newby on raspberryPi and linux. Thanks

  2. What is your raspbian and apache version?

    • Server version: Apache/2.4.10 (Raspbian)
      Server built: Jan 23 2016 22:26:49

      Raspbian Jessie Lite
      Minimal image based on Debian Jessie
      Version: November 2015
      Release date: 2015-11-21
      Kernel version: 4.1

  3. Ok, now it works. Added quotes back to lines:

    $APPROVED_HASH = “xxx”;
    $COMPUTER_NAME = array(“xxx”);
    $COMPUTER_MAC = array(“xxx”);
    $COMPUTER_LOCAL_IP = array(“xxx”);

    in the /var/www/html/config.php

  4. Hi,

    Great app! But for some reason the password I have generated is not being accepted by the webpage. I used the website in the config file to generate it but when I enter it in it just says Invalid Passphrase. Request Denied.

    Any ideas why?

    Thanks

  5. Thought I should quickly mention

    As I am a Pi and Linux noob, I wasn’t sure hwo to delve into the inner workings of this project however, I came accross a simple solution to my problem.

    My setup is the Pi connected through wifi to the router, and a crossover cable to my PC. There was no way I could see to determine which network the software was sending the magic packet to, apart from the fact I knew it wasn’t sending it through the ethernet network.

    I could ping both ways through the ethernet connection, and could manually use wakeonlan, but only when I specified the IP address as the broadcast address.

    In my case the command was ‘wakeonlan -i 169.254.255.255 X1:X1:X1:X1:X1:X1:X1’

    which although it seems simple now… took me a little while to try and work out to put the string arguments into the config file, so instead of using just the MAC address as a the only information in the string variable, I used the working complete argument set, hey presto works a treat!

    $COMPUTER_MAC = array(“-i 169.254.255.255 X1:X1:X1:X1:X1:X1:X1”)

    Leave the computer local IP as it should be e.g. 169.254.32.1 as this is used only for pinging (as far as I am aware).

    I thought I should comment as I couldn’t find this information anywhere and it might stump someone as it did me.

    Any other simpler or more robust way to recreate what I have done?

    Cheers
    Ryan

  6. Hi there,

    First of all, great work!!

    So I had been using your WoL page for a while but had an issue with my server and had to reinstall the whole thing, now I tried to reinstall the server and use your page once again but now I have the following error, with or without “https”:

    Forbidden

    You don’t have permission to access / on this server.
    Server unable to read htaccess file, denying access to be safe

    Can you please help me out?

    • YAY, I got it working back again.

      Turns out it was (as the error states) permissions on the files, all the certificate setup is fine.

      To solve it I used my ftp access and changed the permissions on the files and Voilá, it is working again :D

  7. Works ping?
    I am able to wake wakeonlan and mac command, but since the ‘web’ of my dns, always tells me that the system is awake when it is not, and there is no way to respond.
    I saw that the index.php does a ping -c 1 192.168.1.xx and I think the problem is it do not know how to interpret.

    if I run the same ping from the command line tells me 100% loss, which is logical because it is off

    What can happen?

    • I’ve modified the index.php to do it works
      In the $pinginfo comparation with empty ($pinginfo == “” or != “”, i’ve to put this text “1 packets transmitted, 0 packets received, 100% packet loss”.

      Now, it works perfectly!

  8. Hi there.
    I made it work on a banana pi, great tool.

    One question: When I access the website from my cell phone, it nicely writes out step for step what it is doing, e.g. requesting computer state, Ping 1, Ping 2 etc. When I access it from the computer (Windows 8.1, Firefox and IE11) I see no change until the final result is there. Any ideas why?

  9. Just a quick thanks for your hard work and excellent instructions. Got my R Pi 3 this morning, and it’s a working WOL server tonight. Much appreciated.

  10. Hi i am having issues waking my PC, both locally and remotely.

    The WOL server will allow me to sleep the machine just not wake.

    If i try another WOL utility i am able to wake the machine locally.

    Any indication on what i could look at to troubleshoot?

    Thanks

  11. My thx for this Jeremy!

    I can now control everything from home, that’s just great!
    One question though. Is it possible to add an item to the wol page that instead of waking a pc, it just takes me to my router’s home page? I’d like to be able to remotely enable/disable my WLAN through it.

    Thx!

    • Glad to hear you’re enjoying it! There’s a few ways you can do what you’re describing. Most routers have an option for enabling or disabling “remote” administration. Since you’re entering your network from the outside, the easiest option is to enable that (make sure you have a strong router admin password, and enable HTTPS!). It will usually give you the option to specify a port number. 8080 is a common default. Once you enable that, you could edit the WoL index html page to add a link to https://YOUREXTERNALIP:8080. If you are using a dynamic dns service, just replace YOUREXTERNALIP with that: https://myhomeexample.no-ip.com:8080. Make sense?

      • Yes it makes sense, I’ll try it and report back!

        Many thx Jeremy!

      • It works! Indeed, I enabled remote control to the router, set a port and voila! Adding the port to the end of its url, it takes me there instead of the wol page. Once again, many many thx Jeremy!

  12. I had some troubles with this, but not this software in particular. My setup: Raspberry Pi 3 with WiFi connected to router (xxx.xxx.1.109 to xxx.xxx.1.1), Windows 7 PC with WiFi connected to same router (xxx.xxx.1.100 to xxx.xxx.1.1). Then, I have a crossover cable between Pi and PC (xxx.xxx.2.109 to xxx.xxx.2.100, respectively, both set static). When I accessed the web page, the status was correct (showing either asleep or awake). However, wake on LAN magic packets weren’t sending/weren’t waking up the PC.

    I tried running wakeonlan [MAC] directly, but this didn’t work. I then tried wakeonlan -i xxx.xxx.2.100 [MAC], and this didn’t work either.

    Then I tried installing etherwake because I saw some documentation suggested it might work on all Debian-related distros. etherwake [MAC] worked. I considered editing the index.php code to change to etherwake, but then I tried wakeonlan [MAC] which didn’t work, but then wakeonlan -i xxx.xxx.2.100 [MAC] DID work. I thought this was odd, suggesting that wakeonlan was quasi working.

    So I uninstalled etherwake and tried wakeonlan -i xxx.xxx.2.255 [MAC] instead of xxx.xxx.2.100. This worked! I changed the $COMPUTER_MAC to include this in the string prior to the MAC address. It WORKS!

  13. hi there,

    its works perfectly, thx! :-)

    i have a little problem. i have changed the document root to a different diretory. but it seems that the re-routing from HTTP to HTTPS stop working now. HTTPS only ist set to “true”

    thats from the 000-default.conf:

    SSLEngine On
    SSLCertificateFile /etc/letsencrypt/live/XXXX/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/XXXX/privkey.pem

    DocumentRoot /var/www/html/wol

    AllowOverride AuthConfig FileInfo
    Order allow,deny
    allow from all
    Options -Indexes

    anyone a have idea?

    thx! :-)

  14. I finally figured it out :) Is it possibly somehow to shutdown the computer and turn it on again with this tool? The sleep is neat, just wondered if it was possible to shut it down completely and turn it on like the function Teamviewer has. Appreciate it a lot :)

  15. Ohh yeah and furthermore.. I just tried to access my dns from outside my LAN and it times out. There is no problems what so ever when Im on my LAN. What could be the problem here? Port forwarding?

  16. Ohh well actually managed to get it to work! But a few hours after I get the “Command Failed: Connection timed out after 5001 milliseconds”. What could be the problem now? Really was hoping for a stable solution with this WoL :(

  17. Hello Jeremy!

    One more question/request:

    I’ve bought one of those nice wifi controlled power sockets. After sniffing the packets its own custom android app sends for on/off, I managed to have the power socket switched with netcat. My question is, how can I add ie two links to the wol page which will execute the power on/off scripts I’ve made.

    Many thx!

    ps
    I thought I already had submitted this comment a few days back, but somehow my comment didn’t appear.

  18. Yesterday I managed to make it work.
    Today, this is what I get on sleep command: “Command Failed: Connection timed out after 5001 milliseconds”
    And on wake up, it simply doesn’t wake up. Any help?

  19. Great work!

    Helped me a lot because my router doesn’t support WOL or UDP broadcasting.

    Many thanks!

  20. This works brilliantly! I would love to change the array so that it reads from a CSV file instead, any opinions on how to do that? I have a network with around 40 devices I need to Wake up and it would be much easier if I could just keep an Excel spreadsheet with all the Names, Mac and IP of the devices & export to CSV when it changes. The code would then read the CSV instead of adding them all to the config file.

    Thanks

  21. I can get it to work from inside the network by going to my Pi IP of 192.168.1.16 and it loads and can wake up my PC :D

    So I have port forwarded 440 from outside to 443 inside on TCP and UDP to my Pi and typing my externalip:440 refuses to connect

    for example xx.xx.xx.xx:440 wondering if anyone has a solution

    “This site can’t be reached

    [ExternalIPHere] refused to connect.”

    • EDIT:
      I got it working by doing a few things, not sure which one it was
      1.upgraded the PC to be woken from windows 7 to windows 10
      2.changed how the Pi was connecting to my router, before it was via a USB wifi adapter now its ethernet
      3. added the port forwarding rule for 3389 that you had

      I should note that I expected to have to type [ExernalIP]:50 because I had port 50 forwarded to 80 but what actually loads the correct page is [ExernalIP]:80

      Very important right there

      You should specify for the noobs what port to access externally as my router just has two boxes saying start and end for the port numbers. I had no idea if when I forwarded 50 to 80 whether it does anything to the numbers between

  22. thank you. i am a noob in linux but i setup this in minutes.

    thanks!!!!

  23. Hello guys. Im trying to start the SleepOnLan utility before I logon. The reason for this is because I run my plex as a service and that way I dont need to login first.

    I have tried to run SleepOnLan as a service aswell but when I boot up the PC without logging in and tries to shut it down again via the Remote Wake/Sleep-On-LAN I get the error: Command Failed: Connection timed out after 5001 milliseconds. That must be because the SleepOnLan utility isnt running. Any of you who might have stumbled across this? And perhaps found a solution?

    Best regards,
    Mathias

    • I have asked this here before also but then there wasn’t any solution. I also have tried multiple solutions myself like running a task with the Task Manager and various scripts but non of them have worked. Since I have the EXACT same situation as Mathias, I also would be interested with a solution if there have appeared any in mean time.

      Best,
      Marko

      • I have spent a lot of time trying to get sleep on lan to work also – no solution either (assuming you are using Windows). It seems impossible to start it before the Window login prompt.

        • Im about to say Im glad I am not the only one with the problem, but Im not. This shouldnt be rocket science in any way, but I myself am not skilled enough to solve this cracker. What frustrates me is that I have several services running before login with requires a network connection – they run flawlessly.
          SleepOnLan utility just simply wont :/

          • Don’t be frustrated. The fact that this awesome Wake/Sleep solution exists at all is a great thing and we all should be thankful to Jeremy that we can all use it FOR FREE!!! If he or who ever creates/finds a solution for our problems – Great, if not then we’ll just have to live with it or find a better way ow shutting down your PC. No-one has an obligation for developing it further.
            Simple alternative for for our problem – The times when I completely shut down my PC are very rare and if it’s the case I log on with TeamViewer and then the Sleep app works again.

            Best,
            Marko

          • You are right Marko! It indeed is a wonderful tool completely free of charge. And I am not aiming my frustration at the creater more in a direction that my skills are not sufficient.

            I am just hoping that someone might find a solution for this at some point.

            Any of you tried something like NSSM – the Non-Sucking Service Manager, SRVANY or AlwaysUp?

            Regards,
            Mathias

      • Jeremy, any ideas?

    • I personally dont use the sleep on lan much and just use teamviewer, it works from the login screen from boot. Ofc you have to login remotely

  24. Used your WOL for over a year until Router and Pi went out. Now, website says computer asleep, I enter the password, Pings 30 time in 1/2 sec and fails. The computer however DOES wake. Any idea why it isn’t recongnizing computer state and pings out?

  25. Hi, worked great for me, with à bit struggling, as à newbie om the Raspberry. access to me nas from al over the world.
    Juist upgrades to THE new PIXEL-version and now it doesn’t work anymore. All the files are still there …. Anyone who knows this problem.

  26. Hi, I do not have access to router so I can not change port forwarding, and my IP is not public one, so I found-out a different sollution (very primitive) for wake-up pc, using Gdrive mapping:

    https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=164104&p=1060903#p1060903

    May be this can help to others with same limitations.

  27. Thanks a million, this works perfectly.

  28. Love this! Solved my plex sleeping problem! Question: can I edit the .css somewhere? I would love to make the landing page my own. I am simply not familiar enough with the pi yet to find it

  29. I am so salty. I wasted my time doing this installation to find out that you HAVE to use a dynamic DNS service to access the webpage. It makes absolutely no sense that I can’t just input the IP and port into a web browser and it work. I arrived at the part about router config and dyn DNS and my router doesn’t support any free dyn DNS service providers. I’m not going to pay 40 bucks a month for it, so I assumed I could just use the IP like I previously said, so I carried on with the installation. A long time later it was complete and I tested it. It didn’t work.

    I FOUND THE SOLUTION

    Why set up an entire webserver just for one simple task? Why not just freaking SSH into the Pi with some PuTTY-equivalent app (I use “Connect Bot”) and run a one-lined script file.

    A ONE-LINED SCRIPT FILE. FIVE MINUTE SET UP AND DONE.

    ***

    touch wol.sh

    nano wol.sh

    (insert the following into the file and write-out (replace with machine’s MAC))
    wakeonlan 00:00:00:00:00:00

    chmod +x wol.sh

    THEN RUN THE SCRIPT (./wol.sh) >>(of course the target machine has to have the appropriate settings to WOL)

    ***

    (I named each script the hostname of the machine it wakes to distinguish them from each other.)

    I figured this out and thought it so much easier and more worth my time with about the same amount of steps to actually wake a machine as would accessing a web browser and logging in would be. Don’t get me wrong, the web server is a neat idea, but it doesn’t suit me.

    • For the record, you CAN just type your IP and port and it does work like that. The problem is that when your dynamic IP changes, you’ll have to know the new one. So how do you SSH to your Raspberry Pi with Dyn DNS? There’s should be no difference witch solution you use, relating to the IP type. If it doesn’t work then you did something wrong.

      Your router doesn’t have to support free Dyn DNS as long as it supports port forwarding. You can set up your Raspberry Pi to update your Dyn DNS service, like I have done. Just google it. And believe me, when you have it working, it takes exactly two clicks to wake or sleep your computer. I believe your solution takes way more and someone who doesn’t know about SSH and scripting it’s impossible to use.

  30. Hey, I just set this up on my raspberry PI in order to do wake on LAN of other computer’s on my network. This worked like a charm. The install was super easy and the instructions worked beautifully. Thanks for this!

  31. Quick question, and probably a silly one, however could this be exploited to gain entry behind a router? Basically is there any security risk here? From what I can tell the only risk is someone would be able to broadcast to my network and turn on some computers but thats it – Im no security expert however and wanted some opinions.

  32. Could you please remove all comments posted by me?

  33. Hi
    Thanks for going to the effort to help us newbies. I have installed as per your instructions but I can not get the index.php file to display. I made an info.php file to display the php information and this works but the index.php file will not display. Can you point me in a direction where I might find out why and how to fix.
    Thank you

  34. Hello, I’ve got it working for the past few years, with a SSD in windows 7. Now I have a new SSD with windows 10, and even when disabling fast boot, or activationg magic packet in the network card (well, doing same as with windows 7) it doesn’t wake up my comp. when i switch back to my windows 7 SSD, it works again… so the problem comes from windows 10. Any ideas ?

  35. Hi Jeremy,
    first af all merry christmas and….
    many thanks for this easy but powerful program. I’m using this on my Raspberry to start my NAS Server with the WOL command from the internet via a VPN tunnel – It works great since it’s not possible to do a WOL directly trough a VPN tunnel.

    However since you build up the solution using only one and the same password for all, I wonder if you can add the possibility to have several passwords for several people available to start several devices?

    Background: I want to give access to some friends of mine, but when we all use the same password including me, everyone can start everything available and I want to differ.
    For sure, I can ran your program twice behind i.e. a different web- or port adress to seperate but it would be great if the program has this opportunity.

    cheers, Dirk

  36. Hey Jeremy,

    great tutorial. Now I have a question. Is there a possibility to use a password for every computer on its own? I don’t want to use the password of my server for my gaming pc.

  37. I want to set this up to suspend a remote Linux host, but that doesn’t seem to be possible.

Leave a Reply

Required fields are marked *.