Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define UIPETHERNET_CONF_H
- #define UIP_SOCKET_NUMPACKETS 2
- #define UIP_CONF_MAX_CONNECTIONS 1
- #define UIP_CONF_UDP 0
- #define UIP_CONF_BROADCAST 0
- #define UIP_CONF_UDP_CONNS 0
- #define UIP_ATTEMPTS_ON_WRITE -1
- #define UIP_CONNECT_TIMEOUT -1
- #define UIP_PERIODIC_TIMER 250
- #define UIP_CLIENT_TIMER -1
- #define UIP_CONF_IPV6 0
- #define UIP_UDP 0
- #define MYIPMASK
- #define DEBUG
- #define ENC28J60_CONTROL_CS 53
- #include <Arduino.h>
- #include <UIPEthernet.h>
- #define MACADDRESS 0xDE,0xAD,0xBE,0xEF,0xFE,0xED
- #define MYIPBASEADDR 172,19,15
- #define MYIPADDR MYIPBASEADDR,120
- #define MYIPMASK 255,255,255,0
- #define MYDNS MYIPBASEADDR,254
- #define MYGW MYIPBASEADDR,254
- #define LISTENPORT 5025
- #define UARTBAUD 115200
- char line_buffer[20];
- EthernetServer server(LISTENPORT);
- void setup(void)
- {
- uint8_t mac[6] = {MACADDRESS};
- uint8_t myIP[4] = {MYIPADDR};
- #ifdef MYIPMASK
- uint8_t myMASK[4] = {MYIPMASK};
- uint8_t myDNS[4] = {MYDNS};
- uint8_t myGW[4] = {MYGW};
- #endif
- Serial.begin(UARTBAUD);
- Serial.print("Setup");
- #ifdef MYIPMASK
- Ethernet.begin(mac, myIP, myDNS, myGW, myMASK);
- #else
- Ethernet.begin(mac, myIP);
- #endif
- server.begin();
- }
- void loop(void)
- {
- int attempt = 3;
- EthernetClient client = server.available();
- Serial.println(F("loop"));
- // check for new tcp-packet:
- if (client)
- {
- while (client.connected())
- {
- if (client.available())
- {
- int read_length = sizeof(line_buffer);
- size_t len = 10;
- #ifdef DEBUG
- Serial.println(F("-> New Connection"));
- #endif
- line_buffer[0] = 0;
- len = client.read((uint8_t *)line_buffer, read_length);
- #ifdef REMOVE_N // remove "\r\n" or " \n"
- len -= 2;
- #endif
- line_buffer[len] = 0;
- #ifdef DEBUG
- Serial.println("Disconnected");
- Serial.flush();
- #endif
- }
- }
- client.stop();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement