Hi friends.
for those want to wake up PC with blynk and esp8266 ( WOL features )
before start please enable WOL or wake on lan feature from your motherboard bios settings. it’s called “wake on lan” or “wake on pcie”
To begin, just replace the values to below sketch:
in line: byte macAddr[6] = {0xf4, 0x6d, 0x04, 0x96, 0xa4, 0xc1}; just replace your PC LAN mac address. for example my mac address is f4:6d:04:96:a4:c1 then the format should be in this form 0xf4, 0x6d, 0x04, 0x96, 0xa4, 0xc1
in line: IPAddress bcastAddr(your, pc, ip, address); just replace your PC LAN ip address like that: for example my ip is 10.5.51.2 then the format should be in this form 10, 5, 51, 2
Note: you can set your broadcast IP address for example 10, 5, 51, 255 but not working on all routers ( like mikrotik or juniper ) it can send the magic packet to all IP address network range with desired mac address.
now on your blynk app add button with virtual pin V1
the sketch:
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <WiFiUdp.h>
#include <SimpleTimer.h>
extern "C" {
#include "user_interface.h"
}
#define MAGIC_PACKET_LENGTH 102
#define PORT_WAKEONLAN 9
WiFiUDP udp;
// Wake On LAN PC MAC address
byte macAddr[6] = {0xf4, 0x6d, 0x04, 0x96, 0xa4, 0xc1};
// LAN Broadcast address
IPAddress bcastAddr(your, pc, ip, address);
byte magicPacket[MAGIC_PACKET_LENGTH];
unsigned int localPort = 9;
SimpleTimer timer;
// Virtual pin number to wake pc
#define APP_BUTTON_WAKEONLAN V1
// Blynk App settings
char auth[] = "your auth token";
char ssid[] = "your ssid";
char pass[] = "your wifi pass";
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
if (udp.begin(localPort) == 1) {
BLYNK_LOG("udp begin OK");
buildMagicPacket();
}
doConnect();
}
void loop()
{
Blynk.run();
timer.run();
}
// Blynk Connect to server
void doConnect()
{
BLYNK_LOG("doConnect start");
bool sts = false;
Blynk.disconnect();
sts = Blynk.connect(10000);
BLYNK_LOG("Blynk.connect=%d", sts);
if (!sts) {
BLYNK_LOG("connect timeout. restarting..");
doRestart();
}
}
// Restart this device
void doRestart()
{
system_restart(); // ESP8266 API
}
// Generate magic packet
void buildMagicPacket()
{
memset(magicPacket, 0xFF, 6);
for (int i = 0; i < 16; i++) {
int ofs = i * sizeof(macAddr) + 6;
memcpy(&magicPacket[ofs], macAddr, sizeof(macAddr));
}
}
// BOOT PC button handler of application
BLYNK_WRITE(APP_BUTTON_WAKEONLAN)
{
//BLYNK_LOG("AppButtonWakeOnLan: value=%d", param.asInt());
udp.beginPacket(bcastAddr, PORT_WAKEONLAN);
udp.write(magicPacket, MAGIC_PACKET_LENGTH);
udp.endPacket();
}
good luck