Advertisement
chrisdaloa

test_uipe

Dec 11th, 2017
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.01 KB | None | 0 0
  1. #define UIPETHERNET_CONF_H
  2. #define UIP_SOCKET_NUMPACKETS    2
  3. #define UIP_CONF_MAX_CONNECTIONS 1
  4. #define UIP_CONF_UDP             0
  5. #define UIP_CONF_BROADCAST       0
  6. #define UIP_CONF_UDP_CONNS       0
  7. #define UIP_ATTEMPTS_ON_WRITE    -1
  8. #define UIP_CONNECT_TIMEOUT      -1
  9. #define UIP_PERIODIC_TIMER       250
  10. #define UIP_CLIENT_TIMER        -1
  11. #define UIP_CONF_IPV6            0
  12. #define UIP_UDP                  0
  13.  
  14. #define MYIPMASK
  15. #define DEBUG
  16. #define ENC28J60_CONTROL_CS 53
  17. #include <Arduino.h>
  18. #include <UIPEthernet.h>
  19.  
  20. #define MACADDRESS    0xDE,0xAD,0xBE,0xEF,0xFE,0xED
  21. #define MYIPBASEADDR  172,19,15
  22. #define MYIPADDR      MYIPBASEADDR,120
  23.  
  24. #define MYIPMASK      255,255,255,0
  25. #define MYDNS         MYIPBASEADDR,254
  26. #define MYGW          MYIPBASEADDR,254
  27.  
  28. #define LISTENPORT    5025
  29. #define UARTBAUD 115200
  30. char line_buffer[20];
  31.  
  32. EthernetServer server(LISTENPORT);
  33.  
  34. void setup(void)
  35. {
  36.   uint8_t mac[6]    = {MACADDRESS};
  37.   uint8_t myIP[4]   = {MYIPADDR};
  38. #ifdef MYIPMASK
  39.   uint8_t myMASK[4] = {MYIPMASK};
  40.   uint8_t myDNS[4]  = {MYDNS};
  41.   uint8_t myGW[4]   = {MYGW};
  42. #endif
  43.  
  44.   Serial.begin(UARTBAUD);
  45.   Serial.print("Setup");
  46.  
  47. #ifdef MYIPMASK
  48.   Ethernet.begin(mac, myIP, myDNS, myGW, myMASK);
  49. #else
  50.   Ethernet.begin(mac, myIP);
  51. #endif
  52.   server.begin();
  53. }
  54.  
  55.  
  56. void loop(void)
  57. {
  58.   int            attempt = 3;
  59.   EthernetClient client = server.available();
  60.  
  61.   Serial.println(F("loop"));
  62.   // check for new tcp-packet:
  63.   if (client)
  64.   {
  65.     while (client.connected())
  66.     {
  67.       if (client.available())
  68.       {
  69.         int     read_length = sizeof(line_buffer);
  70.         size_t  len = 10;
  71.  
  72. #ifdef DEBUG
  73.         Serial.println(F("-> New Connection"));
  74. #endif
  75.         line_buffer[0]  = 0;
  76.         len = client.read((uint8_t *)line_buffer, read_length);
  77. #ifdef REMOVE_N // remove "\r\n" or " \n"
  78.         len -= 2;
  79. #endif
  80.         line_buffer[len] = 0;
  81.  
  82. #ifdef DEBUG
  83.         Serial.println("Disconnected");
  84.         Serial.flush();
  85. #endif
  86.  
  87.       }
  88.     }
  89.     client.stop();
  90.   }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement