Advertisement
chrisdaloa

test nanether ethercard

Dec 10th, 2017
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.70 KB | None | 0 0
  1. // Example of EtherCard usage, contributed by Will Rose, 2012-07-05.
  2.  
  3. #include <EtherCard.h>
  4.  
  5. #define BUF_SIZE 512
  6.  
  7. byte mac[] = { 0x00, 0x04, 0xA3, 0x21, 0xCA, 0x38 };   // Nanode MAC address.
  8.  
  9. uint8_t ip[] = { 172, 19, 15, 100 };          // The fallback board address.
  10. uint8_t dns[] = { 172, 19, 15, 254 };        // The DNS server address.
  11. uint8_t gateway[] = { 172, 19, 15, 254 };    // The gateway router address.
  12. uint8_t subnet[] = { 255, 255, 255, 0 };    // The subnet mask.
  13. byte Ethernet::buffer[BUF_SIZE];
  14. byte fixed;                                 // Address fixed, no DHCP
  15.  
  16. void setup(void)
  17. {
  18.     Serial.begin(57600);
  19.     delay(2000);
  20.  
  21.     /* Check that the Ethernet controller exists */
  22.     Serial.println("Initialising the Ethernet controller");
  23.     if (ether.begin(sizeof Ethernet::buffer, mac, 53) == 0) {
  24.         Serial.println( "Ethernet controller NOT initialised");
  25.         while (true)
  26.             /* MT */ ;
  27.     }
  28.  
  29.     /* Get a DHCP connection */
  30.     Serial.println("Attempting to get an IP address using DHCP");
  31.     fixed = false;
  32.     if (ether.dhcpSetup()) {
  33.         ether.printIp("Got an IP address using DHCP: ", ether.myip);
  34.     }
  35.     /* If DHCP fails, start with a hard-coded address */
  36.     else {
  37.         ether.staticSetup(ip, gateway, dns);
  38.         ether.printIp("DHCP FAILED, using fixed address: ", ether.myip);
  39.         fixed = true;
  40.     }
  41.  
  42.     return;
  43. }
  44.  
  45. void loop(void)
  46. {
  47.     word rc;
  48.  
  49.     /* These function calls are required if ICMP packets are to be accepted */
  50.     rc = ether.packetLoop(ether.packetReceive());
  51.     Serial.print("ether.packetLoop() returned ");
  52.     Serial.println(rc, DEC);
  53.  
  54.     // For debugging
  55.     delay(5000);
  56.  
  57.     return;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement