Hi,
I had to implement a timeout at work. Unrolling all the calls didn’t seem to lend itself as an easy solution, so I changed the while() loop in Start_Smart_Config() in core-firmware/src/spark_wlan.cpp. I only wanted to time out if there were credentials, and I found an easy way to reset was to do a deep sleep for 1 second. Get into listen mode as described above; these changes will reset the core after 5 minutes if the core has credentials (remove the tests if you don’t need that feature).
void Start_Smart_Config(void)
{
+ unsigned long SCtimeout;
+ boolean EnableSCtimeout = false;
+
WLAN_SMART_CONFIG_FINISHED = 0;
WLAN_SMART_CONFIG_STOP = 0;
WLAN_SERIAL_CONFIG_DONE = 0;
WLAN_CONNECTED = 0;
WLAN_DHCP = 0;
WLAN_CAN_SHUTDOWN = 0;
SPARK_CLOUD_SOCKETED = 0;
SPARK_CLOUD_CONNECTED = 0;
SPARK_FLASH_UPDATE = 0;
SPARK_LED_FADE = 0;
LED_SetRGBColor(RGB_COLOR_BLUE);
LED_On(LED_RGB);
WiFi.disconnect();
/* Create new entry for AES encryption key */
nvmem_create_entry(NVMEM_AES128_KEY_FILEID,16);
/* Write AES key to NVMEM */
aes_write_key((unsigned char *)(&smartconfigkey[0]));
wlan_smart_config_set_prefix((char*)aucCC3000_prefix);
/* Start the SmartConfig start process */
wlan_smart_config_start(1);
WiFiCredentialsReader wifi_creds_reader(wifi_add_profile_callback);
/* Wait for SmartConfig/SerialConfig to finish */
+ SCtimeout = millis() + 5*60*1000; // set timeout to 5 minutes in the future
+ EnableSCtimeout = WiFi.hasCredentials(); // enable timeout only if I have credentials
while (WiFi.listening())
{
if(WLAN_DELETE_PROFILES)
{
int toggle = 25;
while(toggle--)
{
LED_Toggle(LED_RGB);
Delay(50);
}
WiFi.clearCredentials();
WLAN_DELETE_PROFILES = 0;
+ EnableSCtimeout = false; // I no longer have credentials so don't timeout
}
else
{
LED_Toggle(LED_RGB);
Delay(250);
wifi_creds_reader.read();
}
+ // reset if I have I have credentials and I've been here too long
+ if( EnableSCtimeout && ((long)(millis() - SCtimeout) >= 0) )
+ Spark.sleep(SLEEP_MODE_DEEP,1);
}
LED_On(LED_RGB);