Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- #include <ESP8266HTTPClient.h>
- #include <WiFiUDP.h>
- const char* ssid = "SSID";
- const char* password = "HESLO";
- // WOL
- int getDelay = 15000;
- long getTime = 0;
- const byte targetMacAddress[] = { 0x14, 0xDA, 0xE9, 0x29, 0xD3, 0xF4 };
- const byte targetIPAddress[] = { 192, 168, 1, 255 };
- const int targetWOLPort = 9;
- const unsigned int localUdpPort = 12345;
- WiFiUDP Udp;
- void setup() {
- Serial.begin(9600);
- delay(10);
- // Connect to WiFi network
- //Serial.println();
- //Serial.print(F("Pripojuji se k "));
- //Serial.println(ssid);
- WiFi.mode(WIFI_STA);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- //Serial.print(F("."));
- if (millis() > 10000) {
- goto Preskoc;
- }
- }
- //Serial.println("");
- //Serial.println(F("WiFi pripojena"));
- Preskoc:
- // Print the IP address
- //Serial.println(WiFi.localIP());
- }
- void loop() {
- // Načte WOL příkaz z webu
- if (millis() - getTime > getDelay) {
- if (WiFi.status() == WL_CONNECTED) {
- HTTPClient http;
- http.begin("ADRESA ODKUD NACTE POZADAVEK");
- int httpCode = http.GET();
- //Serial.println(httpCode);
- if (httpCode == 200) {
- String data = http.getString();
- //Serial.println(data);
- if (data == "1") {
- sendWOL();
- delay(200);
- }
- }
- http.end();
- }
- getTime = millis();
- }
- }
- void sendWOL() {
- const int magicPacketLength = 102;
- byte magicPacket[magicPacketLength] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
- for (int ix = 6; ix < magicPacketLength; ix++)
- magicPacket[ix] = targetMacAddress[ix % 6];
- Udp.begin(localUdpPort);
- Udp.beginPacket(targetIPAddress, targetWOLPort);
- Udp.write(magicPacket, magicPacketLength);
- Udp.endPacket();
- Udp.stop();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement