How to re-flash core when in manual mode

Has anyone got any code that would allow manual mode to test for cloud connectivity for say the first 30 seconds if the user wants to re-flash the core, if no connection to go back to manual mode.

I just want to use manual mode but re-flash new programs to the core without having to connect by USB. Any ideas? I think it will be fairly easy just call spark.process() after a few delays, but I don’t want to try it out. Any suggestions?

The thing is, that Spark.connect() - which you’d need to connect to the cloud - is a blocking call.

But there are several threads dealing with interrupt driven Spark.disconnect(), to solve this - e.g. by using SparkIntervalTimer library.

Hi @rocksetta

I use a pin that pull high or low to run or go into a re-flash-me loop. I test that pin at the top of loop() and if it is high I connect to the cloud and call SPARK_WLAN_Loop(); forever.

I usually reset the core and while holding reset, I move the jumper, and then release reset. Once you are looping forever (or flashing) you can move the jumper back.

1 Like

I like the PIN idea which I saw in the documentation, but I want something more software based.

Basically if the cloud is available, then connect to it so that I can re-flash the core ~10-30 seconds on startup, after which I want it to switch to manual mode and not worry at all about the cloud until the next power on. Don’t think it should be really difficult, just can’t get my brain around it. I read some of the other threads about Spark.disconnect(), but they seem to get complex, when this should not be very difficult.

I’m not sure what you’ve read, but by using SparkIntervalTimer it’s not that big a deal - unless your main program is too big to allow for this additional lib.

I found a good description in the thread at https://community.spark.io/t/create-time-out-for-spark-connect/10351/3 but shows no code. At least I now have something to work on.

1 Like

For 0.4.0 we’re making a safe mode where you can push the mode button at startup to have the system boot in automatic mode and connect to the cloud without needing a factory reset.

Sometimes though, if user firmware is really borked on the core, since it’s entwined with the system code, safe mode may not be able to help. So there will also be a factory restore - factory reset without clearing wifi credentials - which can also quickly get you back to a working state. Exite! :slight_smile:

3 Likes

That sounds good @mdma . For the moment, I think this code will solve my problem of wanting to use manual mode but being able to flash the core for an update without using a USB cable.

// must have wifi working for startup, since automatic mode blocks until wifi is connected
// Can use cell phone hotspot as long as it is setup earlier with another cell phone.

void setup() {
    delay(2000);   //give some time to reflash the core
    delay(2000);
    delay(2000);
    delay(2000);
    delay(2000);
    delay(2000);
    delay(2000);
    delay(2000);
    delay(2000);
    delay(2000);
    Spark.disconnect(); // basically puts you in manual mode, so should ignore any poor wifi reception issues

}

void loop() {

}

About when will 0.4.0 core update be ready??

@rocksetta, I remember this topic regarding using SparkIntervalTimer to stop WiFi.listen() in a similar fashion to Spark.connect():