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/main.cpp	Wed Nov 13 21:33:37 2013 +0000
+++ b/main.cpp	Fri Feb 07 00:26:14 2014 +0000
@@ -35,6 +35,10 @@
 
 MENU_LEVEL currentMenu = MENU_TOP;
 
+bool Connected = false;
+bool UsingSmartConfig = false;
+char _deviceName[] = "CC3000";
+
 // ------------------------------------------------------------------------------------------------------------
 /*!
     @brief Resolve a hostname and ping it
@@ -270,6 +274,8 @@
     // wait for a message via a SmartConfig app, store it to the profile list
     // finally it will reenable auto connection, triggering the module to connect to the new access point
     wifi.start_smart_config(0);
+    
+    UsingSmartConfig = true;
 }
 
 // ------------------------------------------------------------------------------------------------------------
@@ -352,6 +358,7 @@
     switch(WaitForSerialCommand()) 
     {
         case '1':      
+            UsingSmartConfig = false;
             wifi._wlan.ioctl_set_connection_policy(0, 0, 1);
         break;
         
@@ -361,7 +368,7 @@
         
         case '3':     
         
-            //wifi.start(0);
+            UsingSmartConfig = false;
             
             // Enable DHCP
             wifi._netapp.dhcp(&ip, &ip, &ip, &ip);
@@ -400,7 +407,7 @@
         case '8':
             //wifi._spi.manualIrqCheck();
         break;
-        
+        case '0':  
         case 'x':      
             currentMenu = MENU_TOP;
         break;
@@ -454,8 +461,9 @@
     pc.printf(" 2 - TCP Server, listen on %d.%d.%d.%d:%d\r\n", ipinfo.aucIP[3], ipinfo.aucIP[2], ipinfo.aucIP[1], ipinfo.aucIP[0], ECHO_SERVER_PORT_TCP);
     pc.printf(" 3 - Web Socket Write \r\n");
     pc.printf(" 4 - Web Socket Read \r\n");
-    pc.printf(" 5 - HTTP Client \r\n");
-    pc.printf(" 6 - Xively Post ADC's \r\n");
+    pc.printf(" 5 - Web Socket Write ADCs \r\n");
+    pc.printf(" 6 - HTTP Client \r\n");
+    pc.printf(" 7 - Xively Post ADC's \r\n");
     pc.printf(" x - Exit to top menu ");
     pc.printf("\r\n");
     
@@ -474,9 +482,12 @@
             WebSocketReadTest();
         break;
         case '5':
+            WebSocketAdcStream();
+        break;
+        case '6':
             HttpClientTest();
         break;
-        case '6':
+        case '7':
             XivelySimpleTest();
         break;
         case '0':   
@@ -522,6 +533,7 @@
         case '5':      
             PingTest();
         break;
+        case '0':  
         case 'x':      
             currentMenu = MENU_TOP;
         break;
@@ -535,13 +547,30 @@
 // ------------------------------------------------------------------------------------------------------------
 void MenuSwitch ( void )
 {
-bool connected = false;
+//bool connected = false;
 
     if ( wifi.is_dhcp_configured() )
     {
-        connected = true;
+        if (!Connected)
+        {
+            // We have just connected
+            Connected = true;
+            
+            if ( UsingSmartConfig )
+            {
+                // Start the mdns service, this tells any smart config apps listening we have succeeded
+                wifi._socket.mdns_advertiser(1, (uint8_t *)_deviceName, strlen(_deviceName));
+                
+                UsingSmartConfig = false;
+            }
+        }
     }
-    
+    else
+    {
+        Connected = false;
+
+    }
+        
     switch ( currentMenu )
     {
         case MENU_TOP :
@@ -553,7 +582,7 @@
         break;
         
         case MENU_TCP :
-            if (connected) 
+            if (Connected) 
             {
                 Menu_TcpControl();
             }
@@ -564,7 +593,7 @@
         break;
         
         case MENU_UDP :
-            if (connected) 
+            if (Connected) 
             {
                 Menu_UdpControl();
             }