Can You Wake a Raspberry Pi Remotely? (Wake-On-Lan Guide)

If you click our links and make a purchase, we may earn an affiliate commission. Learn more

I’ve lost count of how many times I wanted to power up my Raspberry Pi from another room, or halfway across town. Whether running a headless Pi for remote backups or keeping a media server off to save energy, I wanted a simple way to wake things up from anywhere. So, I tested a few solutions and put everything I learned into this guide.

Wake-on-LAN (WOL) technology allows a computer to be powered remotely by sending a special network packet called a “magic packet.” While Raspberry Pi lacks the WOL capability, a few workarounds exist to recreate this functionality.

In this guide, I’ll show you how to wake up a Raspberry Pi remotely using a smart plug or an ESP32 and then use that Pi to wake up your main computer or server with WOL. I’ll also share how to control it safely and reliably over the internet.

If you’re new to Raspberry Pi or Linux, I’ve got something that can help you right away!
Download my free Linux commands cheat sheet – it’s a quick reference guide with all the essential commands you’ll need to get things done on your Raspberry Pi. Click here to get it for free!

Why Use Wake-On-Lan

Wake-on-LAN (WOL) is a feature that allows you to remotely wake your computer from a low-powered state by sending a magic packet to it over ethernet. You can achieve this on regular server computers by changing the BIOS and OS settings to enable WOL.

Wake-on-LAN lets you power on your computer remotely. This feature benefits anyone with a home setup who wants to access their system while away and IT professionals who need to perform updates or system administration outside regular working hours.

WOL is a great feature that can help you economize your setup’s power consumption. Unfortunately, Raspberry Pi does not support WOL. The only way to power up a Raspberry Pi is by inserting the USB power cable or using the GPIO.

However, with some creativity, you can create a Raspberry Pi setup that can be switched on remotely. You can then use this device as a hub that sends magic packets to PCs or servers to switch them on.

How to Switch Raspberry Pi on Remotely?

While the Raspberry Pi does not have WOL capabilities, there are a few creative ways to switch on your Raspberry Pi remotely. In this guide, we shall mention two such options.

Using a Smart Switch / Socket

The most straightforward way to switch on your Raspberry Pi remotely is to use a smart switch. Smart switches like this on Amazon allow you to control the power outlet through your mobile device over local Wi-Fi or remotely via the internet.

Something not working as expected?
You can get answers from real experts in minutes.
Get help with your setup

This smart switch lets you power your Raspberry Pi using the charger cable. Since the Raspberry Pi automatically boots on power, you can switch it on and shut it down remotely.

The apparent advantage of this setup is the ease of setup, and I recommend this option for all beginners.

One drawback of this design is that the Raspberry Pi abruptly shuts down whenever you switch off the smart socket. While it is okay to shut down Raspberry Pi abruptly sometimes, it can lead to data corruption if some processes are running.

Using an ESP32 Board (Making Your Own Smart Switch / Socket)

If you are a little more tech-savvy and want to make your smart switch that safely shuts down your Raspberry Pi, you can also do that. To do so, we can use ESP32 with Wi-Fi capabilities to switch on Raspberry Pi.

What You’ll Need

For this project, you will need the following:

Recommended next step
Master Raspberry Pi in 30 Days

If you want a clearer path than jumping from tutorial to tutorial, my book gives you a step-by-step roadmap to really understand your Raspberry Pi.

Check the book here

Wiring Diagram

To enable the remote power on/off functionality, you need to insert an ESP32 and a 5V Relay Module between our power adapter and the Raspberry Pi. To do this, follow this wiring diagram:

As you can see, we have connected the ESP32 and the 5V Relay Module directly to the red wire of the power adapter. However, we have connected the Raspberry Pi through the relay’s normally open (NO) connection.

The control of the Relay Module is connected to the D19 pin of the ESP32, and thus, the relay will be controlled by the ESP32.

Furthermore, we have connected D17 of the ESP32 directly to the GPIO17 of the Raspberry Pi. This allows our ESP32 to communicate with the Raspberry Pi to enable a safe shutdown instead of abrupt power removal (one of the key advantages of this method over the Smart Switch).

To create a circuit with your Raspberry Pi, consider using the Adafruit Prototyping Board to enhance the appearance and organization of your final product.

ESP32 Firmware

The firmware needed for this project has two main components. First, the system must receive commands from your mobile device to the ESP32. Then, based on the commands received, the ESP32 will change the status of the D17 and D19 pins accordingly.

We can set up our ESP32 as an MQTT subscriber to receive commands over the internet. To acquaint yourself with MQTT, read this tutorial on setting up an MQTT Broker on your Raspberry Pi. You can also read this excellent guide on how to set up an ESP32 as an MQTT subscriber.

Once you have familiarized yourself with using MQTT to receive commands remotely, you can use this program to enable your ESP32 to switch on and safely shut down your Raspberry Pi:

// Include necessary libraries
#include <WiFi.h>
#include <PubSubClient.h>

// ---------- Wi-Fi Credentials ----------
const char* ssid = "YOUR_WIFI_SSID";          // Your WiFi SSID
const char* password = "YOUR_WIFI_PASSWORD";  // Your WiFi Password

// ---------- MQTT Broker details ----------
const char* mqtt_server = "test.mosquitto.org"; // Public MQTT broker for testing purposes
const int mqtt_port = 1883;                     // Default MQTT port
const char* mqtt_topic = "raspberrypi/control"; // MQTT topic to subscribe for Raspberry Pi control

// MQTT Client and WiFi Client instances
WiFiClient espClient;
PubSubClient client(espClient);

// ---------- ESP32 GPIO pins ----------
const int relayPin = 19;            // GPIO pin controlling the relay (power to Raspberry Pi)
const int shutdownPin = 17;         // GPIO pin signaling Raspberry Pi to initiate safe shutdown

// ---------- Configurable shutdown time (milliseconds) ----------
unsigned long shutdownWaitTime = 15000; // Default wait time of 15 seconds (can be adjusted remotely)

// ---------- Setup function runs once at startup ----------
void setup() {
  // Start serial communication for debugging
  Serial.begin(115200);

  // Initialize relay pin as OUTPUT
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, LOW);  // Relay OFF initially

  // Initialize shutdown pin as OUTPUT
  pinMode(shutdownPin, OUTPUT);
  digitalWrite(shutdownPin, LOW);  // Initially LOW

  // Connect to Wi-Fi network
  Serial.print("Connecting to WiFi");
  WiFi.begin(ssid, password);

  // Wait until connected to Wi-Fi
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("\nWiFi connected successfully!");

  // Configure MQTT server and callback function
  client.setServer(mqtt_server, mqtt_port);
  client.setCallback(callback);

  // Establish initial connection to MQTT broker
  reconnect();
}

// ---------- MQTT callback function ----------
// This function runs whenever a new message arrives on subscribed topics
void callback(char* topic, byte* message, unsigned int length) {
  String command = "";

  // Convert incoming byte message to a String
  for (int i = 0; i < length; i++) {
    command += (char)message[i];
  }

  Serial.print("Received MQTT command: ");
  Serial.println(command);

  // Process received command
  if (command == "ON") {
    digitalWrite(relayPin, HIGH);  // Turn ON Raspberry Pi power supply
    Serial.println("Raspberry Pi Powered ON");
  }
  else if (command.startsWith("OFF")) {
    Serial.println("Initiating safe shutdown procedure");

    // Check if shutdown wait time is included (format: OFF:time_in_seconds)
    int separatorIndex = command.indexOf(':');
    if (separatorIndex != -1) {
      String waitTimeStr = command.substring(separatorIndex + 1);
      unsigned long waitTimeSec = waitTimeStr.toInt();
      shutdownWaitTime = waitTimeSec * 1000;
      Serial.print("Configured shutdown wait time: ");
      Serial.print(waitTimeSec);
      Serial.println(" seconds");
    }

    // Signal Raspberry Pi for safe shutdown
    digitalWrite(shutdownPin, HIGH);
    delay(500);  // Signal duration of 500ms
    digitalWrite(shutdownPin, LOW);

    // Wait for Raspberry Pi to shut down safely
    Serial.print("Waiting ");
    Serial.print(shutdownWaitTime / 1000);
    Serial.println(" seconds for safe shutdown...");
    delay(shutdownWaitTime);

    digitalWrite(relayPin, LOW);  // Turn OFF Raspberry Pi power supply
    Serial.println("Raspberry Pi Powered OFF");
  }
}

// ---------- Reconnect function for MQTT ----------
// Attempts to reconnect to the MQTT broker if disconnected
void reconnect() {
  while (!client.connected()) {
    Serial.print("Connecting to MQTT broker...");

    // Attempt to connect to the MQTT broker
    if (client.connect("ESP32_Client")) {
      Serial.println("connected");
      client.subscribe(mqtt_topic);  // Subscribe to the control topic
      Serial.println("Subscribed to MQTT topic successfully");
    }
    else {
      Serial.print("Failed, rc=");
      Serial.print(client.state());
      Serial.println(", retrying in 5 seconds");
      delay(5000);  // Wait 5 seconds before retrying
    }
  }
}

// ---------- Main loop function ----------
// Continuously checks MQTT connection and processes incoming messages
void loop() {
  if (!client.connected()) {
    reconnect();  // Reconnect if disconnected
  }
  client.loop();  // Process MQTT events
}

Once you have assembled the complete circuit and uploaded the firmware with the correct configuration to your ESP32, you can turn on and shut down your Raspberry Pi remotely.

Related Tutorials:

Tip: Command lines can be a pain to memorize. I put the essential Linux commands on a printable cheat sheet so you don't have to keep googling them. You can grab the PDF here if you want to save some time.


🛠 This tutorial doesn't work anymore? Report the issue here, so that I can update it!

Still stuck after following this guide? Drop your question in the RaspberryTips Community — real Pi users answer fast. Post your question here.

How to Use Raspberry Pi as Wake-On-LAN Server?

While the Raspberry Pi cannot be awakened using Wake-On-LAN (WOL), it can be used to wake up your server once it has been powered on using the earlier methods. This chain setup allows you to wake up your entire server system remotely.

Setting Up Your Server

Before configuring your Raspberry Pi to send the magic packet, we need to configure the server to be ready to switch on when it receives one.

The first thing we need to do is enable it in your computer’s BIOS. You must enable the Wake On LAN/WLAN settings and disable the Deep Sleep settings. The exact steps to do this will depend upon the manufacturer of your PC/ Server.

Most commonly, you have to press a key like Del or F2 to access the BIOS settings, and then you can change the settings from there.

Next, we need to configure the network drivers to enable WOL. The exact steps depend on the OS your server is running.

Windows Server

If your server is running some version of Windows, you can follow these steps:

  • Open Device Manager and navigate to your network adapter.
  • Right-click and select Properties, navigate to Power Management, and enable “Allow this device to wake the computer” and “Only allow a magic packet to wake the computer.”
  • Navigate to the “Advanced” tab, choose “Energy-Efficient Ethernet”, and disable it.
  • Click “OK” and close the Device Manager.
  • Navigate to “Control Panel” -> “Hardware and Sound” -> “Power Options” -> “Choose what the power button do” and click on “Change settings that are currently unavailable”.
  • Disable “Turn on fast startup” and click “Save changes”.
  • Now, to figure out the MAC address of your Ethernet port, open a command prompt and enter the command:
    ipconfig /all

With these configurations, whenever a magic packet is received on this computer’s LAN port, it automatically switches on your server.

Ubuntu Server

If instead your server is running on Ubuntu or any other Linux OS, you can follow these steps:

  • Open a terminal and enter this command to see all available network adapters and their MAC address:
    ip a
  • Notice the name of the connection and its MAC address.
  • Verify WOL is supported using the command:
    sudo ethtool <Adapter Name> | grep "Wake-on"
  • If the letter ‘g’ is in “Supports Wake-on,” then WOL is supported.
  • Activate WOL using the command:
  • Next, create a service using the command:
    sudo nano /lib/systemd/system/wakeonlan.service
  • We can then enable this service using the command:
    sudo systemctl enable wakeonlan.service

And that is it; we have configured our Ubuntu server to enable WOL.

Tip: Command lines can be a pain to memorize. I put the essential Linux commands on a printable cheat sheet so you don't have to keep googling them. You can grab the PDF here if you want to save some time.

Installing WOL Tool on Raspberry Pi

Having configured our server to wake up when it receives the magic packet, we now need to configure our Raspberry Pi to enable it to send the magic tool. To do so, follow these steps:

  • Make sure your Raspberry Pi is up to date using the following command:
    sudo apt update && sudo apt full-upgrade
  • Install etherwake from the official repository using apt:
    sudo apt install etherwake
  • Now we can send the Magic Packet using the command (replace AA:BB:CC:DD:EE:FF with the actual MAC address of your server PC):
    sudo etherwake -i eth0 AA:BB:CC:DD:EE:FF

That is it; we have installed the WOL tool on our Raspberry Pi. Before proceeding further with the tutorial, I would advise you to test this command with your Raspberry Pi and your server and verify locally that whenever you send this command, your server PC wakes up.

This setup lets you remotely switch on your Raspberry Pi using your ESP32 and MQTT. Then, you can use SSHTailscale or RPIConnect to connect to your Raspberry Pi remotely and wake your Server PC by executing the etherwake command in a terminal.

Combining & Automating Everything

The setup described above is effective, allowing us to remotely wake up our Raspberry Pi and use it to wake up our Server PC. However, we can enhance this by integrating the entire system into a comprehensive product.

We can write a Python script for our Raspberry Pi so that it connects to our MQTT broker and receives commands from our mobile/ laptop when we are away. Using this, we can make a centralized MQTT-based dashboard on our mobile device with one switch for Raspberry Pi and another for each server PC.

For this, I wrote a simple Python program that you can use:

import paho.mqtt.client as mqtt
from wakeonlan import send_magic_packet
import re

# ---------- Configuration ----------
MQTT_BROKER = "test.mosquitto.org"  # Same as ESP32
MQTT_PORT = 1883
MQTT_TOPIC = "raspberrypi/control"

# ---------- Regular expression to validate MAC address ----------
MAC_REGEX = re.compile(r'^WAKE:([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}$')

# ---------- MQTT Callback Functions ----------
def on_connect(client, userdata, flags, rc):
    if rc == 0:
        print("Connected to MQTT Broker!")
        client.subscribe(MQTT_TOPIC)
        print(f"Subscribed to topic: {MQTT_TOPIC}")
    else:
        print(f"Failed to connect, return code {rc}")

def on_message(client, userdata, msg):
    payload = msg.payload.decode().strip()
    print(f"Received MQTT message: {payload}")

    if MAC_REGEX.match(payload):
        mac = payload.split(":", 1)[1]
        print(f"Valid WAKE command received. Sending magic packet to MAC: {mac}")
        send_magic_packet(mac)
    else:
        print("Invalid WAKE command format. Use: WAKE:AA:BB:CC:DD:EE:FF")

# ---------- Setup MQTT Client ----------
client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1,"RaspberryPi_WOL")
client.on_connect = on_connect
client.on_message = on_message

client.connect(MQTT_BROKER, MQTT_PORT, 60)

# ---------- Blocking loop ----------
try:
    print("Starting MQTT loop...")
    client.loop_forever()
except KeyboardInterrupt:
    print("Exiting...")
    client.disconnect()

With this program running on your Raspberry Pi, you can send an MQTT payload through the same MQTT broker. To switch on a server, you can send the payload: WAKE:AA:BB:CC:DD:EE:FF where AA:BB:CC:DD:EE:FF is the MAC address of the server PC you are trying to wake up.

Note: Please be aware of the security considerations associated with this setup. After testing everything, I recommend switching to a private or secure cloud MQTT broker instead of relying on a public one, like the one mentioned in this tutorial.
You can follow this tutorial to set up your own MQTT broker.

Taking it One Step Further

Here are a few ideas to further enhance and improve the project:

  • Add shutdown functionality to remotely power off your Linux or Windows servers using SSH or RPC.
  • Trigger email or Telegram alerts when a server is turned on/off or fails to respond.
  • Track device uptime and availability by periodically pinging each server and displaying status.

By completing this tutorial, you’ve set up your remote control to turn on your Raspberry Pi and home servers while you’re away, allowing you to manage them without keeping them powered on.

Not getting the same result?

Even when you follow every step, small differences in OS version, hardware or config can change the outcome. Instead of wasting time guessing, get help from people who have already fixed the same kind of issue.

Ask your question now
🔒 No risk. Cancel anytime.
  • Get help on your exact issue
  • Access step-by-step videos for tricky setups
  • Browse the website without ads

Similar Posts

Leave a Reply

Community members only
Comments are reserved for RaspberryTips Community members. Join the community to ask questions, get help, and interact with other Raspberry Pi users.

Join the community  or  log in