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 5:506f580e7ead, committed 2013-10-12
- Comitter:
- SolderSplashLabs
- Date:
- Sat Oct 12 22:10:17 2013 +0000
- Parent:
- 4:4e5e094a81c0
- Commit message:
- Tweaks for robustness
Changed in this revision
diff -r 4e5e094a81c0 -r 506f580e7ead cc3000_hostdriver_mbedsocket.lib --- a/cc3000_hostdriver_mbedsocket.lib Wed Oct 09 00:59:47 2013 +0000 +++ b/cc3000_hostdriver_mbedsocket.lib Sat Oct 12 22:10:17 2013 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/SolderSplashLabs/code/cc3000_hostdriver_mbedsocket/#1d374a7f0c0d +http://mbed.org/users/SolderSplashLabs/code/cc3000_hostdriver_mbedsocket/#bd2c631a031a
diff -r 4e5e094a81c0 -r 506f580e7ead main.cpp --- a/main.cpp Wed Oct 09 00:59:47 2013 +0000 +++ b/main.cpp Sat Oct 12 22:10:17 2013 +0000 @@ -136,8 +136,11 @@ break; } } - - socket.close(); + + if ( wifi.is_connected() ) + { + socket.close(); + } } else { @@ -186,7 +189,7 @@ // ------------------------------------------------------------------------------------------------------------ void Menu_PrintHeader ( void ) { - if ( wifi.is_dhcp_configured() ) + if (( wifi.is_enabled() ) && ( wifi.is_dhcp_configured() )) { wifi.get_ip_config(&ipinfo); } @@ -195,14 +198,18 @@ printf("+-------------------------------------------+\r\n"); printf("| WiFi DipCortex / CC3000 Kitchen Sink |\r\n"); printf("+-------------------------------------------+\r\n"); - if ( wifi.is_dhcp_configured() ) + if (! wifi.is_enabled() ) + { + printf("| CC3000 Disabled |\r\n"); + } + else if ( wifi.is_dhcp_configured() ) { printf("| SSID : %-33s|\r\n", ipinfo.uaSSID); - printf("| IP : %d.%d.%d.%d |\r\n", ipinfo.aucIP[3], ipinfo.aucIP[2], ipinfo.aucIP[1], ipinfo.aucIP[0]); + printf("| IP : %-35s|\r\n", wifi.getIPAddress()); } else if ( wifi.is_connected() ) { - printf("| Connecting, waiting for DHCP |\r\n"); + printf("| Connecting, waiting for DHCP |\r\n"); } else { @@ -259,6 +266,7 @@ // ------------------------------------------------------------------------------------------------------------ void Menu_ConnectionControl ( void ) { +uint32_t ip = 0; Menu_PrintHeader(); printf(" 1 - Enable auto connect to any previous access point\r\n"); printf(" 2 - Disable auto connect \r\n"); @@ -287,21 +295,25 @@ //wifi.start(0); // Enable DHCP - wifi._netapp.dhcp(0, 0, 0, 0); + wifi._netapp.dhcp(&ip, &ip, &ip, &ip); if ( AP_SECURITY == NONE ) { - connect_to_ssid((uint8_t *)SSID); + wifi.connect_non_blocking((uint8_t *)SSID, 0, AP_SECURITY); } else { - connect_to_ssid(SSID,AP_KEY,AP_SECURITY); + printf("\r\n Connecting to : %s key : %s", SSID, AP_KEY ); + wifi.connect_non_blocking((uint8_t *)SSID, (uint8_t *)AP_KEY, AP_SECURITY); + } break; case '4' : + // Stop the module re-connecting + wifi._wlan.ioctl_set_connection_policy(0, 0, 0); + // Then disconnect wifi.disconnect(); - wifi.stop(); break; case '5' : @@ -316,6 +328,10 @@ print_cc3000_info(); break; + case '8': + //wifi._spi.manualIrqCheck(); + break; + case 'x': currentMenu = MENU_TOP; break; @@ -465,11 +481,25 @@ break; case MENU_TCP : - if (connected) Menu_TcpControl(); + if (connected) + { + Menu_TcpControl(); + } + else + { + currentMenu = MENU_TOP; + } break; case MENU_UDP : - if (connected) Menu_UdpControl(); + if (connected) + { + Menu_UdpControl(); + } + else + { + currentMenu = MENU_TOP; + } break; default : @@ -487,8 +517,13 @@ { // Initalise the WiFi Module init(); + pc.baud(SERIAL_BAUD_RATE); + + wait(1); wifi.start(0); + + wait_ms(750); while (1) {
diff -r 4e5e094a81c0 -r 506f580e7ead tcpTests.cpp --- a/tcpTests.cpp Wed Oct 09 00:59:47 2013 +0000 +++ b/tcpTests.cpp Sat Oct 12 22:10:17 2013 +0000 @@ -111,26 +111,34 @@ { counter ++; 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 ) + + if ( wifi.is_connected() ) { - printf("Websocket Failure, reconnecting .... \r\n"); - ws.close(); - if ( ws.connect() ) + res = ws.send(websocketstr); + printf("Reconnects : %05d, Messages Sent : %05d, Websocket send returned : %d.\r\n", reconnects, counter, res); + + if ( -1 == res ) { - // Reconnected - reconnects ++; + printf("Websocket Failure, reconnecting .... \r\n"); + ws.close(); + if ( ws.connect() ) + { + // Reconnected + reconnects ++; + } + else + { + // Failure! + break; + } } - else - { - // Failure! - break; - } + + wait_ms(1000); } - - wait_ms(1000); + else + { + printf("WiFi Connection Lost .... \r\n"); + } if ( pc.readable() ) { @@ -192,7 +200,7 @@ else { buf[0] = '\0'; - printf("Failed to Recv\r\n"); + printf("TCP : Failed to Recv\r\n"); break; } @@ -205,7 +213,10 @@ break; } } - socket.close(); + if ( wifi.is_connected() ) + { + socket.close(); + } printf("Completed.\r\n"); } } @@ -246,5 +257,15 @@ pc.getc(); break; } + + if ( wifi.is_connected() ) + { + break; + } + } + + if ( wifi.is_connected() ) + { + server.close(); } } \ No newline at end of file
diff -r 4e5e094a81c0 -r 506f580e7ead wifi.cpp --- a/wifi.cpp Wed Oct 09 00:59:47 2013 +0000 +++ b/wifi.cpp Sat Oct 12 22:10:17 2013 +0000 @@ -4,7 +4,8 @@ using namespace mbed_cc3000; -tUserFS user_info; +tUserFS cc_user_info; + const char * WIFI_STATUS[] = {"Disconnected", "Scanning", "Connecting", "Connected"}; /* cc3000 module declaration specific for user's board. Check also init() */ @@ -91,7 +92,7 @@ int32_t status = 0; tNetappIpconfigRetArgs ipinfo2; - wifi.get_user_file_info((uint8_t *)&user_info, sizeof(user_info)); + wifi.get_user_file_info((uint8_t *)&cc_user_info, sizeof(cc_user_info)); wifi.get_mac_address(myMAC); printf(" MAC address : %02x:%02x:%02x:%02x:%02x:%02x\r\n", myMAC[0], myMAC[1], myMAC[2], myMAC[3], myMAC[4], myMAC[5]); @@ -122,6 +123,11 @@ printf(" Gateway : %d.%d.%d.%d \r\n", ipinfo2.aucDefaultGateway[3], ipinfo2.aucDefaultGateway[2], ipinfo2.aucDefaultGateway[1], ipinfo2.aucDefaultGateway[0]); printf(" Subnet : %d.%d.%d.%d \r\n", ipinfo2.aucSubnetMask[3], ipinfo2.aucSubnetMask[2], ipinfo2.aucSubnetMask[1], ipinfo2.aucSubnetMask[0]); printf(" DNS : %d.%d.%d.%d \r\n", ipinfo2.aucDNSServer[3], ipinfo2.aucDNSServer[2], ipinfo2.aucDNSServer[1], ipinfo2.aucDNSServer[0]); + + printf(" Cached IP : %s \r\n", wifi.getIPAddress()); + printf(" Cached Gateway : %s \r\n", wifi.getGateway()); + printf(" Cached Subnet : %s \r\n", wifi.getNetworkMask()); + } else { @@ -129,11 +135,11 @@ } // This doesn't work for the wifi dip - printf(" FTC %i\r\n",user_info.FTC); - printf(" PP_version %i.%i\r\n",user_info.PP_version[0], user_info.PP_version[1]); - printf(" SERV_PACK %i.%i\r\n",user_info.SERV_PACK[0], user_info.SERV_PACK[1]); - printf(" DRV_VER %i.%i.%i\r\n",user_info.DRV_VER[0], user_info.DRV_VER[1], user_info.DRV_VER[2]); - printf(" FW_VER %i.%i.%i\r\n",user_info.FW_VER[0], user_info.FW_VER[1], user_info.FW_VER[2]); + printf(" FTC %i\r\n",cc_user_info.FTC); + printf(" PP_version %i.%i\r\n",cc_user_info.PP_version[0], cc_user_info.PP_version[1]); + printf(" SERV_PACK %i.%i\r\n",cc_user_info.SERV_PACK[0], cc_user_info.SERV_PACK[1]); + printf(" DRV_VER %i.%i.%i\r\n",cc_user_info.DRV_VER[0], cc_user_info.DRV_VER[1], cc_user_info.DRV_VER[2]); + printf(" FW_VER %i.%i.%i\r\n",cc_user_info.FW_VER[0], cc_user_info.FW_VER[1], cc_user_info.FW_VER[2]); } /** @@ -176,7 +182,7 @@ wait_ms(500); printf("Waiting for dhcp to be set.\r\n"); } - user_info.FTC = 1; + cc_user_info.FTC = 1; wifi.set_user_file_info((uint8_t *)&user_info, sizeof(user_info)); wifi._wlan.stop(); printf("FTC finished.\r\n");
diff -r 4e5e094a81c0 -r 506f580e7ead wifi.h --- a/wifi.h Wed Oct 09 00:59:47 2013 +0000 +++ b/wifi.h Sat Oct 12 22:10:17 2013 +0000 @@ -34,7 +34,7 @@ #define USE_SMART_CONFIG 0 // Default SSID Settings - #define SSID "soldersplash" +#define SSID "soldersplash" #define AP_KEY "wifidipcortex" #define AP_SECURITY WPA2