2009年11月23日

arduino WOL Repeater

UPDATED FOR THE LATEST VERSION OF ARDUINO IDE I made a "arduino WOL Repeater" with ethernet shield. You can turn on your PCs from out side of your network. The arduino WOL Repeater will forward magic packet to any PCs in your network. It is using bjoern / arduino_osc Library for UDP. I am using "sndmagic version 0.2" to send a magic packet from outside of network. You can get "sndmagic" following website: http://www.st.rim.or.jp/~yumo/pub/sndmagic_chglog.html If you have got other software, please change the value of localPort.
// Wake On Lan ( MagicPacket ) Repeater
// http://yutakalifenet.up.seesaa.net/html/wolRepeater.html
#include <WString.h>
#include <Ethernet.h>
#include <UdpRaw.h>

// ETHERNET CONFIGURATION
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };    // MAC address
byte ip[] = { 192, 168, 1, 200 };    // Arduino IP address
byte gw[] = { 192, 168, 1, 1 };        // Gateway IP address
int localPort = 7;                    //local port to listen on

// set this value like "x.x.x.255"
byte targetIp[] = { 192, 168, 1, 255};
int targetPort = 8000;

#define MAX_SIZE 192            
// maximum packet size
byte packetBuffer[MAX_SIZE];    // buffer to hold incoming packet
int packetSize;                    // holds received packet size
byte remoteIp[4];                // holds recvieved packet's originating IP
unsigned int remotePort;        // holds received packet's originating port

int i;

void setup() {

    Ethernet.begin(mac,ip,gw);
    UdpRaw.begin(localPort);
    Serial.begin(38400);

}

void loop() {

    // if there's data available, read a packet
    if(UdpRaw.available()) {
    packetSize = UdpRaw.readPacket(packetBuffer,MAX_SIZE,remoteIp,(uint16_t *)&remotePort);

    Serial.print("Received packet of size ");
    Serial.println(abs(packetSize));

    Serial.print("From IP ");
        for(i=0; i<3; i++) {
            Serial.print(remoteIp[i],DEC);
            Serial.print(".");
        }
    Serial.print(remoteIp[3],DEC);

    Serial.print(" Port ");
    Serial.println(remotePort); 

    if(packetSize < 0) {
        // if return value <0 the packet was truncated to fit into our buffer
        Serial.print("ERROR: Packet was truncated from ");
        Serial.print(packetSize*-1);
        Serial.print(" to ");
        Serial.print(MAX_SIZE);
        Serial.println(" bytes.");
    }

    Serial.println("Contents:");
    for(i=0; i<min(MAX_SIZE,abs(packetSize)); i++) {
        Serial.print(packetBuffer[i],HEX);
        Serial.print(" ");
    }
    Serial.println("");

    // send a magic packet
    UdpRaw.sendPacket(packetBuffer,packetSize,targetIp,targetPort);
    Serial.println("Start port forwarding to broadcast address:");
        for(i=0; i<3; i++) {
            Serial.print(targetIp[i],DEC);
            Serial.print(".");
        }
    Serial.print(targetIp[3],DEC);
    Serial.println("");
    Serial.println("Done!");
    }
    // wait a bit
    delay(10);

}
タグ:WOL Repeater
posted by love4nature at 00:00| Comment(2) | arduino | このブログの読者になる | 更新情報をチェックする
この記事へのコメント
hi

great article!
thank's for the useful tips!
I'm a newby in arduino's world...I may use this one day! there's so much things to make with arduino!

ありがとう

(Arigato)
Posted by nicolas at 2010年09月09日 23:35
Thanks for your comment
I bought some electronic parts for making somethings with arduino. but not enough time to do it.
Im sure to do it one day.
どういたしまして
Posted by love4nature at 2010年10月14日 05:00
コメントを書く
お名前:

メールアドレス:

ホームページアドレス:

コメント:

認証コード: [必須入力]


※画像の中の文字を半角で入力してください。
×

この広告は1年以上新しい記事の投稿がないブログに表示されております。