BLOG > Raspberry Pi Remote Wake/Sleep-On-LAN Server

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. The V3 Beta release automates most of the setup process, incorporates Dynamic DNS Auto-Updating, and supports signed HTTPS.

I have a very power hungry desktop computer. When I’m travelling with my laptop, I 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 updated 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 self-signed 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).
  • 01/31/2021: An x86 Docker Image is now available for this application (for Desktop, not Raspberry Pi). I have not independently validated its performance, but it pulls directly from my Repo. It’s available on DockerHub here.
  • 02/21/2021: The V3 Beta release automates most of the setup process, incorporates Dynamic DNS Auto-Configuration, and supports signed HTTPS. Follow the V3 Wiki Instructions to install it!

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

383 comments

1 2 3 5
  1. please help me out!! i am facing a lot of trouble in developing a remote desktop display for my raspberry pi.
    and am not able to update my raspberry pi..

  2. Your app is perfect! Thanks

    I can’t see what could be better…. or maybe to be able to wake up more than one device :-)

  3. Hello there,

    I followed all the steps as directed, but When I load the page I only receive a blank webpage, the page loads and the port forwarding is correct. I suspect it has to deal with the program not running correctly on my Pi. Any ideas?

    1. You should enable PHP error printing by putting these lines at the top of your index.php file, in the section:
      error_reporting(E_ALL);
      ini_set(‘display_errors’, ‘1’);

      That should help you figure out what’s wrong.

  4. Thank you very much for your work. I have been thinking about doing something like that for a long time. But due to a lack of time and the fact that I’m not that familiar with linux, webserver and php5, I never got around to actually doing it. But with your work I have a solid starting point and can build on that to make it my own (incl. more than one computer, choosing the kind of “shutdown” and especially using the GPIO to control a relay to cut off the power completely). And for a newbie like me it’s also a good starting point for adding environmental sensors.

    Keep up your good tutorials (I started with your Arduino tutorials :))!

    Michael

      1. I will definitely do that. In the meantime maybe somebody reads this and thinks … “Well, it would be nice to have an Android app for that.” … In would be awesome to have a starting point there as well ;).

  5. I don’t get it. Why so complicated solution ? Why not simply ssh to router and run etherwake ? Rapberry PI is superfluos.

    1. I wanted a dedicated interface for this, and I wanted it to be pretty, with feedback about the current state of the machine. This was mostly a learning exercise for me.

  6. Hi,
    This was an excellent article and me being new to RPi and linux i found this very interesting.
    I followed all the steps closely but when I go to the webpage, my passphrase is always denied.
    Any ideas on what could be the issue and how to fix it?
    Thanks!

  7. This is an amazing article. I have a localised problem, is there anyway to exclude the $COMPUTER_LOCAL_IP from the config. My router seems to block any direct reference to an IP address. I can WOL my PC from an app on my iPad just using the MAC address. Would be grateful if you can help?

    1. Weird. What router are you using? I don’t see how or why it would block direct references to an IP address. What happens if you want to set up file sharing on your network?

  8. This is brilliant. One question though if you don’t mind? I think due to the prescence of another index file (index.html), after I press wake up it returns to the “orignal” index page. Is there a way to repoint this reversion and for example rename index.php to wol.php and have the software acknowledge this?

    Thanks

    Andy

    1. Why not just delete the index.html file? You shouldn’t have two index files, even if they are different file types. If you are using index.html for something else, you can rename this file wol.php, and change the form action to point to wol.php instead of “/”

      1. Hi. As you mention, I am using the index.html file for something else and could do with altering your index.php file really.
        Am I right in saying the reason when I press wakeup it returns to index.html is something in your code? Which would therefore require repointing to (eg) wol.php?
        I am a learner and so any help is much appreciated.

  9. Hi Jeremy,

    I’m stuck with the passphrase. I created a passphrase used the hash calculator to create a hash for the passphrase and copied the hash to the config.php file.

    Restarted the webserver but still getting denied message.

    Any ideas?

    Stefan

    1. Hi Jeremy,

      Got it working. Just re-installed everything and now it works!

      Thanks.

      Stefan

  10. Hi, thaaank you so much! Your stuff is awesome and you inspired me to build a raspberry pi and I’m going to make something awesome with it.. :)

  11. Hello!
    I have problems. I follow the manual and i have no errors in the installation-procedure but i doesnt see any homepage.

    What have i done?
    I also define on my router a portforwarding “port:5000” -> ip-adresse from pi -> to “port:80” (its the same procedure i have made for my ipcam and this portforwarding works – i check this also).
    I enter in my win7-pc in the inet-explorer my “dyndns-adress:5000” but i doesn’t see anything?!

    Is it necessary to start or restart the wake-on-lan-server? and how does this work?
    What are the default ports in this example? 5000? 3389? 80? 7760?

    I hope you can help me!
    Greetings
    Chris

    1. I think i found my failure – i put the hash-code in the file but without the “”! Now i see the site and so i can check this WOL-Server! :)

  12. Hey Jeremy have you any tutorials about doing this with the arduino and ethernet shield. Looking for a good full tutorial but can,t find one online. Keep up the good work very enjoyable.

      1. Thanks for the reply Jeremy. Ah go on make a video for me its something i’ve been looking to do for years and I would really appreciate it. Please !!

  13. On the firt page i always have the error

    Notice: ob_end_flush(): failed to delete and flush buffer. No buffer to delete or flush in /var/www/index.php on line 18

    Any reply was really appreciate.

    Thanks !!!!

    1. Hmmm, that means output buffering isn’t working (this is what allows the page to update as it loads with ping updates).

      try adding the following line to an .htaccess file in the same directory:
      php_value output_buffering “0”

  14. Hi
    I need a bit of help on this!
    Followed all the instructions with no error but when trying to access the start page I get “The page can’t be displayed”.
    Error reporting is enabled in the index.php file (was enabled by default) but I don’t see any errors.
    To check if the webserver and PHP were installed OK I created a simple index.php file which I put in the www directory (temporarily moved the one that came with WOL). This says ‘Welcome …’ and I can access this both from local IP and from my dynamic dyns URL.
    So webserver and php seem to be running.
    Have tried to totally reinstall but still no success.

    Any suggestions greatly appreciated – would love to get this running!
    David

  15. Found my error!
    Managed to find the location of the error log /var/log/apache2/error.log and saw that it was the hash in the config.php file that was causing the problem.
    First I had forgotten to put it in ” ” and then when I did it didn’t become active until I rebooted.
    Working well now – thanks for a great tool!
    David

      1. Oh I thought earlier you said your not sure if you’ll make a video about how to do it on Arduino. So I presumed it was feasible. Thanks anyway

  16. Hmm it seems to work on my LAN, but not outside my LAN.

    I als use the PI al proxy true port 1194 (as many tutorials) so normally i need go to my publicip:1194 ?

  17. can you give a good example of what the config file should look like?

    ie should the mac and ip addresses be in double quotes? single quotes? no quotes?

    Thank you

  18. HI,

    Thanks for this nice solution to remote wake/sleep my server :)

    I installed the php on my synology. The webpage is working well.
    But when i go to the page the webapp tells me the computer is allready awake while its powered off.

    What could be wrong?

    Thx

    1. Sleep-On-Lan works but the webapp thinks its still awake.

      It tells the sleep command succeeded.
      Then pings 10times > Still Awake

      Then i get an FAILED. But my server is a sleep :)

      I think my NIC stays alive. Can this be?

      1. That’s what it seems like. If it says it is awake when it is off, then the ping must be getting a reply, which means the NIC is fully awake. What OS is the server? What kind of computer? You may be able to adjust the sleep settings in the Bios (try lowering it from S1 to S3, for instance).

  19. Jeremy,

    Os is server 2008 r2 on a hp dc 7900 usdt.
    I cant find anything in the bios what could keep the nic awake.

    Thanks 4 your help m8 :)

  20. Jeremy,

    I did some troubleshooting today and i found out that de webapp is saying the pc is awake even when the pc has no power source.

    Any idea?

    1. Ok, well the Raspberry Pi is just running a ping command and checking for a reply. SSH in the the Raspberry Pi, and try pinging the computer’s IP address directly to see what happens. Are you sure you’ve se the right IP for the computer you are trying to wake up?

  21. I’ve been looking for some way to do this literally for years. Some things I noticed though are that with my connection the pings happen so fast that I have to do 100 to be sure the computer reports back that it is up. It would be nice if their were either a delay set between pings, or better, if the pings were just posted over each other (old one erased) so that only one line of text would show up no matter how many pings occurred. I usually get in the 80’s.

    For anyone wanting to wake up more than one computer, the trick is to make several copies of the files on your raspberry pi web server in separate folders and set each one to wake a different computer. It looks like you should be able to put the bootstrap folder one level up to have less duplication if you specify it’s location in thee configuration file. Would be nice though if one of the variables in the configuration file set a title so we could mark which computer was being woken up.

  22. Hey Jeremy,
    Fair play you’ve created a great project.

    I’m just wondering , I’ve 3 different devices and wondering if its possible to add a list to be able to choose which device to power on?

    Thanks

  23. “find the Dynamic DNS (DDNS) updating screen in your router’s administration panel, and enter your account info”

    what do you do if your router doesnt support DDNS? Can you use the Linux no-ip DUC on the RPI?

    1. Yes, that is what I am doing and it works well, although my IP hasn’t changed for a long time even though it is dynamic.

  24. Hello,

    in my var/www directory is still another webinterface. How can I change the Port to a random one? I don’t need to get from net via portforwarding to the Wake on Lan page. My iPhone is connected via VPN, so i want to get via Browser (192.168.x.x/wakeonlan.php) to the landing page, for example.

    Thank You

    Best regards
    Stefan

  25. You don’t need to change the port. Just change the file name from index to something else, like wol.php. The script should still work just fine (this was fixed in a commit about a month ago).

  26. Hello Jeremy,

    nice tool :)! Is it possible to make a cronjob for waking up my Windows pc every week at 02:00 o’ clock pm to make a Backup?

    Thanks!

    Greetings

  27. Hi,

    i thought I can impelment the wake up job into my raspberry pi cron scheduler and when my client is up acronis makes a backup (with a specific schedule) every week for example. Windows task scheduler is not able to start a pc?

    Best regards

    1. Sure, you should be able to do that. Use “crontab -e” to edit the cronjob on your pi. add a line with the desired weekly time, and run the “wakeonlan” command with the right arguments.

  28. Hi Jeremy, first of all excellent work! I installed your wol-server on a raspberry pi using the arm version of arch linux and got it working, with slightly different package names of course. When I start the wol script my server wakes up but isn’t detected as awake. I’m getting 10x still down, so something with the pings isnt working yet. When I ssh into the pi and do a “ping -c 1 computerip” I get this reply:
    PING 192.168.178.35 (192.168.178.35) 56(84) bytes of data.
    64 bytes from 192.168.178.35: icmp_seq=1 ttl=64 time=0.451 ms

    — 192.168.178.35 ping statistics —
    1 packets transmitted, 1 received, 0% packet loss, time 0ms
    rtt min/avg/max/mdev = 0.451/0.451/0.451/0.000 ms

    Any ideas how to solve this?
    Thanks in advance!!
    Johannes

    1. Hmm…. Try confirming that the exec command from PHP is working okay by adding “echo $pinginfo;” after the following line. If nothing shows up, then exec must be failing, and it may have something to do with permissions differences on arch linux.

      $pinginfo = exec(“ping -c 1 ” . $COMPUTER_LOCAL_IP[$selectedComputer]);

  29. Nevermind, figured it out. I replaced the if condition with (strpos($pinginfo,’64 bytes’) == true).

  30. Hi There,

    I made it through your exellent guis, but having trouble getting my computer to sleep. I got the following Error: Fatal error: Call to undefined function curl_init() in /var/www/index.php on line 199

    Could you help me out?

    Thanks a lot!

    Theo

  31. Hi, I am really grateful for your awesome work on this.

    It just works flawlessly, and the tutorial was easy to follow.

    Since I only want to wake (not put to sleep) my PC, is there any way to easily get rid of the Sleep! Button? I messed with the PHP so it doesnt do anything anymore, but the Button remained in place. Also: Is there a way to remove the dropdown menu, since I only use it for my main PC?

    These are more css and html related questions, but if you could help me with what lines to modify I would be so happy :)

    Thanks again!

      1. That’s all I could have asked for. I am new to the wolrd of linux (and github), so thank you for the advice. Working great as of now!

        Have a good weekend!

  32. Hi and thank you for such a nice tutorial.

    I have a problem, maybe you could help?
    My ISP blocks all of the incoming traffic below 1024. But I think your solution listens to port 80? So I’m stuck again by my ISP…

    Is there a way to change that port number so I can access the Pi over WAN?

    Thanks anyway!
    Jelle

  33. Hi Jeremy,
    I’m loving what you’ve done, and the tutorial is awesome I had it up and running really quickly. While I have it working, I still don’t have the full functionality I need.

    I’ll explain my setup – my house uses WiFi for all connections to the router, this complicated any WoL attempts, requiring other ethernet connected hardware. That’s where raspberry Pi comes in to the rescue. I had a my Pi connected to the wifi network, with a direct ethernet connection to the laptop. This worked sometimes, but even with fixed IP on both ends it wasn’t reliable, especially after a few hours off period. Current set up is with a second router/switch. The raspberry pi remains connected to the modem router by WiFi, it is then also connected to the second switch by ethernet. The laptop is also connected by ethernet to the second switch.

    This setup allows me to wake the laptop wirelessly, from my phone. I have a tasker task which switches to the second network and sends the WoL packet. My problem is that I can’t make your WoL Server send the command onto the second network. Sub domains are 192.168.0.XXX and 192.168.254.XXX for networks 1 and 2 respectively. Is it possible for your server to run off one network interface, but send the WoL command out on another?

    Many thanks

    1. Hmmmm….. That may be a bit tricky. The web server is running on only one of the network interfaces. What happens if you run the wakeonlan linux app directly from the shell; does that work?

  34. I keep getting this error when I want to sleep it.

    Fatal error: Call to undefined function curl_init() in /var/www/index.php on line 199

1 2 3 5

Leave a Reply to rdagijones Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Advertisement