├── Blinker_WOL.ino └── README.md /Blinker_WOL.ino: -------------------------------------------------------------------------------- 1 | /********************************************** 2 | * ESP32 + ARDUINO + Blinker + XiaoAi 3 | * Remote boot by WOL 4 | * Creater:Faiz 5 | */ 6 | 7 | #define BLINKER_WIFI 8 | #define BLINKER_MIOT_OUTLET 9 | 10 | #include 11 | #include 12 | #include 13 | char auth[] = "xxxxxxxxxx"; //密钥 14 | char ssid[] = "Faiz"; //wifi名 15 | char pswd[] = "xxxxxxxx"; //wifi密码 16 | 17 | //The udp library class 18 | WiFiUDP udp; 19 | 20 | bool oState = false; 21 | BlinkerButton Button1("awaking"); 22 | 23 | //awaking! 24 | void button1_callback(const String & state) 25 | { 26 | BLINKER_LOG("get button state: ", state); 27 | digitalWrite(LED_BUILTIN, HIGH); 28 | delay(50); 29 | digitalWrite(LED_BUILTIN,LOW); 30 | delay(50); 31 | pcawaking(); 32 | digitalWrite(LED_BUILTIN, HIGH); 33 | delay(50); 34 | digitalWrite(LED_BUILTIN, LOW); 35 | delay(50); 36 | digitalWrite(LED_BUILTIN, HIGH); 37 | delay(50); 38 | digitalWrite(LED_BUILTIN, LOW); 39 | delay(50); 40 | } 41 | 42 | 43 | void miotPowerState(const String & state) 44 | { 45 | BLINKER_LOG("need set power state: ", state); 46 | 47 | if (state == BLINKER_CMD_ON) { 48 | BlinkerMIOT.powerState("on"); 49 | BlinkerMIOT.print(); 50 | digitalWrite(LED_BUILTIN, HIGH); 51 | delay(25); 52 | digitalWrite(LED_BUILTIN, LOW); 53 | delay(25); 54 | pcawaking(); 55 | digitalWrite(LED_BUILTIN, HIGH); 56 | delay(25); 57 | digitalWrite(LED_BUILTIN, LOW); 58 | delay(25); 59 | digitalWrite(LED_BUILTIN, HIGH); 60 | delay(25); 61 | digitalWrite(LED_BUILTIN, LOW); 62 | oState = false; //force off!! 63 | } 64 | else if (state == BLINKER_CMD_OFF) { 65 | digitalWrite(LED_BUILTIN, LOW); 66 | 67 | BlinkerMIOT.powerState("off"); 68 | BlinkerMIOT.print(); 69 | 70 | oState = false; 71 | } 72 | } 73 | 74 | void miotQuery(int32_t queryCode) 75 | { 76 | BLINKER_LOG("MIOT Query codes: ", queryCode); 77 | 78 | switch (queryCode) 79 | { 80 | case BLINKER_CMD_QUERY_ALL_NUMBER : 81 | BLINKER_LOG("MIOT Query All"); 82 | BlinkerMIOT.powerState(oState ? "on" : "off"); 83 | BlinkerMIOT.print(); 84 | break; 85 | case BLINKER_CMD_QUERY_POWERSTATE_NUMBER : 86 | BLINKER_LOG("MIOT Query Power State"); 87 | BlinkerMIOT.powerState(oState ? "on" : "off"); 88 | BlinkerMIOT.print(); 89 | break; 90 | default : 91 | BlinkerMIOT.powerState(oState ? "on" : "off"); 92 | BlinkerMIOT.print(); 93 | break; 94 | 95 | } 96 | digitalWrite(LED_BUILTIN, HIGH); 97 | delay(25); 98 | digitalWrite(LED_BUILTIN, LOW); 99 | delay(25); 100 | digitalWrite(LED_BUILTIN, HIGH); 101 | delay(25); 102 | digitalWrite(LED_BUILTIN, LOW); 103 | } 104 | 105 | void pcawaking() 106 | { 107 | int i=0; 108 | char mac[6]={0xXX,0xXX,0xXX,0xXX,0xXX,0xXX}; //mac地址 109 | char pac[102]; 110 | char * Address = "xxx.xxx.xxx.255";//udp adress //群发最后为.255 111 | int Port = 3333;//udp port 112 | //make magicpacket 113 | for(i=0;i<6;i++) 114 | { 115 | pac[i]=0xFF; 116 | } 117 | for(i=6;i<102;i+=6) 118 | { 119 | memcpy(pac+i,mac,6); 120 | } 121 | udp.beginPacket(Address, Port); 122 | udp.write((byte*)pac, 102);//send pac to txbuffer 123 | udp.endPacket();//biubiubiu 124 | } 125 | 126 | void dataRead(const String & data) 127 | { 128 | BLINKER_LOG("Blinker readString: ", data); 129 | 130 | Blinker.vibrate(); 131 | 132 | uint32_t BlinkerTime = millis(); 133 | 134 | Blinker.print("millis", BlinkerTime); 135 | } 136 | 137 | void setup() 138 | { 139 | Serial.begin(115200); 140 | BLINKER_DEBUG.stream(Serial); 141 | 142 | pinMode(LED_BUILTIN, OUTPUT); 143 | digitalWrite(LED_BUILTIN, LOW); 144 | 145 | Blinker.begin(auth, ssid, pswd); 146 | Blinker.attachData(dataRead); 147 | 148 | BlinkerMIOT.attachPowerState(miotPowerState); 149 | BlinkerMIOT.attachQuery(miotQuery); 150 | 151 | Button1.attach(button1_callback); 152 | } 153 | 154 | void loop() 155 | { 156 | Blinker.run(); 157 | } 158 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Blinker-xiaoAi-WOL 2 | Remote boot(WOL) 3 | 4 | #使用ESP32模块以及arduino,实现网络唤醒电脑(WOL) 5 | 6 | #替换BLinker注册生成的密钥,以及WiFi名称以及WiFi密码;替换电脑主机的mac地址以及局域网群发地址(也可以是主机的固定IP地址;若网关为192.168.128.1,则群发地址为192.168.128.255) 7 | 8 | #将控制面板的网络唤醒以及BIOS的网络唤醒选项打开(本人主板为微星B450m迫击炮MAX,BIOS中为打开PCIE唤醒) 9 | --------------------------------------------------------------------------------