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/
Diff: examples/UdpClient/UdpClient.ino
- Revision:
- 6:f092f8b320ae
- Parent:
- 0:e3fb1267e3c3
- Child:
- 11:3fb19220d9ec
--- a/examples/UdpClient/UdpClient.ino Tue Dec 27 13:02:23 2016 +0100 +++ b/examples/UdpClient/UdpClient.ino Tue Dec 27 13:45:01 2016 +0100 @@ -40,7 +40,7 @@ int success; int len = 0; - if (((signed long)(millis()-next))>0) + if (millis()>next) { do { @@ -52,56 +52,55 @@ //beginPacket fails if remote ethaddr is unknown. In this case an //arp-request is send out first and beginPacket succeeds as soon //the arp-response is received. + #if defined(ESP8266) + wdt_reset(); + #endif } - while (!success && ((signed long)(millis()-next))<0); - if (!success ) - goto stop; - - success = udp.write("hello world from arduino"); - - #if ACTLOGLEVEL>=LOG_INFO - LogObject.uart_send_str(F("bytes written: ")); - LogObject.uart_send_decln(success); - #endif - - success = udp.endPacket(); - - #if ACTLOGLEVEL>=LOG_INFO - LogObject.uart_send_str(F("endPacket: ")); - LogObject.uart_send_strln(success ? "success" : "failed"); - #endif - - do + while (!success && (millis()<next)); + if (success) { + success = udp.write("hello world from arduino"); + #if ACTLOGLEVEL>=LOG_INFO + LogObject.uart_send_str(F("bytes written: ")); + LogObject.uart_send_decln(success); + #endif + success = udp.endPacket(); + #if ACTLOGLEVEL>=LOG_INFO + LogObject.uart_send_str(F("endPacket: ")); + LogObject.uart_send_strln(success ? "success" : "failed"); + #endif + do + { //check for new udp-packet: success = udp.parsePacket(); - } - while (!success && ((signed long)(millis()-next))<0); - if (!success ) - goto stop; - - #if ACTLOGLEVEL>=LOG_INFO - LogObject.uart_send_str(F("received: '")); - #endif - do - { - int c = udp.read(); + #if defined(ESP8266) + wdt_reset(); + #endif + } + while (!success && (millis()<next)); + if (success) + { #if ACTLOGLEVEL>=LOG_INFO - LogObject.write(c); + LogObject.uart_send_str(F("received: '")); #endif - len++; + do + { + int c = udp.read(); + #if ACTLOGLEVEL>=LOG_INFO + LogObject.write(c); + #endif + len++; + } + while ((success = udp.available())>0); + #if ACTLOGLEVEL>=LOG_INFO + LogObject.uart_send_str(F("', ")); + LogObject.uart_send_dec(len); + LogObject.uart_send_strln(F(" bytes")); + #endif + //finish reading this packet: + udp.flush(); + } } - while ((success = udp.available())>0); - #if ACTLOGLEVEL>=LOG_INFO - LogObject.uart_send_str(F("', ")); - LogObject.uart_send_dec(len); - LogObject.uart_send_strln(F(" bytes")); - #endif - - //finish reading this packet: - udp.flush(); - - stop: udp.stop(); next = millis()+5000; }