主要就是用WOL的库
在Arduino的库管理器搜索wol
第一个就是
下面直接放点灯源码
#define BLINKER_WIFI
#include <WiFiUdp.h>
#include <WakeOnLan.h>
WiFiUDP UDP;
WakeOnLan WOL(UDP);
#include <Blinker.h>
char auth[] = "key";
// 编写:1812z 这里需要改
char ssid[] = "ssid";
char pswd[] = "password";
void wakeMyPC() {
const char *MACAddress = "E0:3F:49:7A:92:EE";
//上面改mac地址
WOL.sendMagicPacket(MACAddress); // Send Wake On Lan packet with the above MAC address. Default to port 9.
// WOL.sendMagicPacket(MACAddress, 7); // Change the port number
}
BlinkerButton Button2("BUTTON_2");
void button2_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
if (state == BLINKER_CMD_BUTTON_TAP) {
BLINKER_LOG("Button tap!");
wakeMyPC();
}
else{
digitalWrite(LED_BUILTIN, LOW);
Blinker.delay(1000);
digitalWrite(LED_BUILTIN, HIGH);
}
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
Blinker.begin(auth, ssid, pswd);
//wol
WOL.setRepeat(3, 100); // Optional, repeat the packet three times with 100ms between. WARNING delay() is used between send packet function.
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
}
void loop()
{
Blinker.run();
}
源码需要改key,wifi名字和密码,自己电脑mac地址
手机app只要加个按键,数据改BUTTON_2 即可
点击就会让指定电脑开机【如何指定看源码注释】
|