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

Files at this revision

API Documentation at this revision

Comitter:
SolderSplashLabs
Date:
Tue Nov 12 09:19:13 2013 +0000
Parent:
1:6f4eaec531c4
Child:
3:15828ac052f1
Commit message:
Ping reports fixed; Added WebSocket Read

Changed in this revision

cc3000_hostdriver_mbedsocket.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
tcpTests.cpp Show annotated file Show diff for this revision Revisions of this file
tcpTests.h Show annotated file Show diff for this revision Revisions of this file
--- a/cc3000_hostdriver_mbedsocket.lib	Mon Nov 04 22:18:14 2013 +0000
+++ b/cc3000_hostdriver_mbedsocket.lib	Tue Nov 12 09:19:13 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/SolderSplashLabs/code/cc3000_hostdriver_mbedsocket/#960b73df5981
+http://mbed.org/users/SolderSplashLabs/code/cc3000_hostdriver_mbedsocket/#ca8c234997c0
--- a/main.cpp	Mon Nov 04 22:18:14 2013 +0000
+++ b/main.cpp	Tue Nov 12 09:19:13 2013 +0000
@@ -15,7 +15,7 @@
 #if (MY_BOARD == WIGO)
 cc3000 wifi(PTA16, PTA13, PTD0, SPI(PTD2, PTD3, PTC5), PORTA_IRQn);
 #elif (MY_BOARD == WIFI_DIPCORTEX)
-cc3000 wifi(p28, p27, p30, SPI(p21, p14, p37), PIN_INT0_IRQn);
+cc3000 wifi(p28, p27, p30, SPI(p21, p14, p37));
 Serial uart(p19, p20);
 USBSerial pc;               // USB CDC serial port
 #else
@@ -262,6 +262,7 @@
 // ------------------------------------------------------------------------------------------------------------
 void SmartConfig ( void )
 {
+    pc.printf("\r\nStarting Smart config, waiting for message from smartphone app ....\r\n");
     // We dont want to auto reconnect to an access point
     wifi._wlan.ioctl_set_connection_policy(0, 0, 0);
     
@@ -470,7 +471,7 @@
             WebSocketTest();
         break;
         case '4':
-        
+            WebSocketReadTest();
         break;
         case '5':
             HttpClientTest();
--- a/tcpTests.cpp	Mon Nov 04 22:18:14 2013 +0000
+++ b/tcpTests.cpp	Tue Nov 12 09:19:13 2013 +0000
@@ -256,6 +256,79 @@
 
 // ------------------------------------------------------------------------------------------------------------
 /*!
+    @brief Open a WebSocket, send a string
+*/
+// ------------------------------------------------------------------------------------------------------------
+void WebSocketReadTest ( 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 receiving !!\r\n\r\n");
+        while (1)
+        {   
+            counter ++;
+            //sprintf(tmpBuffer, "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]);
+            
+            if ( wifi.is_connected() )
+            {
+                res = ws.read(tmpBuffer);
+                
+                if ( res )
+                {
+                    pc.printf("Websocket Received : %s (Reconnects : %05d, Messages Recv : %05d)\r\n", tmpBuffer, reconnects, counter);
+                }
+                
+                if ( ws.is_connected() )
+                {
+                
+                }
+                else
+                {
+                    pc.printf("Websocket Closed, reconnecting .... \r\n");
+                    ws.close();
+                    if ( ws.connect() )
+                    {
+                        // Reconnected
+                        reconnects ++;
+                    }
+                    else
+                    {
+                        // Failure!
+                        break;
+                    }
+                }
+            }
+            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");
+    }
+}
+
+// ------------------------------------------------------------------------------------------------------------
+/*!
     @brief Open a TCP port send a string and wait for a reply
 */
 // ------------------------------------------------------------------------------------------------------------
--- a/tcpTests.h	Mon Nov 04 22:18:14 2013 +0000
+++ b/tcpTests.h	Tue Nov 12 09:19:13 2013 +0000
@@ -3,6 +3,7 @@
 
 void HttpClientTest ( void );
 void WebSocketTest ( void );
+void WebSocketReadTest ( void );
 void TcpClientTest ( void );
 void TcpServerTest ( void );
 void XivelySimpleTest ( void );