Go Down

Topic: Arduino send WOL message (Read 934 times) previous topic - next topic

michu

hey guys

I try to send a Wake on LAN "Magic Packet" with my Arduino Ethernet. This "Magic Packet" is quite easy, 6 x "0xff" then 16 x the mac address, so the payload should be 102 bytes (raw data, without headers). My captured packet is only 38 bytes large, I guess the SENDING buffer is limited.

Here is the code I use:
Code: [Select]

byte broadcastAddress[] = { 255, 255, 255, 255 };    //to verify!

//send wol magic pajet
void WOL(byte mac[]) {
#ifdef USE_SERIAL_DEBUG
 Serial.print("Send WOL... ");
#endif
 
   byte i;
   //Starts a connection to write UDP data to the remote connection, parameter: remoteIP, remotePort
   //Hint about port 7: Since the magic packet is only scanned for the string above, and not actually
   //parsed by a full protocol stack, it may be sent as any network- and transport-layer protocol, although
   //it is typically sent as a UDP datagram to port 7 or 9
   Udp.beginPacket(broadcastAddress, 7);
   
   //Writes UDP data to the remote connection. Must be wrapped between beginPacket() and endPacket().

   //Start of WOL magic paket (preamble)
   for (i=0; i<6; i++) {
     Udp.write(0xff);
   }
   
   //the wol packet contains 16 times the mac address
   //NOTE: BUG here, we cannot send more than 46 bytes...
   for (i=0; i<16; i++) {
     Udp.write(mac, sizeof mac);
   }
   
   //Called after writing UDP data to the remote connection.
   Udp.endPacket();
#ifdef USE_SERIAL_DEBUG
 Serial.println("done!");
#endif
   
}


I took a look at the EthernetUDP class, all I found was a
Code: [Select]
#define UDP_TX_PACKET_MAX_SIZE 24


which is a bit unrelated I guess. Can someone help me?

Cheers

#1
Sep 03, 2012, 03:51 pm Last Edit: Sep 03, 2012, 03:54 pm by countrypaul Reason: 1
Have you checked the contents of the packet that is being sent?
From hte code you posted I can't see how sizeof can return the size of 6 bytes for the mac address as it can only see that it is a byte array that is passed in. Check that size of is giving the right value.

I'm thinking that sizeof may be giving you a sizeof the pointer which I am assuming is 2 bytes on the Arduino.

Paul

Michu,

I used the following code to do what you're trying to do - http://www.blueleafsoftware.com/Resources/EmbeddedSand/Wake_on_LAN

Hope it helps.
Regards,

jfrmilner

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy