Stuck in waiting for credentials after flash from cloud ide

After using WiFi.setCredentials in the firmware, and running fine, after a flash of new firmware from cloud ide, the core reboots but in the listening mode even if the last credentials were ok.

So the core is automatically booting into listening mode after you’ve flashed some new firmware?

If so, either A, the credentials have somehow been cleared, or B, you’ve somehow put the core into listening mode manually. Both of these are possible and the easiest way to diagnose is for us to get a glimpse at your code. Mind posting it?

Here is the code. It’s a part of the whole program, but the one that changes the credentials.

void setCredentials(){
char s[ssid.length()+1] ;
char p[password.length()+1] ;
ssid.toCharArray(s,ssid.length()+1) ;
password.toCharArray(p,password.length()+1) ;

//
//Serial.println("Disconnecting...") ;
//WiFi.disconnect();

//WiFi.clearCredentials() ;

if (securityMode == 0){
    Serial.println("Setting credentials, no passord...") ;
    WiFi.setCredentials(s);
} else if (securityMode == 1 || securityMode == 2){
    Serial.println("Setting credentials WEP...") ;
    WiFi.setCredentials(s,p,WEP);
} else if (securityMode == 3){
    Serial.println("Setting credentials WPA...") ;
    WiFi.setCredentials(s,p,WPA) ;
} else if (securityMode == 4){
    Serial.println("Setting credentials WPA2...") ;
    WiFi.setCredentials(s,p,WPA2) ;
}
/*
Serial.print("Waiting for connection...") ;
WiFi.connect() ;

Serial.println("Connecting to cloud...") ;    
Spark.connect() ;
if (WiFi.ready()){
    Serial.println("WiFi Ready") ;
    Serial1.println("I/OK") ;
} else {
    Serial.println("WiFi Not ready") ;
    Serial1.println("I/ERROR") ;
}
*/

//delay(20000) ;
int start = millis() ;
while (millis() - start < 20000){
    SPARK_WLAN_Loop();
}
Serial1.println("I/OK") ;

}