System Semi-Automatic Mode

Hello there,

I switched to Semi-Automatic Mode for my project because I need data logging to be running over night for days at a time, and for any reason if the Cloud disconnects my user code stops, while it trys to reconnect I’ve read up on the “blocking” that the Core currently does; So I figured Semi-Automatic Mode :smiley: skip the Cloud and go straight to WiFi connection/user-code.

But after flashing my core with my firmware, the Core immediately goes into listening mode, I try and connect with the SmartConfig App (Spark App on iPhone) and the Core goes solid blue, flashes green once, and goes right back into listening mode, it repeats this small loop for as long as I got the SmartConfig App running.

I posted code below, am I going about this the wrong way? As always any insight or direction is greatly appreciated :slight_smile:

SYSTEM_MODE(SEMI_AUTOMATIC);

unsigned long lastsync =0; 

void setup()
{
Serial.begin(115200);
}

void loop()
{
if(!WiFi.ready())
{
  WiFiSetup();
}

 if(millis() - lastSync > ONE_DAY_MILLIS){ // THIS will request a time synchronizatoin from the SparkCloud
  Spark.connect();
 timout=millis();
if (millis()-timout >= 30000){  //instead of using if(Spark.connecting()) made a 30000ms time out
  if (Spark.connected()){
  Spark.syncTime();
  lastSync = millis();
  Spark.disconnect();
  }
}


void WiFiSetup(){
WiFi.listen();
if (WiFi.listening()){
WiFi.connect();
timout=millis();
while(WiFi.connecting()){
    if (millis()- timout>=30000){
        Serial.print("Could not connect to Wifi");
        break;
        }
        }
        if(!WiFi.ready()){
            Serial.print("Failed to connect to WiFi");
            } 
            Serial.print("Connected!");
}

I’m fairly certain the WiFi.listen() puts the core into listening mode. You shouldn’t need a WiFi.listen() anywhere in your code

Thanks for the speedy reply harrisonhjones !

I only put WiFi.listen if I need to setup WiFi, lets say if WiFi disconnects. Or are you saying even in Semi-Automatic mode if WiFi drops it will go into listening mode automatically and try and reconnect?

@UST, what @harrisonhjones is saying is that the WiFi.listen() command puts the WiFi module into a mode that waits for new wifi credentials (blue flashing). In semi-automatic mode, unless you explicitly disable WiFi, it will always be on even without a cloud connection. :smile:

1 Like

I undersntand now ! Thanks peekay123