This example uses the mbed libraries to check Ethernet TCP Echo Server Example.

Dependencies:   EthernetInterface mbed-rtos mbed

Fork of FRDM_K64F-Ethernet-SKM by Szymon eS

Files at this revision

API Documentation at this revision

Comitter:
szymones
Date:
Wed Dec 06 14:04:57 2017 +0000
Parent:
1:aa0966de74f9
Commit message:
final version for laboratory

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r aa0966de74f9 -r 47551c2af80b main.cpp
--- a/main.cpp	Wed Dec 06 10:14:24 2017 +0000
+++ b/main.cpp	Wed Dec 06 14:04:57 2017 +0000
@@ -1,7 +1,10 @@
 #include "mbed.h"
 #include "EthernetInterface.h"
  
-#define MBED_DEV_IP       "192.168.5.61"
+ 
+#define MBED_DEV_IP       "192.168.5.61"//lab
+//#define MBED_DEV_IP       "192.168.0.101"//router
+
 #define MBED_DEV_MASK     "255.255.255.0"
 #define MBED_DEV_GW       "192.168.5.1"
 #define ECHO_SERVER_PORT   5000
@@ -15,7 +18,7 @@
 
 //Serial pc(USBTX, USBRX);
 
-void eth_vTaskTimeReq(){
+void eth_vTaskClientReq(){
     int socketFd;
     int len;
     struct sockaddr_in clientSockDescr, serverSockDescr;
@@ -64,13 +67,30 @@
         lwip_close(socketFd);
 }
  
+ void ledf_on(void)
+{
+    DigitalOut led1(LED1);
+
+        led1 = 0;
+} 
+
+void ledf_off(void)
+{
+    DigitalOut led1(LED1);
+
+        led1 = 1;
+
+}
+
 int main (void) {
     EthernetInterface eth;
     eth.init(MBED_DEV_IP, MBED_DEV_MASK, MBED_DEV_GW); //Assign a device ip, mask and gateway
     eth.connect();
     printf("IP Address is %s\n", eth.getIPAddress());
+    char led_on= 'o';
+    char led_off= 'f';
     
-    eth_vTaskTimeReq();
+    eth_vTaskClientReq();
     
     TCPSocketServer server;
     server.bind(ECHO_SERVER_PORT);
@@ -87,6 +107,13 @@
         while (true) {
             int n = client.receive(buffer, sizeof(buffer));
             if (n <= 0) break;
+            
+            if( memcmp( &led_on, buffer, 1) == 0 )
+                ledf_on();
+              
+            if( memcmp( &led_off, buffer, 1) == 0 )
+                ledf_off();
+              
             printf("%s\n", buffer);
             client.send_all(buffer, n);
             if (n <= 0) break;