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:

I wanted something reliable that I could quickly setup and then mostly forget about. 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 without any optimization.


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:

The following configuration needs to be updated in the sketch code:

// 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>"

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 control the bot. You can use @Botfather to create a new bot and @userinfobot to get your ID.

Usage

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:

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