/*
* Wake On LAN Example
*/
#include <ESP8266WiFi.h>
#include <WiFiUDP.h>
const char* ssid = "アクセスポイントのSSID";
const char* password = "アクセスポイントのパスワード";
WiFiUDP udp;
// The Broadcast IP address to send the magic packet to.
IPAddress broad_ip(192, 168, 10, 255);
// The targets MAC address to send the packet to
byte mac[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
unsigned int localPort = 8;
// local port to listen on
void sendWOL(IPAddress addr, byte * mac, size_t
size_of_mac) {
byte preamble[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF};
byte i;
udp.beginPacket(addr, localPort);
udp.write(preamble, sizeof(preamble));
for (i = 0; i < 16; i++) {
udp.write(mac, size_of_mac);
}
udp.endPacket();
}
void setup_wifi() {
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Wait for WiFi...");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
void setup() {
delay(1000);
Serial.begin(9600);
setup_wifi();
udp.begin(localPort); //start udp client, not sure
if really necessary.
}
void loop()
{
static int flag=0;
if (flag == 0) {
Serial.println("Sending WOL
Packet...");
sendWOL(broad_ip, mac, sizeof(mac));
flag++;
}
}
|