Stuck in WiFi off while attempting to use SEMI_AUTOMATIC

I’m having an issue with a simple program to test how to programmatically go into connected mode after starting up in semi-automatic mode. The attached program simply remains in WiFi off (breathing white). I know I’m likely missing something simple here. Guidance would be greatly appreciated.

SYSTEM_MODE(SEMI_AUTOMATIC)
SYSTEM_THREAD(ENABLED)

int i=0;

int led7 = D7;

void setup() {
   pinMode(led7, OUTPUT);
}

void loop() {
   int i = i+1;
   digitalWrite(led7,HIGH);
   //Serial.printlnf("System version: %s", System.version().c_str());
   delay(1000);
   digitalWrite(led7,LOW);
   //Serial.println(WiFi.localIP());
   //Serial.println(WiFi.macAddress());
   delay(1000);
   if (i>10) {
       if (!Particle.connected()) {
        flashLED();
       WiFi.on();
       WiFi.connect();
       Particle.connect();
       flashLED();
       }
   }
}

void flashLED() {
    for (int i = 1;i<6;i++){
        digitalWrite(led7,HIGH);
        delay(100);
        digitalWrite(led7,LOW);
        delay(100);
    }
}
int i = i+1;

should be

i = i+1;

or more idiomatic C++,

i++;

When you add the int declaration, this creates an entirely new variable that lasts only for the duration of the current function, so i will never be greater than one. Removing int uses the global i variable.

3 Likes

Duh…I knew it was something stupid. Many many years of programming and I couldn’t see that. Thanks!

Also reset i = 0 in your if statement.