TCP echo client using the WiConnect library and mbed TCP Socket API.

Dependencies:   WiConnect mbed

Revision:
2:2f1df6a7ed12
Parent:
0:447a1bbce2ca
--- a/main.cpp	Sat Aug 23 13:09:29 2014 +0000
+++ b/main.cpp	Sun Aug 24 03:34:32 2014 +0000
@@ -2,10 +2,10 @@
 #include "Wiconnect.h"
 #include "target_config.h"
 
-#define NETWORK_SSID "<YOUR NETWORK SSID HERE>"
-#define NETWORK_PASSWORD "<YOUR NETWORK PASSWORD HERE>"
+#define NETWORK_SSID "ASUS"
+#define NETWORK_PASSWORD "Y@nkee123"
 
-#define ECHO_SERVER_ADDRESS  "<YOUR LOCAL IP ADDRESS HERE>"
+#define ECHO_SERVER_ADDRESS  "192.168.1.110"
 #define ECHO_SERVER_PORT 7
 
 
@@ -21,27 +21,31 @@
 
     consoleSerial.baud(115200);
 
+    printf("Initializing WiConnect...\r\n");
     if(WICONNECT_FAILED(result, wiconnect.init(true)))
     {
         printf("Failed to initialize Wiconnect: %s\r\n", Wiconnect::getWiconnectResultStr(result));
         for(;;);
     }
-    else if(WICONNECT_FAILED(result, wiconnect.join(NETWORK_SSID, NETWORK_PASSWORD)))
+    
+    printf("Joining network: %s\r\n", NETWORK_SSID);
+    if(WICONNECT_FAILED(result, wiconnect.join(NETWORK_SSID, NETWORK_PASSWORD)))
     {
         printf("Failed to join network: %s\r\n", Wiconnect::getWiconnectResultStr(result));
         for(;;);
     }
 
-    printf("IP Address is %s\n", wiconnect.getIpAddress());
+    printf("IP Address is %s\r\n", wiconnect.getIpAddress());
 
     TCPSocketConnection socket;
     while (socket.connect(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT) < 0)
     {
-        printf("Unable to connect to (%s) on port (%d)\r\n", ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT);
+        printf("Unable to connect to (%s) on port (%d) (is the TCP server python script running?\r\n", ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT);
         wait(1);
     }
 
-    char hello[] = "Hello World\n";
+    printf("Sending msg to server...\r\n");
+    char hello[] = "Hello World\r\n";
     if(socket.send_all(hello, sizeof(hello) - 1) == -1)
     {
         printf("Failed to send data\r\n");
@@ -55,11 +59,11 @@
         for(;;);
     }
     buf[n] = '\0';
-    printf("%s", buf);
+    printf("Received msg from server: %s", buf);
 
     socket.close();
     wiconnect.deinit();
 
-    printf("Finished!");
+    printf("\r\n\r\n*** Finished!");
     while(true) {}
 }