Advertisement
Guest User

Untitled

a guest
Aug 26th, 2011
490
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. *
  2.  * Arduino ENC28J60 Ethernet shield Wake-On-Lan client
  3.  * This is just an example client that waits 5s then sends
  4.  * the magic packet out every 60 seconds.
  5.  * In practice, this is only really needs to be sent once.
  6.  *
  7.  */
  8. #include "EtherShield.h"
  9.  
  10. // Please modify the following lines. mac and ip have to be unique
  11. // in your local area network. You can not have the same numbers in
  12. // two devices:
  13. // how did I get the mac addr? Translate the first 3 numbers into ascii is: TUX
  14. static uint8_t mymac[6] = {
  15.   0x54,0x55,0x58,0x10,0x00,0x25};
  16.  
  17. // The arduinos IP address
  18. static uint8_t myip[4] = {
  19.   192,168,1,25};
  20.  
  21. // The mac address of the PC you want to wake u
  22. static uint8_t wolmac[6] = {
  23.   0x01,0x23,0x45,0x67,0x89,0xab};
  24.  
  25. // Packet buffer, must be big enough to packet and payload
  26. #define BUFFER_SIZE 150
  27. static uint8_t buf[BUFFER_SIZE+1];
  28.  
  29. EtherShield es=EtherShield();
  30. uint32_t lastUpdate = 0;
  31.  
  32. void setup(){
  33.  
  34.   // Initialise SPI interface
  35.   es.ES_enc28j60SpiInit();
  36.  
  37.   // initialize enc28j60
  38.   es.ES_enc28j60Init(mymac, 8);
  39.  
  40.   //init the ethernet/ip layer:
  41.   es.ES_init_ip_arp_udp_tcp(mymac,myip, 80);
  42.  
  43.   lastUpdate = millis();
  44.  
  45.   delay(5000);
  46. }
  47.  
  48. void loop(){
  49.   uint16_t dat_p;
  50.  
  51.   while(1){
  52.     // handle ping and wait for a tcp packet
  53.     dat_p=es.ES_packetloop_icmp_tcp(buf,es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf));
  54.  
  55.     if( lastUpdate < (millis() - 60000) ) {
  56.       es.ES_send_wol( buf, wolmac );
  57.       lastUpdate = millis();
  58.     }
  59.   }
  60. }
  61.  
  62. // End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement