Connect to SSID, get ip by dhcp, ping google.com, display statistics
Dependencies: NVIC_set_all_priorities cc3000_hostdriver_mbedsocket mbed
Diff: main.cpp
- Revision:
- 1:1ef047ffeef4
- Parent:
- 0:26d9788555b6
- Child:
- 3:f38499c4000e
diff -r 26d9788555b6 -r 1ef047ffeef4 main.cpp
--- a/main.cpp Sat Sep 14 05:13:00 2013 +0000
+++ b/main.cpp Sun Sep 15 14:41:26 2013 +0000
@@ -28,6 +28,13 @@
Serial pc(USBTX, USBRX);
cc3000 wigo(PTA16, PTA13, PTD0, SPI(PTD2, PTD3, PTC5), PORTA_IRQn);
+tUserFS user_info;
+
+#ifndef CC3000_UNENCRYPTED_SMART_CONFIG
+ const uint8_t smartconfigkey[] = {0x73,0x6d,0x61,0x72,0x74,0x63,0x6f,0x6e,0x66,0x69,0x67,0x41,0x45,0x53,0x31,0x36};
+#else
+ const uint8_t smartconfigkey = 0;
+#endif
/** Print cc3000 information
* \param none
@@ -35,7 +42,6 @@
*/
void print_cc3000_info() {
uint8_t myMAC[8];
- tUserFS user_info;
printf("MAC address + cc3000 info\n");
wigo.get_user_file_info((uint8_t *)&user_info, sizeof(user_info));
@@ -78,7 +84,7 @@
// Wi-Go set current to 500mA since we're turning on the Wi-Fi
SET_PWR_EN1;
SET_PWR_EN2;
-
+
NVIC_SetAllPriority(3);
NVIC_SetPriority(SPI0_IRQn, 0x0); // Wi-Fi SPI interrupt must be higher priority than SysTick
NVIC_SetPriority(PORTA_IRQn, 0x1);
@@ -87,7 +93,24 @@
CLEAN_PORT_INTERRUPT;
}
-/** Main function
+/** First time configuration
+ * \param none
+ * \return none
+ */
+void do_FTC(void) {
+ printf("Running First Time Configuration\n");
+ wigo.start_smart_config(smartconfigkey);
+ while (wigo.is_dhcp_configured() == false) {
+ wait_ms(500);
+ printf("Waiting for dhcp to be set.\n");
+ }
+ user_info.FTC = 1;
+ wigo.set_user_file_info((uint8_t *)&user_info, sizeof(user_info));
+ wigo._wlan.stop();
+ printf("FTC finished.\n");
+}
+
+/** Ping a site
* \param none
* \return int
*/
@@ -100,16 +123,29 @@
print_cc3000_info();
printf("Attempting SSID Connection\n");
+#if (USE_SMART_CONFIG == 1)
+ if (user_info.FTC == 1) {
+ wigo._wlan.ioctl_set_connection_policy(0, 1, 1);
+ } else {
+ printf("Smart config is not set, starting configuration\n");
+ do_FTC();
+ printf("Smart config is set. Please restart your board.\n");
+ while(1);
+ }
+#else
+ wigo._wlan.ioctl_set_connection_policy(0, 0, 0);
+
+
#ifndef CC3000_TINY_DRIVER
- #ifdef AP_KEY
- connect_to_ssid((uint8_t *)SSID,(uint8_t *)AP_KEY,AP_SECURITY);
- #else
- connect_to_ssid((uint8_t *)SSID);
- #endif
+#ifdef AP_KEY
+ connect_to_ssid((uint8_t *)SSID,(uint8_t *)AP_KEY,AP_SECURITY);
#else
- connect_to_ssid((uint8_t *)SSID);
+ connect_to_ssid((uint8_t *)SSID);
#endif
-
+#else
+ connect_to_ssid((uint8_t *)SSID);
+#endif
+#endif
printf("DHCP request\n");
while (wigo.is_dhcp_configured() == false) {
wait_ms(500);