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

Dependencies:   WiConnect mbed

Revision:
0:447a1bbce2ca
Child:
2:2f1df6a7ed12
Child:
6:b425959b75f0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Aug 23 13:08:08 2014 +0000
@@ -0,0 +1,65 @@
+
+#include "Wiconnect.h"
+#include "target_config.h"
+
+#define NETWORK_SSID "<YOUR NETWORK SSID HERE>"
+#define NETWORK_PASSWORD "<YOUR NETWORK PASSWORD HERE>"
+
+#define ECHO_SERVER_ADDRESS  "<YOUR LOCAL IP ADDRESS HERE>"
+#define ECHO_SERVER_PORT 7
+
+
+static Serial consoleSerial(STDIO_UART_TX, STDIO_UART_RX);
+static char buf[256];
+
+
+int main()
+{
+    WiconnectResult result;
+    SerialConfig serialConfig(WICONNECT_RX_PIN, WICONNECT_TX_PIN, 256);
+    Wiconnect wiconnect(serialConfig, 256, NULL, WICONNECT_RESET_PIN);
+
+    consoleSerial.baud(115200);
+
+    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("Failed to join network: %s\r\n", Wiconnect::getWiconnectResultStr(result));
+        for(;;);
+    }
+
+    printf("IP Address is %s\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);
+        wait(1);
+    }
+
+    char hello[] = "Hello World\n";
+    if(socket.send_all(hello, sizeof(hello) - 1) == -1)
+    {
+        printf("Failed to send data\r\n");
+        for(;;);
+    }
+
+    int n = socket.receive(buf, 256);
+    if(n == -1)
+    {
+        printf("Failed to receive data\r\n");
+        for(;;);
+    }
+    buf[n] = '\0';
+    printf("%s", buf);
+
+    socket.close();
+    wiconnect.deinit();
+
+    printf("Finished!");
+    while(true) {}
+}