esp8266远程开机,局域网,wake,唤醒,魔术包,开机

Arduino 使用一个esp8266远程电脑开机无需格外的外设,使用魔术包广播功能。

需要配置网卡的唤醒功能,只要是10年内的电脑应该都有这个功能,配置方法具体操作可百度,要改blos的配置 (usb网卡不行,无线网卡不行)

只需要修改自己电脑的mac即可,本来写来给自己方便用的,结果笔记本不支持插网线,台式机试了下可以开机,想要更多功能可以自己扩展。比如:外网开机。语音控制都很简单。 

String mac ="08606E484CAC";//目标电脑主机mac,如:08-60-6E-48-4C-AC 需要去掉:或-

全部代码: 

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <server.h>

#ifndef STASSID
#define STASSID "LingFeng"//wif名称
#define STAPSK  "a12345678"//wif密码
#endif

const char* ssid     = STASSID;
const char* password = STAPSK;
const IPAddress serverIP(255,255,255,255);//广播地址不用修改
String head="FFFFFFFFFFFF";//魔术包头,无需修改
uint16_t port=9;
String mac ="08606E484CAC";//目标电脑主机mac,如:08-60-6E-48-4C-AC 需要去掉:或-

WiFiUDP Udp;
void setup() {
  Serial.begin(115200);

  // We start by connecting to a WiFi network

  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  //连接wif功能
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}


void loop() {
    String stringSound;
    stringSound=head+mac;
    //组包
    for(int i = 0;i<16;i++)
    {
      stringSound+=mac;
    }
    int macLength=stringSound.length() / 2;
    byte byteArray[macLength] = {0};
    hexCharacterStringToBytes(byteArray,stringSound.c_str());
    Udp.beginPacketMulticast(serverIP,port,WiFi.localIP());
    Udp.write(byteArray,102);//发送开机数据包
    Udp.endPacket();//结束发送
    delay(1000);
}
void hexCharacterStringToBytes(byte *byteArray, const char *hexString)
{
    bool oddLength = strlen(hexString) & 1;

    byte currentByte = 0;
    byte byteIndex = 0;

    for (byte charIndex = 0; charIndex < strlen(hexString); charIndex++)
    {
        bool oddCharIndex = charIndex & 1;

        if (oddLength)
        {
            // If the length is odd
            if (oddCharIndex)
            {
                // odd characters go in high nibble
                currentByte = nibble(hexString[charIndex]) << 4;
            }
            else
            {
                // Even characters go into low nibble
                currentByte |= nibble(hexString[charIndex]);
                byteArray[byteIndex++] = currentByte;
                currentByte = 0;
            }
        }
        else
        {
            // If the length is even
            if (!oddCharIndex)
            {
                // Odd characters go into the high nibble
                currentByte = nibble(hexString[charIndex]) << 4;
            }
            else
            {
                // Odd characters go into low nibble
                currentByte |= nibble(hexString[charIndex]);
                byteArray[byteIndex++] = currentByte;
                currentByte = 0;
            }
        }
    }
}

byte nibble(char c)
{
    if (c >= '0' && c <= '9')
        return c - '0';

    if (c >= 'a' && c <= 'f')
        return c - 'a' + 10;

    if (c >= 'A' && c <= 'F')
        return c - 'A' + 10;

    return 0; // Not a valid hexadecimal character
}

  • 4
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

风和技术资料库

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值