Spark Core breathing blue... with a twist :)

Good evening, folks.

The situation I am currently in is that I am in the early stages of trying to develop a solution which will be predominantly used away from any form of wifi connection, but the intent is to give it a way to connect to the particle cloud when a switch is toggled.

I have used a version of @peekay123’s hack for this (from a thread back in June 2014), and have modified it so that it doesn’t use the deprecated spark_disable_wlan / cloud header files.

SYSTEM_MODE(SEMI_AUTOMATIC);

// ...

int ArmConfigSwitch = D7;

// ...

void setup()
{
    pinMode(ArmConfigSwitch, INPUT_PULLUP);

// ...

if (digitalRead(ArmConfigSwitch) == HIGH)
{
	WiFi.on();
	while (WiFi.ready() != TRUE)	//Wait for wifi to come ON
		Spark.process();

	Spark.connect();
	while (!Spark.connected())
		Spark.process();
}

// ... and continue on to the rest of the code, which just flashes some LEDs at the moment

Now then, when the ArmConfigSwitch (pin D7) is shorted to GND, the code begins executing normally and as it should do.

When the ArmConfigSwitch is shorted HIGH, the RGB LED on the core glows white briefly, and then sinks into a steadily breathing blue (at the same pace as the usual breathing cyan). If I then short the ArmConfigSwitch pin to LOW (GND) and press the reset button on the core, it goes back to flashing the LEDs as it should do.

At this point, there is no way to get the core back up onto the wifi or cloud, so it’s a quick factory reset and reclaim before re-flashing it again. Ideally I’d like to be able to flick a switch and hit the reset button to make it connect to the cloud in semi-automatic mode… but it’s eluding me.

If anyone can help me out with this it’d be sincerely appreciated.

Regards,

Steve

Do you need to denounce your switch so that you only perform that action once? Otherwise if the input is still High you will continue to execute that code.

It was in my head as a “turn the key in the housing to activate it’s ‘listen for wifi’ function for updates and/or reprogramming when plugging in the power” kind of function rather than needing to be debounced or whatnot.

It’s only there to enable code updates while not in the field, rather than having to factory wipe / reclaim over USB like I have had to do up til now.

Try WiFi.on() then WiFi.connect() then do the test for ready. Ready will only return true once an IP has been assigned, so you will need to connect.