Turning WiFi OFF after Failing to Connect to Cloud

Hi Community,

I’d like to turn the WiFi off after trying to connect to the WiFi but failed. This is usually due to the internet is down and the device stuck at blinking cyan.

I wrote a small test to do this:

SYSTEM_MODE(MANUAL);
SYSTEM_THREAD(ENABLED);

void setup()
{
	WiFi.on();
	Particle.connect();
}


void loop()
{
	Serial.println("Turning WiFi OFF...");
	Particle.disconnect();
	WiFi.disconnect();
	WiFi.off();
	delay(5000);
	
	Serial.println("Turning WiFi back on...");
	WiFi.on();
	Particle.connect();
	delay(5000);
}

I paired the device with a router without internet but the device stucks in blinking CYAN forever. I expected the device could go back to breathing WHITE. How am I supposed to turn the WiFi OFF?

Thank you.

Let me ping someone that might be able to help, @rickkas7 or @ParticleD are you able to assist?

I kinda figured it out.

Basically, I just set the device to listening mode and jump out of it without reconnecting. Of course, I’m using SEMI_AUTO mode of WiFi. Here’s a piece of codes.

#include "application.h"
SYSTEM_MODE(MANUAL);
SYSTEM_THREAD(ENABLED);

void turn_wifi_off();
void turn_wifi_on();

void setup()
{
	WiFi.on();
	Particle.connect();
}

void loop()
{
	Serial.println("Turning WiFi OFF...");
	turn_wifi_off();
	delay(10000);
	
	Serial.println("Turning WiFi back on...");
	turn_wifi_on();
	delay(5000);
}

void turn_wifi_off()
{
	WiFi.listen();
	delay(500);
	Particle.disconnect();
	WiFi.disconnect();
	WiFi.off();
	delay(500);
	WiFi.listen(FALSE);
	WiFi.off();
}

void turn_wifi_on()
{
	WiFi.on();
	Particle.connect();
}

What to expect is that the led turns breathing WHITE when turning the WiFi off and turns breathing CYAN when turning the WiFi ON.

The logic sounds wired but it manages to reboot the Antenna otherwise it would stuck in blinking CYAN forever.

1 Like