Simple UDP Client using the UIPEthernet library for ENC28J60 Ethernet boards.

Dependencies:   UIPEthernet

Revision:
1:f6b6e2c173b9
Parent:
0:47d7b7b2bba3
Child:
2:c69ad6e71f97
--- a/main.cpp	Sat Jul 01 08:23:21 2017 +0000
+++ b/main.cpp	Sat Jul 01 08:37:21 2017 +0000
@@ -1,15 +1,15 @@
 /*
  * UIPEthernet UdpClient example.
  *
- * UIPEthernet is a TCP/IP stack that can be used with a enc28j60 based
+ * UIPEthernet is a TCP/IP stack that can be used with an enc28j60 based
  * Ethernet-shield.
  *
  * UIPEthernet uses the fine uIP stack by Adam Dunkels <adam@sics.se>
  *
  *      -----------------
  *
- * This UdpClient example tries to send a packet via udp to 192.168.0.1
- * on port 5000 every 5 seconds. After successfully sending the packet it
+ * This UdpClient example tries to send a packet via udp to 192.168.1.181
+ * on port 7 every 5 seconds. After successfully sending the packet it
  * waits for up to 5 seconds for a response on the local port that has been
  * implicitly opened when sending the packet.
  *
@@ -24,9 +24,9 @@
 // MAC address must be unique within the connected network. Modify as appropriate.
 const uint8_t    MY_MAC[6] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 };
 // IP address must be unique and compatible with your network.
-const IPAddress  MY_IP(192, 168, 1, 182);
-const IPAddress  SRV_IP(192, 168, 1, 181);   // UDP server IP address
-const uint16_t   UDP_PORT = 7;               // UDP port used
+const IPAddress  MY_IP(192, 168, 1, 182);   // this UDP client IP address
+const IPAddress  SRV_IP(192, 168, 1, 181);  // UDP server IP address
+const uint16_t   PORT = 7;                  // port used
 const char*      message = "Hello World from mbed!";
 
 Serial           pc(USBTX, USBRX);
@@ -41,7 +41,7 @@
  */
 int main(void) {
     const char* message = "Hello World from mbed";
-    time_t  next = time(NULL) + 5;
+    time_t  next = time(NULL);
     uIPEthernet.begin(MY_MAC, MY_IP);
 
     IPAddress   localIP = uIPEthernet.localIP();
@@ -55,7 +55,7 @@
             next = time(NULL) + 5;
             
             do {
-                success = udp.beginPacket(SRV_IP, UDP_PORT);
+                success = udp.beginPacket(SRV_IP, PORT);
                 pc.printf("beginPacket: ");
                 if (success)
                     pc.printf("succeeded.\r\n");
@@ -105,6 +105,7 @@
 
             //finish reading this packet:
             udp.flush();
+            next = time(NULL) + 5;
         }
     }
 }