Hello
I working on the code below but i can't get it to send the wol packet. any one who help me out?
The purpose for the code is that I connect to arduino with a tcp connection and then I send a command to it fx. "target1" and then i generates a Wol packet based on the mac address and send to the target ip and close the tcp connection. but i think the code breaks before it sends the wol packet.
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
EthernetUDP Udp;
// Enter a MAC address, IP address and Portnumber for your Server below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress serverIP(xxx,xxx,x,xx);
byte gateway[] = { xxx, xxx, xx, xx }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(xxxx); //server port
// TARGET 1
byte targetIp1[] = { xxx, xxx, x, x };
int targetPort1 = x;
byte wolMac1[] = { 0xXX,0xXX,0xXX,0xXX,0xXX,0xXX }; // The target PC Mac Address
// TARGET 2
byte targetIp2[] = { xxx, xxx, x, xx };
int targetPort2 = x;
byte wolMac2[] = { 0xXX,0xXX,0xXX,0xXX,0xXX,0xXX }; // The target PC Mac Address
// Initialize the Ethernet server library
// with the IP address and port you want to use
void setup()
{
// start the Ethernet connection and the server:
Ethernet.begin(mac, serverIP, gateway, subnet);
server.begin();
}
void loop()
{
EthernetClient client = server.available();
if (client) {
char inBuffer[116];
int inCount = 0;
while (client.connected()) {
while (client.available()) {
char ch = client.read();
if(inCount < 31 && ch != '\r' && ch != '\n') {
inBuffer[inCount] = ch;
inCount++;
inBuffer[inCount] = 0;
}
}
byte all[102];
int i,c1,j=0;
for(i = 0; i < 6; i++,j++){
all[j] = 0xFF;
}
for(i = 0; i < 16; i++){
for( c1 = 0; c1 < 6; c1++,j++)
all[j] = wolMac1[c1];
}
//if "target1" received it should generate a wol1 packet and send it to target 1
if(strcmp(inBuffer,"target1") == 0){
Udp.beginPacket(targetIp1,targetPort1);
for(i = 0; i < 102; i++);
Udp.write(all[i]);
Udp.endPacket();
client.println("The power is ON");
}
//if "target2" received it should generate a wol1 packet and send it to target 2
if(strcmp(inBuffer,"target2") == 0) {
Udp.beginPacket(targetIp2,targetPort2);
for(i = 0; i < 102; i++);
Udp.write(all[i]);
Udp.endPacket();
client.println("The power is OFF");
}
if(inCount > 0) {
// send response to client here if you wish
client.println("Closing connection");
delay(2000);
client.stop();
}
}
}
}
Thanks in advance