UIPEthernet library for Arduino IDE, Eclipse with arduino plugin and MBED/SMeshStudio (AVR,STM32F,ESP8266,Intel ARC32,Nordic nRF51,Teensy boards,Realtek Ameba(RTL8195A,RTL8710)), ENC28j60 network chip. Compatible with Wiznet W5100 Ethernet library API. Compiled and tested on Nucleo-F302R8. Master repository is: https://github.com/UIPEthernet/UIPEthernet/

Committer:
cassyarduino
Date:
Mon Jan 02 16:38:07 2017 +0100
Revision:
17:be34a75aa9a7
Parent:
12:aef29fbc4a62
Changes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cassyarduino 0:e3fb1267e3c3 1 /*
cassyarduino 17:be34a75aa9a7 2 * UIPEthernet TCPServer example.
cassyarduino 0:e3fb1267e3c3 3 *
cassyarduino 0:e3fb1267e3c3 4 * UIPEthernet is a TCP/IP stack that can be used with a enc28j60 based
cassyarduino 0:e3fb1267e3c3 5 * Ethernet-shield.
cassyarduino 0:e3fb1267e3c3 6 *
cassyarduino 0:e3fb1267e3c3 7 * UIPEthernet uses the fine uIP stack by Adam Dunkels <adam@sics.se>
cassyarduino 0:e3fb1267e3c3 8 *
cassyarduino 0:e3fb1267e3c3 9 * -----------------
cassyarduino 0:e3fb1267e3c3 10 *
cassyarduino 0:e3fb1267e3c3 11 * This Hello World example sets up a server at 192.168.1.6 on port 1000.
cassyarduino 0:e3fb1267e3c3 12 * Telnet here to access the service. The uIP stack will also respond to
cassyarduino 0:e3fb1267e3c3 13 * pings to test if you have successfully established a TCP connection to
cassyarduino 0:e3fb1267e3c3 14 * the Arduino.
cassyarduino 0:e3fb1267e3c3 15 *
cassyarduino 0:e3fb1267e3c3 16 * This example was based upon uIP hello-world by Adam Dunkels <adam@sics.se>
cassyarduino 0:e3fb1267e3c3 17 * Ported to the Arduino IDE by Adam Nielsen <malvineous@shikadi.net>
cassyarduino 0:e3fb1267e3c3 18 * Adaption to Enc28J60 by Norbert Truchsess <norbert.truchsess@t-online.de>
cassyarduino 0:e3fb1267e3c3 19 */
cassyarduino 0:e3fb1267e3c3 20
cassyarduino 17:be34a75aa9a7 21 #define MACADDRESS 0x00,0x01,0x02,0x03,0x04,0x05
cassyarduino 17:be34a75aa9a7 22 #define MYIPADDR 192,168,1,6
cassyarduino 17:be34a75aa9a7 23 #define MYIPMASK 255,255,255,0
cassyarduino 17:be34a75aa9a7 24 #define MYDNS 192,168,1,1
cassyarduino 17:be34a75aa9a7 25 #define MYGW 192,168,1,1
cassyarduino 17:be34a75aa9a7 26 #define LISTENPORT 1000
cassyarduino 17:be34a75aa9a7 27 #define UARTBAUD 115200
cassyarduino 17:be34a75aa9a7 28
cassyarduino 11:3fb19220d9ec 29 #if defined(__MBED__)
cassyarduino 11:3fb19220d9ec 30 #include <mbed.h>
cassyarduino 11:3fb19220d9ec 31 #include "mbed/millis.h"
cassyarduino 11:3fb19220d9ec 32 #define delay(x) wait_ms(x)
cassyarduino 11:3fb19220d9ec 33 #define PROGMEM
cassyarduino 11:3fb19220d9ec 34 #include "mbed/Print.h"
cassyarduino 11:3fb19220d9ec 35 #endif
cassyarduino 11:3fb19220d9ec 36
cassyarduino 0:e3fb1267e3c3 37 #include <UIPEthernet.h>
cassyarduino 0:e3fb1267e3c3 38 #include "utility/logging.h"
cassyarduino 0:e3fb1267e3c3 39
cassyarduino 17:be34a75aa9a7 40 EthernetServer server = EthernetServer(LISTENPORT);
cassyarduino 0:e3fb1267e3c3 41
cassyarduino 11:3fb19220d9ec 42 #if defined(ARDUINO)
cassyarduino 11:3fb19220d9ec 43 void setup() {
cassyarduino 11:3fb19220d9ec 44 #endif
cassyarduino 11:3fb19220d9ec 45 #if defined(__MBED__)
cassyarduino 11:3fb19220d9ec 46 int main() {
cassyarduino 11:3fb19220d9ec 47 #endif
cassyarduino 0:e3fb1267e3c3 48 #if ACTLOGLEVEL>LOG_NONE
cassyarduino 12:aef29fbc4a62 49 #if defined(ARDUINO)
cassyarduino 17:be34a75aa9a7 50 LogObject.begin(UARTBAUD);
cassyarduino 12:aef29fbc4a62 51 #endif
cassyarduino 12:aef29fbc4a62 52 #if defined(__MBED__)
cassyarduino 12:aef29fbc4a62 53 Serial LogObject(SERIAL_TX,SERIAL_RX);
cassyarduino 17:be34a75aa9a7 54 LogObject.baud(UARTBAUD);
cassyarduino 12:aef29fbc4a62 55 #endif
cassyarduino 0:e3fb1267e3c3 56 #endif
cassyarduino 0:e3fb1267e3c3 57
cassyarduino 17:be34a75aa9a7 58 uint8_t mac[6] = {MACADDRESS};
cassyarduino 17:be34a75aa9a7 59 uint8_t myIP[4] = {MYIPADDR};
cassyarduino 17:be34a75aa9a7 60 uint8_t myMASK[4] = {MYIPMASK};
cassyarduino 17:be34a75aa9a7 61 uint8_t myDNS[4] = {MYDNS};
cassyarduino 17:be34a75aa9a7 62 uint8_t myGW[4] = {MYGW};
cassyarduino 0:e3fb1267e3c3 63
cassyarduino 17:be34a75aa9a7 64 // Ethernet.begin(mac,myIP);
cassyarduino 17:be34a75aa9a7 65 Ethernet.begin(mac,myIP,myDNS,myGW,myMASK);
cassyarduino 0:e3fb1267e3c3 66
cassyarduino 0:e3fb1267e3c3 67 server.begin();
cassyarduino 11:3fb19220d9ec 68 #if defined(ARDUINO)
cassyarduino 0:e3fb1267e3c3 69 }
cassyarduino 0:e3fb1267e3c3 70
cassyarduino 11:3fb19220d9ec 71 void loop() {
cassyarduino 11:3fb19220d9ec 72 #endif
cassyarduino 11:3fb19220d9ec 73
cassyarduino 11:3fb19220d9ec 74 #if defined(__MBED__)
cassyarduino 11:3fb19220d9ec 75 while(true) {
cassyarduino 11:3fb19220d9ec 76 #endif
cassyarduino 0:e3fb1267e3c3 77 size_t size;
cassyarduino 0:e3fb1267e3c3 78
cassyarduino 0:e3fb1267e3c3 79 if (EthernetClient client = server.available())
cassyarduino 0:e3fb1267e3c3 80 {
cassyarduino 17:be34a75aa9a7 81 #if ACTLOGLEVEL>=LOG_INFO
cassyarduino 17:be34a75aa9a7 82 LogObject.uart_send_str(F("DATA from Client:'"));
cassyarduino 17:be34a75aa9a7 83 #endif
cassyarduino 0:e3fb1267e3c3 84 while((size = client.available()) > 0)
cassyarduino 0:e3fb1267e3c3 85 {
cassyarduino 12:aef29fbc4a62 86 uint8_t* msg = (uint8_t*)malloc(size+1);
cassyarduino 12:aef29fbc4a62 87 memset(msg, 0, size+1);
cassyarduino 0:e3fb1267e3c3 88 size = client.read(msg,size);
cassyarduino 0:e3fb1267e3c3 89 #if ACTLOGLEVEL>=LOG_INFO
cassyarduino 12:aef29fbc4a62 90 #if defined(ARDUINO)
cassyarduino 12:aef29fbc4a62 91 LogObject.write(msg,size);
cassyarduino 12:aef29fbc4a62 92 #endif
cassyarduino 12:aef29fbc4a62 93 #if defined(__MBED__)
cassyarduino 12:aef29fbc4a62 94 LogObject.uart_send_str(msg);
cassyarduino 12:aef29fbc4a62 95 #endif
cassyarduino 0:e3fb1267e3c3 96 #endif
cassyarduino 0:e3fb1267e3c3 97 free(msg);
cassyarduino 0:e3fb1267e3c3 98 }
cassyarduino 0:e3fb1267e3c3 99 #if ACTLOGLEVEL>=LOG_INFO
cassyarduino 17:be34a75aa9a7 100 LogObject.uart_send_strln(F("'"));
cassyarduino 0:e3fb1267e3c3 101 #endif
cassyarduino 0:e3fb1267e3c3 102 client.stop();
cassyarduino 0:e3fb1267e3c3 103 }
cassyarduino 0:e3fb1267e3c3 104 }
cassyarduino 11:3fb19220d9ec 105 #if defined(__MBED__)
cassyarduino 11:3fb19220d9ec 106 }
cassyarduino 11:3fb19220d9ec 107 #endif