Wake On Lan using an ESP32 Telegram bot

I wanted a simple and reliable way to turn on my PC from anywhere without having to choose one of the following:

  • Port Forwarding: As most consumer routers don’t support forwarding broadcast packets, this would imply having to make a DHCP reservation for the device that needs waking up so that the local IP will not change. Also, in case of internet connections with dynamic IP, a DDNS service would be required.

  • Local Server: This would require having to maintain a small local server like a Raspberry Pi and having it powered on 24/7. They don’t consume much power but it’s overkill and if you run them from an SD card it often gets corrupted.

I wanted something reliable that I could quickly setup and then mostly forget about it. The solution I came up with was to host a simple Telegram Bot on an ESP32 board, it will:

  1. Connect to the local network via WiFI
  2. Wait for the /wol command on Telegram
  3. Broadcast the Wake-on-Lan packet on the local network

💵 The power consumption is very low, less than half a watt, so you can keep it running for about 1$ in electricity per year.


It keeps working if I buy a new router, it does not depend on my public or local IP staying the same and I don’t have to keep a linux server running for such a simple task.

The sketch

I am using an ESP32 board called M5Atom, it is pretty small and can be powered by USB type-c. It’s a pretty simple project, so I am using the Arduino IDE for ease of use.

The code should be pretty simple to understand and can be found on my Github at https://github.com/daniele-salvagni/wol-bot-esp32

⚙️ Configuration

In orfer to compile, the following extra libraries can be installed from the Library Manager:

// WiFi configuration
#define WIFI_SSID "<wifi-network-name>"
#define WIFI_PASS "<wifi-password>"

// MAC address of the target device
#define MAC_ADDR "00:00:00:00:00:00"

// Telegram Bot Token
#define BOT_TOKEN  "<telegram-bot-token-id>"
#define ALLOWED_ID "<id-for-the-allowed-user>"

Then you just need to fill your WiFi configuration and MAC Address, your Telegram bot token and your Telegram User ID so no one else can use the bot. You can use @Botfather to create a new bot and @userinfobot to get your ID.

🔎 Usage

  • Use /start to get a list of the available commands
  • Use the /wol command or press the physical button to turn on your PC
  • Use the /ping command to check if the bot is online

Telegram Bot

Enabling Wake on Lan

Most motherboards support the “Wake-on-Lan” (WOL) function. This works by sending a packet of data called a “Magic Packet”. When this packet is received by the target macine, its network interface wakes up the rest of the computer.

The magic packet consists of the following parts:

  • Header: 6 Bytes which is nothing but 6 bytes of 0xff.
  • Data: 16*6 Bytes, the MAC Address of the target device repeated 16 times.
  • Password: Some clients require 6 extra Bytes containing a password known as SecureOn.

This feature usually needs to be enabled from both the BIOS and the operating system of the PC/server you want to wake up.

Here is a screenshot of the setting in my BIOS:

Asus ROG Strix Wake-on-Lan

To enable Wake-on-Lan on Windows you can go to Device Manager => Network Adapters => Properties. Then enable “Wake on Magic Packet” in the Advanced tab and check “Only allow a magic packet to wake the computer” in the Power Management tab.

“Fast Startup” also needs to be disabled (Power Options => “Choose what the power buttons do”) as it will conflict with this feature.

Disable Fast Startup in Windows 11

🐛 Debugging with Wireshark

If you encounter any issues you can use Wireshark and filter for WOL packets to check what’s going wrong.

✅ TODO List

  • Refactor code
  • Store network configuration in EEPROM
  • Add configuration commands to Telegram bot

Made with ❤ and #Code