* switch from mbed to mbed-src, which works better with my board * list APs and their RSSI * read CC3000 firmware version
Dependencies: cc3000_hostdriver_mbedsocket mbed-src
Fork of cc3000_hello_world_demo_sparkfun by
Revision 10:b994a1c2b54c, committed 2014-10-24
- Comitter:
- lwrnc
- Date:
- Fri Oct 24 02:06:43 2014 +0000
- Parent:
- 9:053a5e3e4c06
- Commit message:
- use mbed-src, read firmware version, list APs; ; wifi with the precompiled mbed currently doesn't work with my board, so switch to mbed-src.
Changed in this revision
diff -r 053a5e3e4c06 -r b994a1c2b54c main.cpp --- a/main.cpp Tue Oct 14 22:48:10 2014 +0000 +++ b/main.cpp Fri Oct 24 02:06:43 2014 +0000 @@ -19,42 +19,112 @@ using namespace mbed_cc3000; +const char SSID[] = "yourap"; +const char KEY[] = "yourkey"; + /* cc3000 module declaration specific for user's board. Check also init() */ #if (MY_BOARD == WIGO) -cc3000 wifi(PTA16, PTA13, PTD0, SPI(PTD2, PTD3, PTC5), "ssid", "key", WPA2, false); +cc3000 wifi(PTA16, PTA13, PTD0, SPI(PTD2, PTD3, PTC5), SSID, KEY, WPA2, false); Serial pc(USBTX, USBRX); #elif (MY_BOARD == WIFI_DIPCORTEX) -cc3000 wifi(p28, p27, p30, SPI(p21, p14, p37), "ssid", "key", WPA2, false); +cc3000 wifi(p28, p27, p30, SPI(p21, p14, p37), SSID, KEY, WPA2, false); Serial pc(UART_TX, UART_RX); #elif (MY_BOARD == MBED_BOARD_EXAMPLE) -cc3000 wifi(p9, p10, p8, SPI(p5, p6, p7), "ssid", "key", WPA2, false); +cc3000 wifi(p9, p10, p8, SPI(p5, p6, p7), SSID, KEY, WPA2, false); Serial pc(USBTX, USBRX); #elif (MY_BOARD == SPARKFUN_WIFI_SHIELD) -cc3000 wifi(D2, D7, D10, SPI(D11, D12, D13), "demo", "ARMDEMO1", WPA2, false); //SparkFun Board on Arduino pin definitions +cc3000 wifi(D2, D7, D10, SPI(D11, D12, D13), SSID, KEY, WPA2, false); //SparkFun Board on Arduino pin definitions Serial pc(USBTX, USBRX); #elif (MY_BOARD == ADAFRUIT_WIFI_SHIELD) -cc3000 wifi(D3, D5, D10, SPI(D11, D12, D13), "demo", "ARMDEMO1", WPA2, false); //SparkFun Board on Arduino pin definitions +cc3000 wifi(D3, D5, D10, SPI(D11, D12, D13), SSID, KEY, WPA2, false); Serial pc(USBTX, USBRX); #endif + +// from http://developer.mbed.org/users/dflet/code/CC3000Test/ +typedef struct scanResults { + unsigned long numNetworksFound; + unsigned long results; + unsigned isValid:1; + unsigned rssi:7; + unsigned securityMode:2; + unsigned ssidLength:6; + unsigned short frameTime; + unsigned char ssid_name[32]; + unsigned char bssid[6]; +} scanResults; + +int8_t listAPs() { + int ret; + scanResults sr; + int apCounter; + + if ((ret = wifi._wlan.ioctl_get_scan_results(2000, (unsigned char *)&sr)) != 0) { + printf("get scan results failed ret=%d\r\n", ret); + return -1; + } + apCounter = sr.numNetworksFound; + printf("APs found: %d\r\n", apCounter); + + do { + if (sr.isValid) { + char ssidbuf[32]; + memcpy(ssidbuf, sr.ssid_name, sr.ssidLength); + ssidbuf[sr.ssidLength] = 0; + printf("ssid=%s rssi=%3d\r\n", ssidbuf, sr.rssi); + } + + if (--apCounter> 0) { + if ((ret = wifi._wlan.ioctl_get_scan_results(2000, (unsigned char *)&sr)) != 0) { + printf("get scan results failed ret=%d\r\n", ret); + return -1; + } + } + } while (apCounter > 0); + printf(("End of AP list.")); + return 0; +} + + /** - * \brief Hello World + * \brief Connect to an AP, read firmware version, and list APs * \param none * \return int */ int main() { + int i = 0; init(); /* board dependent init */ - pc.baud(9600); + pc.baud(115200); - printf("cc3000 Hello World demo. \r\n"); + // allow time to get a serial console + for (int i=10; i>=0; i--) { + wait(0.5); + pc.printf("Starting in %d\r\n", i); + } + + printf("cc3000 WiFi demo.\r\n"); wifi.init(); + printf("init done. connecting\r\n"); if (wifi.connect() == -1) { - printf("Failed to connect. Please verify connection details and try again. \r\n"); + while (++i < 10) { + printf("Failed to connect. Please verify connection details and try again. \r\n"); + wait(1.0); + } } else { - printf("IP address: %s \r\n",wifi.getIPAddress()); - printf("\r\ncc3000 connected to the Internet. Demo completed. \r\n"); + while (++i < 10) { + uint8_t v[2], ret; + + printf("IP address: %s \r\n",wifi.getIPAddress()); + wait(1.0); + + ret = wifi._nvmem.read_sp_version(v); + printf("cc3000 sp version=%d.%d ret=%x\r\n", v[0], v[1], ret); + + ret = listAPs(); + wait(60.0); + printf("\r\ncc3000 connected to the Internet. Demo completed.\r\n"); + } } wifi.disconnect(); -} - +} \ No newline at end of file
diff -r 053a5e3e4c06 -r b994a1c2b54c mbed-src.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-src.lib Fri Oct 24 02:06:43 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-src/#6f4f7ff1e53a
diff -r 053a5e3e4c06 -r b994a1c2b54c mbed.bld --- a/mbed.bld Tue Oct 14 22:48:10 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1 \ No newline at end of file