WiFi DipCortex USB CDC

Dependencies:   HTTPClient NTPClient USBDevice WebSocketClient cc3000_hostdriver_mbedsocket mbed

Fork of WiFiDip-UsbKitchenSink by Carl - SolderSplash Labs

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

Demo shows you how to implement the CC3000 library with the WiFi DipCortex.

The demo shows :

  • USB CDC ( Serial ) Menu system allow control of the module and starting each example
  • Smart Connect
  • Manual connect
  • Connection status
  • Ping
  • TCP Client
  • TCP Server
  • Web Socket read/write to sockets.mbed.org
  • HTTP Client test Post, Put, Delete
  • Posting ADC data to Xively every 1 second
  • UDP Client
  • UDP Server
  • NTP Example, contacts time server to get the current time

You will need a Driver for the USB CDC port which can be found here : http://www.soldersplash.co.uk/docs/DipCortex-USB-CDC.zip

Please refer to : http://mbed.org/users/SolderSplashLabs/notebook/dipcortex---getting-started-with-mbed/ as well as the SolderSplash Forum for support http://forum.soldersplash.co.uk/viewforum.php?f=15

Revision:
4:ce953c80c5b3
Parent:
3:15828ac052f1
--- a/tcpTests.cpp	Wed Nov 13 21:33:37 2013 +0000
+++ b/tcpTests.cpp	Fri Feb 07 00:26:14 2014 +0000
@@ -193,6 +193,77 @@
     @brief Open a WebSocket, send a string
 */
 // ------------------------------------------------------------------------------------------------------------
+void WebSocketAdcStream ( void )
+{
+
+int res = 0;
+uint16_t counter = 0;
+uint16_t reconnects = 0;
+uint8_t myMAC[8];
+
+    wifi.get_mac_address(myMAC);
+    
+    Websocket ws((char *)WEB_SOCKET_URL);
+    if ( ws.connect() )
+    {
+        pc.printf("Connected to websocket server.\r\n");
+        
+        pc.printf("\r\n!! Press any key to stop sending !!\r\n\r\n");
+        while (1)
+        {   
+            counter ++;
+            sprintf(tmpBuffer, "{\"id\":\"wifly_acc\",\"ax\":\"%d\",\"ay\":\"%d\",\"az\":\"%d\"}", adc0.read_u16(), adc1.read_u16(), adc2.read_u16());
+            
+            if ( wifi.is_connected() )
+            {
+                res = ws.send(tmpBuffer);
+                pc.printf("Reconnects : %05d, Messages Sent : %05d, Websocket send returned : %d.\r\n", reconnects, counter, res);
+            
+                if ( -1 == res ) 
+                {
+                    pc.printf("Websocket Failure, reconnecting .... \r\n");
+                    ws.close();
+                    if ( ws.connect() )
+                    {
+                        // Reconnected
+                        reconnects ++;
+                    }
+                    else
+                    {
+                        // Failure!
+                        break;
+                    }
+                }
+                
+                wait_ms(1000);
+            }
+            else
+            {
+                pc.printf("WiFi Connection Lost .... \r\n");
+            }
+            
+            if ( pc.readable() )
+            {
+                pc.printf("Closing Socket \r\n");
+                pc.getc();
+                break;
+            }
+        }
+        
+        ws.close();
+        pc.printf("Websocket Closed \r\n");
+    }
+    else
+    {
+        pc.printf("Websocket connection failed\r\n");
+    }
+}
+
+// ------------------------------------------------------------------------------------------------------------
+/*!
+    @brief Open a WebSocket, send a string
+*/
+// ------------------------------------------------------------------------------------------------------------
 void WebSocketTest ( void )
 {