Spark Core not updating with new code

I’ve been working on some code using TCPClient, and have been updating it regularly after using the Serial monitor to debug. However, the most recent code updates have not been loaded (although the flash has said successful) and the core continues to function as if the old code is still there (I reloaded a very basic program just to test, and I’m getting serial output from the old program).

I’m using spark dev from a mac. Has anyone run into this? Am I missing something? I’ve tried unplugging, closing and restarting programs, resetting the core (holding mode for 10sec)…to no avail.

Thanks.

Just to be sure: what happens when you do that, does it start blinking blue? It might be that you’re only erasing the credentials, not actually resetting it.
In order to do a factory reset, you have to hold down the MODE button, and tap the RESET button. Continue holding the MODE button until it starts flashing white.

I have run into this particularly after using the web IDE… I simply forget to save and compile my sketch before I upload it… the web IDE will do that automatically, the spark dev app for mac doesn’t.

I always feel foolish when I get frustrated with not seeing my expected changes!!! :wink:

1 Like

Maybe I wasn’t doing a factory reset, it was only blinking blue. I’ll try that also, although I’d still like to know why this was happening.

As for saving and compiling, I’ve been doing those things as well. Sometimes multiple times just to make sure I didn’t forget…

Update: A factory reset worked, but this keeps happening sporadically. Not really sure what’s going on…

I hate to bring up an old thread, but I’ve experienced this issue several times over the past week. It’s very annoying having to factory reset every time and start fresh.

Have you ever considered using DFU instead of factory reset?
And have you been able to eliminate any other reasons for being unable to flash OTA than a bug?

The OPs problems revolved around Particle Dev and his use of it (as I’d suspect rereading the thread).

Good point, I didn’t think to try that. It worked on the second try when adding --force, but it failed on the first try with the following error:

Error writing firmware…Incorrect platform id (expected 0, parsed 11017), use --force to override

I should have added more detail to my post earlier. I was only using the webIDE to flash the core, and saved and compiled before I did with no error. Although the WebIDE message said it had flashed successfully, I noticed that my core never flash magenta, it only did a high-speed cyan flash.

I spoke to soon. I was able to get my code on the core using DFU, and it listed my new variable when doing particle list, however any call to the core would time out. I had to do a factory reset in order to get things going again.

Without seeing your code things are left to guessing :wink:

Here’s what I have so far.

#include "Adafruit_DHT/Adafruit_DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT22

DHT dht(DHTPIN, DHTTYPE);

double h = 0;
double t = 0;
double f = 0;
int relayPin = D6;

int toggleRelay(String command){
    if(relayState("switch") == 1){
        digitalWrite(relayPin, LOW);
        return 0;
    }else{
        digitalWrite(relayPin, HIGH);
        return 1;
    }
}

int relayState(String command){
    if(digitalRead(relayPin) == HIGH){
        return 1;
    }else{
        return 0;
    };
}

void setup() {
	dht.begin();
	pinMode(DHTPIN, INPUT);
	pinMode(relayPin, OUTPUT);
	Particle.function("toggleRelay", toggleRelay);
	Particle.function("relayState", relayState);
	Particle.variable("temp", t);
}

void loop() {
	delay(2000);

	h = dht.getHumidity();
	t = dht.getTempCelcius();
	f = dht.getTempFarenheit();
	
	Particle.publish("temp", String(t));
}

Hopefully you’ll be able to spot an issue… this is all new to me. Thanks for the help!

I see, you are using the Adafruit_DHT22 library.
Try using the Piettetech_DHT library instead, since this has proven to be less prone to blocking, which can cause cloud drops.

In order to keep your device responsive you might also do away with delay(2000) and rather do this

uint32_t msSoftDelay;

void loop() {
  if (millis() - msSoftDelay >= 2000) {
    msSoftDelay = millis();
    h = dht.getHumidity();
    t = dht.getTempCelcius();
    f = dht.getTempFarenheit();
	
    Particle.publish("temp", String(t));
  }
}

You are also publishing an event with a all but unique name, which might be used by loads of other people too.
Try coming up with a less common name and/or publish as PRIVATE rather than default PUBLIC.

Particle.publish(String eventName, String data, int ttl, PRIVATE);

see https://docs.particle.io/reference/firmware/core/#particle-publish-

1 Like

Thanks for the tips! I’ll give the other library a try and update my loop. The publish was just a test and should have been removed before posting here, I knew it would bring up some red flags :smile:

I’ll test it out tonight (hopefully) and post the results.

I tried to replicate the issue with the Piettetech_DHT library and so far so good, it hasn’t locked up.

Thanks for the help @ScruffR!

3 Likes