Advanced ESP32 project for sending Wake-on-LAN (WOL) Magic Packets over Wi-Fi, with full MQTT support, OTA updates, ping-based status checks, and a configuration portal hosted on the device using SPIFFS.
This project supports hardware button-triggered WOL, scheduled ping after WOL, OTA updates with MQTT progress reporting, optional factory reset, and the ability to wake up the PC and check its ping from anywhere in the world via MQTT.
- 🌐 Wi-Fi Integration: Connects to your local Wi-Fi network.
- 🖥️ Wake-on-LAN (WOL): Sends n magic packets to wake compatible PCs (n = 10).
- 🔘 User Button WOL: D0 button sends WOL on >1s press.
- 🔘 User command PinOut 1: D4 output LOW or HIGH (Default LOW).
- 🔘 User command PinOut 2: D5 output LOW or HIGH (Default LOW).
- ☁️ MQTT Support:
- Subscribes to
wol/event
for"TurnOn"
,"CheckUpdate"
,"FactoryReset"
,"PingPC"
,"PinOut1On"
,"PinOut1Off"
,"PinOut2On"
or"PinOut2Off"
commands. - publishes logs/status to
wol/log
andwol/status
.
- Subscribes to
- 🔄 Automatic Ping After WOL: Schedules a ping 1min after sending WOL (non-blocking).
- 🕵️ Ping-based Status Check: Uses
ESP32Ping
to verify if the target device is online. - 🔆 LED Indicator: D1 LED flashes to indicate WOL, ping, or OTA progress.
- 💾 OTA Updates: Checks for firmware every 12h; publishes progress to MQTT every 10%.
- 🛠️ Factory Reset: Holding D2 button LOW at boot deletes
config.json
. - 📄 Configuration Portal: Hosts HTML page on SPIFFS to configure Wi-Fi, MQTT, target IP/MAC, and UDP port.
👉 Important: OTA updates only replace the firmware.
- The configuration stored in
/config.json
(set via the WiFi/MQTT portal) is preserved and not modified by the update.
- ESP32-C3 (e.g., Seeed Studio XIAO ESP32-C3 [Tested], DevKitM-1, Lolin C3 Mini)
- ESP32-S3 (DevKit, Seeed Studio XIAO S3, AiThinker modules, etc.)
- ESP32 original (ESP32-WROOM-32, ESP32-WROVER, DevKit V1)
- ESP32-S2 (DevKit, XIAO ESP32-S2, etc.)
- ESP32-PICO-D4 (with 4 MB flash)
Before starting, ensure you have all the tools and libraries correctly installed:
-
Arduino IDE
- Version 1.8.18 recommended ( >2.0 Upload ESP32 DATA don't work).
-
ESP32 Board Manager
- Add URL:
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
- Install ESP32 Boards version 3.3.0 or higher.
- Add URL:
-
Libraries
- ArduinoJson v7.4.2
- PubSubClient
- ESP32Ping
-
Internet Connection
- Required for OTA updates and MQTT.
-
MQTT Broker
- Example: Mosquitto, HiveMQ.
- Note broker IP, port, username, and password.
- Board:
XIAO-ESP32C3
(Seeed Studio) - Partition Scheme: Default 4MB (supports OTA)
- Upload Speed: 921600 (optional)
- Flash Size: 4MB
- SPIFFS
- Store
config.json
andsetup.html
- Upload via ESP32 Sketch Data Upload plugin.
- The
data
folder is used to store files that will be uploaded to the SPIFFS filesystem on the ESP32. - Install the ESP32 Sketch Data Upload plugin for Arduino IDE if not already installed:
- Follow instructions: https://randomnerdtutorials.com/install-esp32-filesystem-uploader-arduino-ide/
- Store
✅ After these steps, your ESP32 is ready for OTA, SPIFFS, JSON configuration, WOL, and MQTT.
Topic | Purpose |
---|---|
wol/event |
Subscribe to "TurnOn" , "CheckUpdate" , "FactoryReset" , "PingPC" , "PinOut1On" , "PinOut1Off" , "PinOut2On" or "PinOut2Off" commands |
wol/status |
Publishes "MQTT Ready" , firmware version, and status messages |
wol/log |
Publishes detailed logs (boot, WOL, ping, OTA) |
- Press Button D0 (>1s) to send WOL magic packet.
- LED flashes during WOL.
- Schedules a ping 1 minutes later to check if PC is online.
- PinOut 1 and PinOut 2 MQTT commands for custom config.
- LED flashes during Commands.
"TurnOn"
: Sends WOL immediately."CheckUpdate"
: Manually trigger an OTA update check."FactoryReset"
: Manually trigger Factory Reset."PingPC"
: Pings the target and publishes online/offline status."PinOut1On"
: Command for D4 output HIGH."PinOut1Off"
: Command for D4 output LOW."PinOut2On"
: Command for D5 output HIGH."PinOut2Off"
: Command for D5 output LOW.
- Checks every 12h or Press Button D2 (only after boot) for new firmware (
version.txt
) on GitHub. - Downloads and flashes firmware directly to OTA partition.
- Publishes progress via MQTT every 10%.
- Reports:
- Download progress
- Flash writing
- Update success or errors
- Device restarts automatically after OTA.
- Hold Button D2 LOW at boot to delete
config.json
. - Device restarts and launches the configuration portal if no config exists.
- LED stay fixed ON
- Hotspot:
WOL_ESP32_Config
if no config file. - HTML page allows:
- Wi-Fi SSID & password
- MQTT server, port, user, password
- Target IP & Broadcast IP
- MAC address for WOL
- UDP port
- Submitting saves config and restarts device.
Portal via browser (http://192.168.4.1).
Or update by ESP32DATA config.json
:
{
"ssid": "YOUR_WIFI",
"password": "YOUR_PASSWORD",
"mqtt_server": "broker.local",
"mqtt_port": 1883,
"mqtt_user": "user",
"mqtt_password": "pass",
"target_ip": "192.168.1.100",
"broadcastIP": "192.168.1.255",
"mac_address": [0xDE,0xAD,0xBE,0xEF,0xFE,0xED],
"udp_port": 9
}
Pin | Function |
---|---|
D0 | User button (send WOL) |
D1 | LED indicator |
D2 | Factory reset / config portal |
D4 | Output LOW or HIGH (MQTT) |
D5 | Output LOW or HIGH (MQTT) |
- Button debounce: >1s press triggers WOL.
- Magic Packet: Broadcast UDP to broadcastIP:udp_port using target MAC.
- MQTT Logs: Full OTA, WOL, and ping progress published to wol/log.
- SPIFFS HTML: setup.html must be uploaded via Arduino IDE or ESP32FS tool.
- Firmware Version: Stored in FIRMWARE_VERSION constant (5.2); OTA compares with version.txt.
- 🌐 Wake on Lan
- 📡 MQTT
- 📴 Shutdown
- Developed for ESP32-C3 with Seeed Studio XIAO board.
- Integrates WOL, MQTT, OTA, and a Wi-Fi configuration portal.
- Ideal for automating PC wake-up and monitoring over Wi-Fi.