Created
June 27, 2014 11:26
-
-
Save companje/485d213eef733dffc8c0 to your computer and use it in GitHub Desktop.
Globe4D Wake-on-LAN Arduino-board
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SPI.h> | |
#include <Ethernet.h> | |
#include <util.h> | |
#include "utility/w5100.h" | |
#include "utility/socket.h" | |
#define MAC 0x80, 0xEE, 0x73, 0x95, 0x81, 0x92 | |
static byte myMAC[] = {0x00, 0x1A, 0x4B, 0x38, 0x0C, 0x5C}; | |
static IPAddress myIP(192,168,15,44); | |
static byte targetIP[] = { 255, 255, 255, 255 }; | |
byte magicpacket[102] = { | |
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | |
MAC,MAC,MAC,MAC,MAC,MAC,MAC,MAC, | |
MAC,MAC,MAC,MAC,MAC,MAC,MAC,MAC | |
}; | |
void setup () { | |
Ethernet.begin(myMAC, myIP); | |
Serial.begin(9600); | |
Serial.println("Globe4D Wake-on-LAN"); | |
Serial.println("waiting 5 seconds..."); | |
delay(5000); | |
if (UDP_RawSendto(magicpacket, 102, 8888, targetIP, 7) != 102) { | |
Serial.println("Error sending WOL packet"); | |
} else { | |
Serial.println("done"); | |
} | |
} | |
void loop() { | |
} | |
//http://www.megunolink.com/downloads/libraries/wake-on-lan/ | |
//http://playground.arduino.cc/Main/ArduinoWaker | |
int UDP_RawSendto(byte* pDataPacket, int nPacketLength, int nLocalPort, byte* pRemoteIP, int nRemotePort) { | |
int nResult; | |
int nSocketId; // Socket ID for Wiz5100 | |
// Find a free socket id. | |
nSocketId = MAX_SOCK_NUM; | |
for (int i = 0; i < MAX_SOCK_NUM; i++) { | |
uint8_t s = W5100.readSnSR(i); | |
if (s == SnSR::CLOSED || s == SnSR::FIN_WAIT) { | |
nSocketId = i; | |
break; | |
} | |
} | |
if (nSocketId == MAX_SOCK_NUM) return 0; // couldn't find one. | |
if (socket(nSocketId, SnMR::UDP, nLocalPort, 0)) { | |
nResult = sendto(nSocketId,(unsigned char*)pDataPacket,nPacketLength,(unsigned char*)pRemoteIP,nRemotePort); | |
close(nSocketId); | |
} else nResult = 0; | |
return nResult; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment