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@0:e3fb1267e3c3, 2016-12-21 (annotated)
- Committer:
- cassyarduino
- Date:
- Wed Dec 21 16:58:10 2016 +0100
- Revision:
- 0:e3fb1267e3c3
- Child:
- 11:3fb19220d9ec
initial release
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 | 0:e3fb1267e3c3 | 21 | #include <UIPEthernet.h> |
cassyarduino | 0:e3fb1267e3c3 | 22 | #include "utility/logging.h" |
cassyarduino | 0:e3fb1267e3c3 | 23 | |
cassyarduino | 0:e3fb1267e3c3 | 24 | EthernetServer server = EthernetServer(1000); |
cassyarduino | 0:e3fb1267e3c3 | 25 | |
cassyarduino | 0:e3fb1267e3c3 | 26 | void setup() |
cassyarduino | 0:e3fb1267e3c3 | 27 | { |
cassyarduino | 0:e3fb1267e3c3 | 28 | #if ACTLOGLEVEL>LOG_NONE |
cassyarduino | 0:e3fb1267e3c3 | 29 | LogObject.begin(9600); |
cassyarduino | 0:e3fb1267e3c3 | 30 | #endif |
cassyarduino | 0:e3fb1267e3c3 | 31 | |
cassyarduino | 0:e3fb1267e3c3 | 32 | uint8_t mac[6] = {0x00,0x01,0x02,0x03,0x04,0x05}; |
cassyarduino | 0:e3fb1267e3c3 | 33 | IPAddress myIP(192,168,0,6); |
cassyarduino | 0:e3fb1267e3c3 | 34 | |
cassyarduino | 0:e3fb1267e3c3 | 35 | Ethernet.begin(mac,myIP); |
cassyarduino | 0:e3fb1267e3c3 | 36 | |
cassyarduino | 0:e3fb1267e3c3 | 37 | server.begin(); |
cassyarduino | 0:e3fb1267e3c3 | 38 | } |
cassyarduino | 0:e3fb1267e3c3 | 39 | |
cassyarduino | 0:e3fb1267e3c3 | 40 | void loop() |
cassyarduino | 0:e3fb1267e3c3 | 41 | { |
cassyarduino | 0:e3fb1267e3c3 | 42 | size_t size; |
cassyarduino | 0:e3fb1267e3c3 | 43 | |
cassyarduino | 0:e3fb1267e3c3 | 44 | if (EthernetClient client = server.available()) |
cassyarduino | 0:e3fb1267e3c3 | 45 | { |
cassyarduino | 0:e3fb1267e3c3 | 46 | while((size = client.available()) > 0) |
cassyarduino | 0:e3fb1267e3c3 | 47 | { |
cassyarduino | 0:e3fb1267e3c3 | 48 | uint8_t* msg = (uint8_t*)malloc(size); |
cassyarduino | 0:e3fb1267e3c3 | 49 | size = client.read(msg,size); |
cassyarduino | 0:e3fb1267e3c3 | 50 | #if ACTLOGLEVEL>=LOG_INFO |
cassyarduino | 0:e3fb1267e3c3 | 51 | LogObject.write(msg,size); |
cassyarduino | 0:e3fb1267e3c3 | 52 | #endif |
cassyarduino | 0:e3fb1267e3c3 | 53 | free(msg); |
cassyarduino | 0:e3fb1267e3c3 | 54 | } |
cassyarduino | 0:e3fb1267e3c3 | 55 | #if ACTLOGLEVEL>=LOG_INFO |
cassyarduino | 0:e3fb1267e3c3 | 56 | LogObject.uart_send_strln(F("DATA from Server!")); |
cassyarduino | 0:e3fb1267e3c3 | 57 | #endif |
cassyarduino | 0:e3fb1267e3c3 | 58 | client.stop(); |
cassyarduino | 0:e3fb1267e3c3 | 59 | } |
cassyarduino | 0:e3fb1267e3c3 | 60 | } |