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@11:3fb19220d9ec, 2016-12-29 (annotated)
- Committer:
- cassyarduino
- Date:
- Thu Dec 29 13:07:19 2016 +0100
- Revision:
- 11:3fb19220d9ec
- Parent:
- 0:e3fb1267e3c3
- Child:
- 12:aef29fbc4a62
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 | 0:e3fb1267e3c3 | 41 | LogObject.begin(9600); |
cassyarduino | 0:e3fb1267e3c3 | 42 | #endif |
cassyarduino | 0:e3fb1267e3c3 | 43 | |
cassyarduino | 0:e3fb1267e3c3 | 44 | uint8_t mac[6] = {0x00,0x01,0x02,0x03,0x04,0x05}; |
cassyarduino | 0:e3fb1267e3c3 | 45 | IPAddress myIP(192,168,0,6); |
cassyarduino | 0:e3fb1267e3c3 | 46 | |
cassyarduino | 0:e3fb1267e3c3 | 47 | Ethernet.begin(mac,myIP); |
cassyarduino | 0:e3fb1267e3c3 | 48 | |
cassyarduino | 0:e3fb1267e3c3 | 49 | server.begin(); |
cassyarduino | 11:3fb19220d9ec | 50 | #if defined(ARDUINO) |
cassyarduino | 0:e3fb1267e3c3 | 51 | } |
cassyarduino | 0:e3fb1267e3c3 | 52 | |
cassyarduino | 11:3fb19220d9ec | 53 | void loop() { |
cassyarduino | 11:3fb19220d9ec | 54 | #endif |
cassyarduino | 11:3fb19220d9ec | 55 | |
cassyarduino | 11:3fb19220d9ec | 56 | #if defined(__MBED__) |
cassyarduino | 11:3fb19220d9ec | 57 | while(true) { |
cassyarduino | 11:3fb19220d9ec | 58 | #endif |
cassyarduino | 0:e3fb1267e3c3 | 59 | size_t size; |
cassyarduino | 0:e3fb1267e3c3 | 60 | |
cassyarduino | 0:e3fb1267e3c3 | 61 | if (EthernetClient client = server.available()) |
cassyarduino | 0:e3fb1267e3c3 | 62 | { |
cassyarduino | 0:e3fb1267e3c3 | 63 | while((size = client.available()) > 0) |
cassyarduino | 0:e3fb1267e3c3 | 64 | { |
cassyarduino | 0:e3fb1267e3c3 | 65 | uint8_t* msg = (uint8_t*)malloc(size); |
cassyarduino | 0:e3fb1267e3c3 | 66 | size = client.read(msg,size); |
cassyarduino | 0:e3fb1267e3c3 | 67 | #if ACTLOGLEVEL>=LOG_INFO |
cassyarduino | 0:e3fb1267e3c3 | 68 | LogObject.write(msg,size); |
cassyarduino | 0:e3fb1267e3c3 | 69 | #endif |
cassyarduino | 0:e3fb1267e3c3 | 70 | free(msg); |
cassyarduino | 0:e3fb1267e3c3 | 71 | } |
cassyarduino | 0:e3fb1267e3c3 | 72 | #if ACTLOGLEVEL>=LOG_INFO |
cassyarduino | 0:e3fb1267e3c3 | 73 | LogObject.uart_send_strln(F("DATA from Server!")); |
cassyarduino | 0:e3fb1267e3c3 | 74 | #endif |
cassyarduino | 0:e3fb1267e3c3 | 75 | client.stop(); |
cassyarduino | 0:e3fb1267e3c3 | 76 | } |
cassyarduino | 0:e3fb1267e3c3 | 77 | } |
cassyarduino | 11:3fb19220d9ec | 78 | #if defined(__MBED__) |
cassyarduino | 11:3fb19220d9ec | 79 | } |
cassyarduino | 11:3fb19220d9ec | 80 | #endif |