ESP8266结合点灯科技实现远程WIFI网络唤醒计算机

Blinker app添加按钮,点击后发送消息到官方的mqtt,ESP收到消息后触发事件发送魔术包到PC唤醒

win10 PC设置 (我是华硕hero iv)

  1. 网卡设置为可被魔术包唤醒
  2. 关闭快速启动
  3. bios中:高级电源设置中的由PCI-E/PCI为开启;启动项-CSM中,开启csm,然后启动设备控制为UEFI,其他的均设置为:UEFI驱动设备优先

esp代码如下:

#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中添加的按钮的“数据键名”相同

原文链接:https://blog.csdn.net/a1092484359/article/details/108992592?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165277097916781685374034%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=165277097916781685374034&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-30-108992592-null-null.nonecase&utm_term=%E7%A7%91%E6%8A%80

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发
头像
文明发言,共建和谐米科社区
提交
头像

昵称

取消
昵称表情图片