Go Down

Topic: Project Arduino - Wake On Lan your PC over internet (WoL)! (Read 3 times) previous topic - next topic

nathanas

Nov 26, 2012, 10:13 pm Last Edit: Nov 26, 2012, 10:25 pm by nathanas Reason: 1
Hi there,
 I recently bought an Ethernet Arduino Rev3 board and I'm trying to write a sketch so I can Wake up my PC over the internet.
I have the server code ready but I can't find out how to send a magic packet via arduino.

I don't know how to program anything else and I'm frustrated with the Udp protocol.
I've found lots of useful links after lots of hours of searching and testing but none of the codes can be compiled successfully.

I always get a message "Error compiling" when I try to compile the codes. I've tried the sketches on Arduino 023, Arduino 1.0.1 & Arduino 1.0.2 with no luck.
I've added any necessary libraries but still no progress.

Can someone help me by sharing his/her code for sending WoL packets over LAN?
Have in mind that I'll be sharing my final code here, so its not just for me, if you feel like spending some time posting.
Any help would be grateful!

Some of the links I've already tried and are not compiling:
http://www.blueleafsoftware.com/Resources/EmbeddedSand/Wake_on_LAN
http://arduino.seesaa.net/article/134495683.html
http://www.arduino.cc/playground/Main/ArduinoWaker
http://arduino.cc/forum/index.php/topic,93848.0.html
http://code.google.com/p/arduino/source/browse/trunk/libraries/Ethernet/Udp.h?r=1094

Can any of you compile any of the sketches?

nathanas

Can't anyone help me please? I thought it'sbeen an issue for lots of people?

Can anybody please tell me if you can compile the codes given in the links?


dxw00d

The download on the first link compiled ok in IDE 1.0.1.

nathanas

#3
Nov 27, 2012, 01:10 pm Last Edit: Nov 27, 2012, 01:52 pm by nathanas Reason: 1

The download on the first link compiled ok in IDE 1.0.1.

Dear  dxw00d,
can you please tell me what libraries are you using?
Please copy paste all the code from the arduino IDE 1.0.1 sketch and let me know about the libraries you are using.
Are libraries the original ones?

All I can think of is that my Ethernet board is not working properly if you can easily upload the program.

Please send the code that you compiled so I know I don't have any errors when I copy paste or something.

I can see that the <utility/socket.h> library is not highlighted in blue like the others. So I don't think its been recognised.

The code I've trying to upload:
Code: [Select]
#include <SPI.h>
#include <Ethernet.h>
#include <Utility\Socket.h>

void SendWOLMagicPacket(byte * pMacAddress)
{
 // The magic packet data sent to wake the remote machine. Target machine's
 // MAC address will be composited in here.
 const int nMagicPacketLength = 102;
 byte abyMagicPacket[nMagicPacketLength] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
 byte abyTargetIPAddress[] = { 255, 255, 255, 255 }; // don't seem to need a real ip address.
 const int nWOLPort = 7;
 const int nLocalPort = 8888; // to "listen" on (only needed to initialize udp)


 // Compose magic packet to wake remote machine.
 for (int ix=6; ix<102; ix++)
   abyMagicPacket[ix]=pMacAddress[ix%6];

 if (UDP_RawSendto(abyMagicPacket, nMagicPacketLength, nLocalPort,
 abyTargetIPAddress, nWOLPort) != nMagicPacketLength)
   Serial.println("Error sending WOL packet");
}

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;
}


And the errors I get:
Quote

C:\Program Files\arduino-1.0.2\libraries\Ethernet\UdpBytewise.cpp:1: error: stray '\377' in program
C:\Program Files\arduino-1.0.2\libraries\Ethernet\UdpBytewise.cpp:1: error: stray '\376' in program
C:\Program Files\arduino-1.0.2\libraries\Ethernet\UdpBytewise.cpp:51: error: stray '@' in program
C:\Program Files\arduino-1.0.2\libraries\Ethernet\UdpBytewise.cpp:59:4: error: invalid preprocessing directive #i
C:\Program Files\arduino-1.0.2\libraries\Ethernet\UdpBytewise.cpp:61:4: error: invalid preprocessing directive #i
C:\Program Files\arduino-1.0.2\libraries\Ethernet\UdpBytewise.cpp:63:4: error: invalid preprocessing directive #i
C:\Program Files\arduino-1.0.2\libraries\Ethernet\UdpBytewise.cpp:69:4: error: invalid preprocessing directive #i
C:\Program Files\arduino-1.0.2\libraries\Ethernet\UdpBytewise.cpp:71:4: error: invalid preprocessing directive #i
C:\Program Files\arduino-1.0.2\libraries\Ethernet\UdpBytewise.cpp:135: error: stray '#' in program
C:\Program Files\arduino-1.0.2\libraries\Ethernet\UdpBytewise.cpp:187: error: missing terminating ' character
C:\Program Files\arduino-1.0.2\libraries\Ethernet\UdpBytewise.cpp:213: error: missing terminating ' character
C:\Program Files\arduino-1.0.2\libraries\Ethernet\UdpBytewise.cpp:229: error: stray '#' in program
C:\Program Files\arduino-1.0.2\libraries\Ethernet\UdpBytewise.cpp:229: error: missing terminating ' character
C:\Program Files\arduino-1.0.2\libraries\Ethernet\UdpBytewise.cpp:1: error: expected unqualified-id before '/' token
C:\Program Files\arduino-1.0.2\libraries\Ethernet\UdpBytewise.cpp:75: error: expected unqualified-id before '/' token
C:\Program Files\arduino-1.0.2\libraries\Ethernet\UdpBytewise.cpp:99: error: expected unqualified-id before '/' token



dxw00d

#4
Nov 27, 2012, 01:54 pm Last Edit: Nov 27, 2012, 01:57 pm by dxw00d Reason: 1
I clicked on the link at the end of "Here's the source for...", to download the sketch. Unzipped it and opened it in the IDE. The link points to http://www.blueleafsoftware.com/Products/MegunoLink/Downloads/WOLTest.zip.

Colour coding in the IDE is really rather hit and miss. It relies on library developers providing the appropriate information, in the form of a keywords.txt file, in the library directory.

Go Up