Hi
I'm using the updated version of the etherShield library by Andrew Lindsay (see http://blog.thiseldo.co.uk/?p=329) and trying to get a very simple wake on lan function working, provided by the EtherShield class. The function in question is es.ES_send_wol, but I'm not having much luck - the code just gets to the function and stops, I get no further output on serial. Here's my code.
/*
* Arduino ENC28J60 Ethernet shield WOL
*/
#include "etherShield.h"
#define SEND_WOL_PIN_PIN 3
#define BUFFER_SIZE 650
#define DATE_BUFFER_SIZE 30
static char datebuf[DATE_BUFFER_SIZE]="none";
static uint8_t buf[BUFFER_SIZE+1];
static uint8_t mymac[6] = {
0x54,0x55,0x58,0x10,0x00,0x25};
static uint8_t pcmac[6] = {
0x00,0x11,0xd8,0xdc,0x3e,0x3a};
static uint8_t myip[4] = {
192,168,168,168};
EtherShield es=EtherShield();
unsigned long lastPress;
void setup(){
pinMode(SEND_WOL_PIN_PIN, INPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
lastPress = millis();
for(int i = 0; i < 20; i++){
digitalWrite(13, HIGH);
delay(35);
digitalWrite(13, LOW);
delay(15);
}
}
void loop(){
//if(digitalRead(SEND_WOL_PIN_PIN) == HIGH && millis() - lastPress > 1000){
Serial.print("Old millis - ");
Serial.println(lastPress);
lastPress = millis();
es.ES_send_wol(buf, pcmac);
Serial.println("WOL packet sent!!");
//}
}
The bits out of the library that strike me as being particularly relevant are below:
#ifdef WOL_client
void EtherShield::ES_send_wol(uint8_t *buf,uint8_t *wolmac) {
send_wol(buf,wolmac);
}
#endif // WOL_client
and...
#ifdef WOL_client
// -------------------- special code to make a WOL packet
// A WOL (Wake on Lan) packet is a UDP packet to the broadcast
// address and UDP port 9. The data part contains 6x FF followed by
// 16 times the mac address of the host to wake-up
//
void send_wol(uint8_t *buf,uint8_t *wolmac)
{
uint8_t i=0;
uint8_t m=0;
uint8_t pos=0;
uint16_t ck;
//
while(i<6){
buf[ETH_DST_MAC +i]=0xff;
buf[ETH_SRC_MAC +i]=macaddr[i];
i++;
}
buf[ETH_TYPE_H_P] = ETHTYPE_IP_H_V;
buf[ETH_TYPE_L_P] = ETHTYPE_IP_L_V;
fill_buf_p(&buf[IP_P],9,iphdr);
buf[IP_TOTLEN_L_P]=0x54;
buf[IP_PROTO_P]=IP_PROTO_ICMP_V;
i=0;
while(i<4){
buf[IP_SRC_P+i]=ipaddr[i];
buf[IP_DST_P+i]=0xff;
i++;
}
fill_ip_hdr_checksum(buf);
buf[UDP_DST_PORT_H_P]=0;
buf[UDP_DST_PORT_L_P]=0x9; // wol=normally 9
buf[UDP_SRC_PORT_H_P]=10;
buf[UDP_SRC_PORT_L_P]=0x42; // source port does not matter
buf[UDP_LEN_H_P]=0;
buf[UDP_LEN_L_P]=110; // fixed len
// zero the checksum
buf[UDP_CHECKSUM_H_P]=0;
buf[UDP_CHECKSUM_L_P]=0;
// copy the data (102 bytes):
i=0;
while(i<6){
buf[UDP_DATA_P+i]=0xff;
i++;
}
m=0;
pos=UDP_DATA_P+i;
while (m<16){
i=0;
while(i<6){
buf[pos]=wolmac[i];
i++;
pos++;
}
m++;
}
//
ck=checksum(&buf[IP_SRC_P], 16+ 102,1);
buf[UDP_CHECKSUM_H_P]=ck>>8;
buf[UDP_CHECKSUM_L_P]=ck& 0xff;
enc28j60PacketSend(pos,buf);
}
#endif // WOL_client
If anyone can think why the program would pause when I invoke ES_send_wol, I'd be very grateful for the insight!
Cheers
Olly