Unable to flash code to the Spark Core from web IDE

I am able to flash the code to Spark Core from web IDE only once after a factory reset.
When I try flashing the same code for the second time, I see Red flashes, Blue flashes, burst of Cyan flashes followed by breathing Cyan on the Spark Core.
The web IDE says “Server has failed to process the request on time please try again”

Above behaviour is also noticed when I try to flash ‘Blink an Led’ sample code to the Spark Core.

Please suggest where I could be going wrong.

You might want to share the code and let us see what’s wrong? :wink:

@kennethlimcp, I observe the above mentioned behaviour even when I try to flash Spark Core with “BLINK AN LED” sample code (see below) provided by Spark.

int led = D0;  // You'll need to wire an LED to this one to see it blink.
int led2 = D7; // This one is the built-in tiny one to the right of the USB jack


void setup() {
  pinMode(led, OUTPUT);
  pinMode(led2, OUTPUT);
}

void loop() {
  digitalWrite(led, HIGH);   // Turn ON the LED pins
  digitalWrite(led2, HIGH);
  delay(1000);               // Wait for 1000mS = 1 second
  digitalWrite(led, LOW);    // Turn OFF the LED pins
  digitalWrite(led2, LOW); 
  delay(1000);               // Wait for 1 second in off mode
}

Might need to take a look at a video of your core behavior than.

It’s really hard to advice anything without much to look at…

@kennethlimcp,

Following factory reset, I am able to flash the below code to the Spark Core. When I try to flash the same code again there seems to be a problem, Please see the video here

#include <math.h>

void setup() {

}

void loop() {
    uint32_t res_0 = 0b11100010101110101110001010111010;
    double res_0_float = ((double)res_0);
    char pubStr[32];
    sprintf(pubStr,"%d",res_0_float);
    Spark.publish("logging", pubStr);
    delay(1000);
}

It seems like a Hard Fault and i’m not so familiar with that. Maybe there’s some issue with the way you are using the variable etc.

Let’s wait for someone else to take a look and comment :smiley:

So %d is not right for double-precision (sorry!). Try this:

   sprintf(pubStr,"%f",res_0_float);

There is not a lot of forgiveness in the external libraries and small errors like this can turn into bigger problems.

1 Like

@bko,
Thanks for your reply, the problem still persists despite changing to %f

sprintf(pubStr,"%f",res_0_float);

I can reproduce the problem to a degree - what follows is really diagnostics for the spark team:

  • after flashing the original code the spark is no longer able to OTA flash.
  • on restart, I don’t see the SOS, but I do get what looks like a reset:
  • white LED, then blue LED (listening), then back to white LED, then blue again - this may repeat another time (or not at all) before finally flashing green, then cyan then breathing.
  • When breathing, the cloud cannot push OTA updates and the LED never turns magenta.
  • using cli spark list shows my core as offline (after quite a long pause - I counted 30s.)
  • flashing tinker fixes the problem and OTA flash works again, so I flash the sketch above
  • spark starts up normally, gets to breathing. I attempt OTA flash again, but this fails with a stuck magenta LED, which then turns off, and eventually the core resets.
  • after reset, OTA flash doesn’t work (although spark list shows the core online.)
  • flash tinker allows OTA to work again.

With repeated attempts, I trimmed the code down to:

void loop() {
    Spark.publish("logging", "abc");    
    delay(1000);
}

This blocks OTA updates. Tried increasing the delay to 1500, didn’t help.
At 2000ms, it attempts to OTA flash, but fails with stuck magenta.
Increased to 4000ms and then the flash succeeded, but not at 2500ms, which waited for a minute before giving a stuck magenta.

So somewhere between 2500 and 4000ms lies the threshold for publishing events that is fast enough to stop OTA from happening.

@pravi - try changing your delay to 4000ms. Then it should work.

I swear there was a github issue for publish blocking OTA update but I can’t find it now.