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/
examples/TcpServer/TcpServer.ino@12:aef29fbc4a62, 2016-12-29 (annotated)
- Committer:
- cassyarduino
- Date:
- Thu Dec 29 14:09:13 2016 +0100
- Revision:
- 12:aef29fbc4a62
- Parent:
- 11:3fb19220d9ec
- Child:
- 17:be34a75aa9a7
Changes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cassyarduino | 0:e3fb1267e3c3 | 1 | /* |
cassyarduino | 0:e3fb1267e3c3 | 2 | * UIPEthernet EchoServer 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 | 11:3fb19220d9ec | 21 | #if defined(__MBED__) |
cassyarduino | 11:3fb19220d9ec | 22 | #include <mbed.h> |
cassyarduino | 11:3fb19220d9ec | 23 | #include "mbed/millis.h" |
cassyarduino | 11:3fb19220d9ec | 24 | #define delay(x) wait_ms(x) |
cassyarduino | 11:3fb19220d9ec | 25 | #define PROGMEM |
cassyarduino | 11:3fb19220d9ec | 26 | #include "mbed/Print.h" |
cassyarduino | 11:3fb19220d9ec | 27 | #endif |
cassyarduino | 11:3fb19220d9ec | 28 | |
cassyarduino | 0:e3fb1267e3c3 | 29 | #include <UIPEthernet.h> |
cassyarduino | 0:e3fb1267e3c3 | 30 | #include "utility/logging.h" |
cassyarduino | 0:e3fb1267e3c3 | 31 | |
cassyarduino | 0:e3fb1267e3c3 | 32 | EthernetServer server = EthernetServer(1000); |
cassyarduino | 0:e3fb1267e3c3 | 33 | |
cassyarduino | 11:3fb19220d9ec | 34 | #if defined(ARDUINO) |
cassyarduino | 11:3fb19220d9ec | 35 | void setup() { |
cassyarduino | 11:3fb19220d9ec | 36 | #endif |
cassyarduino | 11:3fb19220d9ec | 37 | #if defined(__MBED__) |
cassyarduino | 11:3fb19220d9ec | 38 | int main() { |
cassyarduino | 11:3fb19220d9ec | 39 | #endif |
cassyarduino | 0:e3fb1267e3c3 | 40 | #if ACTLOGLEVEL>LOG_NONE |
cassyarduino | 12:aef29fbc4a62 | 41 | #if defined(ARDUINO) |
cassyarduino | 12:aef29fbc4a62 | 42 | LogObject.begin(9600); |
cassyarduino | 12:aef29fbc4a62 | 43 | #endif |
cassyarduino | 12:aef29fbc4a62 | 44 | #if defined(__MBED__) |
cassyarduino | 12:aef29fbc4a62 | 45 | Serial LogObject(SERIAL_TX,SERIAL_RX); |
cassyarduino | 12:aef29fbc4a62 | 46 | #endif |
cassyarduino | 0:e3fb1267e3c3 | 47 | #endif |
cassyarduino | 0:e3fb1267e3c3 | 48 | |
cassyarduino | 0:e3fb1267e3c3 | 49 | uint8_t mac[6] = {0x00,0x01,0x02,0x03,0x04,0x05}; |
cassyarduino | 0:e3fb1267e3c3 | 50 | IPAddress myIP(192,168,0,6); |
cassyarduino | 0:e3fb1267e3c3 | 51 | |
cassyarduino | 0:e3fb1267e3c3 | 52 | Ethernet.begin(mac,myIP); |
cassyarduino | 0:e3fb1267e3c3 | 53 | |
cassyarduino | 0:e3fb1267e3c3 | 54 | server.begin(); |
cassyarduino | 11:3fb19220d9ec | 55 | #if defined(ARDUINO) |
cassyarduino | 0:e3fb1267e3c3 | 56 | } |
cassyarduino | 0:e3fb1267e3c3 | 57 | |
cassyarduino | 11:3fb19220d9ec | 58 | void loop() { |
cassyarduino | 11:3fb19220d9ec | 59 | #endif |
cassyarduino | 11:3fb19220d9ec | 60 | |
cassyarduino | 11:3fb19220d9ec | 61 | #if defined(__MBED__) |
cassyarduino | 11:3fb19220d9ec | 62 | while(true) { |
cassyarduino | 11:3fb19220d9ec | 63 | #endif |
cassyarduino | 0:e3fb1267e3c3 | 64 | size_t size; |
cassyarduino | 0:e3fb1267e3c3 | 65 | |
cassyarduino | 0:e3fb1267e3c3 | 66 | if (EthernetClient client = server.available()) |
cassyarduino | 0:e3fb1267e3c3 | 67 | { |
cassyarduino | 0:e3fb1267e3c3 | 68 | while((size = client.available()) > 0) |
cassyarduino | 0:e3fb1267e3c3 | 69 | { |
cassyarduino | 12:aef29fbc4a62 | 70 | uint8_t* msg = (uint8_t*)malloc(size+1); |
cassyarduino | 12:aef29fbc4a62 | 71 | memset(msg, 0, size+1); |
cassyarduino | 0:e3fb1267e3c3 | 72 | size = client.read(msg,size); |
cassyarduino | 0:e3fb1267e3c3 | 73 | #if ACTLOGLEVEL>=LOG_INFO |
cassyarduino | 12:aef29fbc4a62 | 74 | #if defined(ARDUINO) |
cassyarduino | 12:aef29fbc4a62 | 75 | LogObject.write(msg,size); |
cassyarduino | 12:aef29fbc4a62 | 76 | #endif |
cassyarduino | 12:aef29fbc4a62 | 77 | #if defined(__MBED__) |
cassyarduino | 12:aef29fbc4a62 | 78 | LogObject.uart_send_str(msg); |
cassyarduino | 12:aef29fbc4a62 | 79 | #endif |
cassyarduino | 0:e3fb1267e3c3 | 80 | #endif |
cassyarduino | 0:e3fb1267e3c3 | 81 | free(msg); |
cassyarduino | 0:e3fb1267e3c3 | 82 | } |
cassyarduino | 0:e3fb1267e3c3 | 83 | #if ACTLOGLEVEL>=LOG_INFO |
cassyarduino | 0:e3fb1267e3c3 | 84 | LogObject.uart_send_strln(F("DATA from Server!")); |
cassyarduino | 0:e3fb1267e3c3 | 85 | #endif |
cassyarduino | 0:e3fb1267e3c3 | 86 | client.stop(); |
cassyarduino | 0:e3fb1267e3c3 | 87 | } |
cassyarduino | 0:e3fb1267e3c3 | 88 | } |
cassyarduino | 11:3fb19220d9ec | 89 | #if defined(__MBED__) |
cassyarduino | 11:3fb19220d9ec | 90 | } |
cassyarduino | 11:3fb19220d9ec | 91 | #endif |