- A+
所属分类:软件分享
Blinker app添加按钮,点击后发送消息到官方的mqtt,ESP收到消息后触发事件发送魔术包到PC唤醒
win10 PC设置 (我是华硕hero iv)
网卡设置为可被魔术包唤醒
关闭快速启动
bios中:高级电源设置中的由PCI-E/PCI为开启;启动项-CSM中,开启csm,然后启动设备控制为UEFI,其他的均设置为:UEFI驱动设备优先
esp代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
#define BLINKER_WIFI #include <Blinker.h> char auth[] = "***********************"; char ssid[] = "ssid"; char pswd[] = "password"; #define BUTTON_1 "OPEN" WiFiUDP Udp; //根据自己的路由器选择子网段的广播地址 #define BROADCAST_ADD "192.168.1.255" //网卡唤醒端口 #define REMOTEPORT 9 //网卡的MAC地址 6个字节 char NETCARD_MAC[6] = {0x2C,0x4D,0x54,0x9E,0xBD,0xAE}; //WOL包 char WOL_Buffer[102]; BlinkerButton Button1(BUTTON_1); //WOL魔术包初始化 void WOL_packet_init() { int i,j; for(i=0;i<6;i++) { WOL_Buffer[i] = 0xFF; } for(i=1;i<17;i++) { for(j=0;j<6;j++) { WOL_Buffer[i*6 + j] = NETCARD_MAC[j]; } } } void WOL_packet_transfer() { Udp.beginPacket(BROADCAST_ADD, REMOTEPORT); Udp.write(WOL_Buffer); Udp.endPacket(); } void button1_callback(const String & state) { digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); BLINKER_LOG("get button state: ", state); if (state == BLINKER_CMD_BUTTON_TAP) { BLINKER_LOG("Button tap!"); WOL_packet_transfer(); Button1.print(); } else { BLINKER_LOG("Get user setting: ", state); } } void dataRead(const String & data) { BLINKER_LOG("Blinker readString: ", data); Blinker.vibrate(); uint32_t BlinkerTime = millis(); Blinker.print("millis", BlinkerTime); } void setup() { Serial.begin(115200); BLINKER_DEBUG.stream(Serial); pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, LOW); Blinker.begin(auth, ssid, pswd); Blinker.attachData(dataRead); Button1.attach(button1_callback); WOL_packet_init(); } void loop() { Blinker.run(); digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); } |
在上面的设置中,只需要设置 auth(点灯提供的设备密钥)、ssid(WIFI名称)、pswd(WIFI密码)、netchard_mac(网卡mac地址,直接替换0x后的英文即可)
特别要注意的是:button_1 的值 要与app中添加的按钮的“数据键名”相同