WiFi DipCortex USB CDC
Dependencies: HTTPClient NTPClient USBDevice WebSocketClient cc3000_hostdriver_mbedsocket mbed
Fork of WiFiDip-UsbKitchenSink by
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, committed 2014-02-07
- Comitter:
- SolderSplashLabs
- Date:
- Fri Feb 07 00:26:14 2014 +0000
- Parent:
- 3:15828ac052f1
- Commit message:
- Added mDNS after smart config
Changed in this revision
diff -r 15828ac052f1 -r ce953c80c5b3 main.cpp --- 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(); }
diff -r 15828ac052f1 -r ce953c80c5b3 tcpTests.cpp --- 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 ) {
diff -r 15828ac052f1 -r ce953c80c5b3 tcpTests.h --- a/tcpTests.h Wed Nov 13 21:33:37 2013 +0000 +++ b/tcpTests.h Fri Feb 07 00:26:14 2014 +0000 @@ -4,6 +4,7 @@ void HttpClientTest ( void ); void WebSocketTest ( void ); void WebSocketReadTest ( void ); +void WebSocketAdcStream ( void ); void TcpClientTest ( void ); void TcpServerTest ( void ); void XivelySimpleTest ( void );