Timo Karppinen / Mbed OS UDP_RoundTripEcho_OS6_H743ZI
Revision:
5:fb39c8c13b34
Parent:
2:150dadff3c6b
Child:
6:11edc8f9d870
--- a/main.cpp	Sat Nov 21 16:03:30 2020 +0000
+++ b/main.cpp	Mon Nov 23 12:48:48 2020 +0000
@@ -4,7 +4,7 @@
  ***********************************
  * Round trip delay meter. Date and time is taken from a NTP server. 
  * A microcontroller board with an Ethernet interface.
- * An other microcontroller with "Round trip delay echo" will be needed. 
+ * An other microcontroller with "Round trip echo" will be needed. 
  * NXP FRDM-K64F used for testing.
  *   
  * Timo Karppinen 20.11.2020
@@ -41,8 +41,8 @@
 void udpReceive( void );
 void udpSend( void );
 
-DigitalIn sw2(SW2);
-DigitalOut led2(LED2);
+DigitalIn sw2(SW2);     // sw2 on K64F, button pressed = FALSE
+DigitalOut led2(LED2);  // RGB LED green on K64F
 int sw2state = 0;
 int sw2old = 1;
 
@@ -56,7 +56,7 @@
 Timer armedFor;
     
 int main() {
-    printf("\nNTP Client example (using Ethernet)\r\n");
+    printf("\nRound trip delay in UDP messaging (using Ethernet)\n");
     
     //Bring up the network interface
     net.connect();
@@ -86,7 +86,7 @@
 
     while(1) {  
     sw2state = sw2.read();
-    printf( "sw2state is  %d\n", sw2state);
+    printf( "\nsw2state is  %d\n", sw2state);
     
     if((sw2state == 0)&&(sw2state != sw2old)) {
         led2.write(0);
@@ -153,12 +153,13 @@
     int bytes;
     while(1) {
         bytes = serverUDP.recvfrom(&clientUDP, &in_data, BUFF_SIZE);
+        newDatagram = 1;    // set this before using time for printing
         printf("\n");
         printf("bytes received: %d\n",bytes);
         printf("string: %s\n",in_data);
         printf("client address: %s\n", clientUDP.get_ip_address());
         printf("\n");
-        newDatagram = 1;
+ 
         }
 }