WiFi DipCortex / CC3000 Demo - Contains a menu driven set of tests to initalise and control the CC3000 radio. Also allowing you to test various TCP and UDP connections.

Dependencies:   NTPClient WebSocketClient cc3000_hostdriver_mbedsocket mbed HTTPClient

http://www.soldersplash.co.uk/products/wifi-dipcortex/

Please Note, this example uses the serial port so you will need an external RS232 TTL to USB adapter.

Revision:
2:3adf4a0475d7
Parent:
0:039d229f3d6b
Child:
3:d81f8a9f3733
--- a/main.cpp	Mon Oct 07 21:21:20 2013 +0000
+++ b/main.cpp	Tue Oct 08 00:03:54 2013 +0000
@@ -99,14 +99,19 @@
 
 // ------------------------------------------------------------------------------------------------------------
 /*!
-    @brief Open a WebSocket, send string a string
+    @brief Open a WebSocket, send a string
 */
 // ------------------------------------------------------------------------------------------------------------
 void WebSocketTest ( void )
 {
 int res = 0;
-uint32_t counter = 0;
+uint16_t counter = 0;
+uint16_t reconnects = 0;
+uint8_t myMAC[8];
+char websocketstr[100];
 
+    wifi.get_mac_address(myMAC);
+    
     Websocket ws((char *)WEB_SOCKET_URL);
     if ( ws.connect() )
     {
@@ -116,10 +121,25 @@
         while (1)
         {   
             counter ++;
-            res = ws.send("WiFi DipCortex / CC3000 - Says Hello");
-            printf("%05d : Websocket send returned : %d.\r\n", counter, res);
+            sprintf(websocketstr, "WiFi DipCortex / CC3000 - %05d - %02x:%02x:%02x:%02x:%02x:%02x\r\n", counter, myMAC[0], myMAC[1], myMAC[2], myMAC[3], myMAC[4], myMAC[5]);
+            res = ws.send(websocketstr);
+            printf("Reconnects : %05d, Messages Sent : %05d, Websocket send returned : %d.\r\n", reconnects, counter, res);
         
-            if ( -1 == res ) break;
+            if ( -1 == res ) 
+            {
+                printf("Websocket Failure, reconnecting .... \r\n");
+                ws.close();
+                if ( ws.connect() )
+                {
+                    // Reconnected
+                    reconnects ++;
+                }
+                else
+                {
+                    // Failure!
+                    break;
+                }
+            }
             
             wait_ms(1000);
             
@@ -215,6 +235,7 @@
     
     server.bind(15000);
     server.listen();
+    printf("\r\n!! Press any key to stop listening !!\r\n\r\n");
     while (1) 
     {
         status = server.accept(client);
@@ -222,7 +243,6 @@
         {
             client.set_blocking(false, 1500); // Timeout after (1.5)s
             printf("Connection from: %s \r\n", client.get_address());
-            char buffer[256];
             //client.receive(buffer, sizeof(buffer));
             //printf("Received: %s \r\n",buffer);
             printf("Sending the message to the server. \r\n");
@@ -257,6 +277,8 @@
         
         // 2 second timeout
         socket.set_blocking(false, 2000);
+        
+        printf("\r\n!! Press any key to stop !!\r\n\r\n");
     
         while (1)
         {
@@ -315,6 +337,8 @@
 
     if (0 == socket.bind(ECHO_SERVER_PORT_UDP) )
     {   
+        printf("\r\n!! Press any key to stop listening !!\r\n\r\n");
+        
         while (true) 
         {
             printf("Waiting for packet...\r\n");
@@ -416,7 +440,8 @@
             wifi._wlan.ioctl_set_connection_policy(0, 0, 0);
         break;
         
-        case '3':      
+        case '3':     
+            //wifi.start(0); 
             if ( AP_SECURITY == NONE )
             {
                 connect_to_ssid((uint8_t *)SSID);
@@ -429,6 +454,7 @@
         
         case '4' :
             wifi.disconnect();
+            wifi.stop();
         break;
         
         case '5' :
@@ -485,7 +511,7 @@
     Menu_PrintHeader();
 
     printf(" 1 - TCP Client, Connect to %s:%d\r\n", ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT_TCP);
-    printf(" 2 - TCP Server, listen on port\r\n", ECHO_SERVER_PORT_TCP);
+    printf(" 2 - TCP Server, listen on port %d\r\n", ECHO_SERVER_PORT_TCP);
     printf(" 3 - Web Socket Write \r\n");
     printf(" 4 - Web Socket Read \r\n");
     printf(" x - Exit to top menu ");
@@ -524,6 +550,7 @@
     printf(" 3 - UDP test menu \r\n" );
     printf(" 4 - Connection status \r\n");
     printf(" 5 - Ping - %s \r\n", HostToPing);
+    printf(" x - Top Menu \r\n");
     
     printf("\r\n");
     printf("Enter command character : ");
@@ -568,7 +595,7 @@
     switch ( currentMenu )
     {
         case MENU_TOP :
-            if (connected) Menu_Top();
+            Menu_Top();
         break;
         
         case MENU_CONNECTION :
@@ -599,7 +626,6 @@
     // Initalise the WiFi Module
     init(); 
     pc.baud(SERIAL_BAUD_RATE);
-
     wifi.start(0);
 
     while (1)