[SOLVED] Photon not updating with new code

Mod edit (@harrisonhjones): Solution: see this post

I’m doing quite a big project with the Blynk library (the code now haves 500 lines), and i have this annoying issue where i need to enter DFU mode all the time just to update the code. When i flash a new code in the web API it shows no problems, but when i check if the code was actually updated, it’s just running the old code. The only workaround was entering DFU mode. Am i doing something wrong?

@NicolasCaous, your code may be preventing the OTA from properly occurring. I believe there was a discussion on this in another topic, referring to using system events to detect when an OTA is pending so you can “park” your code.

Uhmm, so what do i need to write in the code in order to make OTA fuction properly?

The easiest is to try enabling system threading and see if that fixes your problem.

That is already part of my code

Ah, in that case you’ll want to try @peekay123’s solution. Somewhere in your mainloop see if OTA is pending, if so, just wait for a little while, doing nothing else, so the OTA will trigger (ie “park your code”)

Since it works on DFU, i maybe can trigger it using System.dfu(true); I can do it via the Blynk terminal i have setup, do you think it will work?

@NicolasCaous, I haven’t tried this myself since I use a Particle.function() to put my devices in “park” mode waiting on an OTA (among other things). Take a look here:

https://docs.particle.io/reference/firmware/photon/#ota-updates

But, i don’t get it how to code this fuction.

void loop() {
    if(System.updatesPending()) {
        //DO NOTHING
    } else {
        //DO STUFF
    }
}

Is it like this?

@NicolasCaous, give it a shot. I would call Particle.process() in a while() loop in “do nothing” for good measure (system will reset after OTA).

For that i need SYSTEM_MODE(SEMI-AUTOMATIC);?

It didn’t worked, i tried like that :

void loop() {
    if(System.updatesPending()) {
        //DO NOTHING
    } else {
        //DO STUFF
    }
}

and like that:

if(System.updatesPending()) {
    while(true) {
        Particle.process();
    }
}

It worked! I solved my problem like this:

if(System.updatesPending()) {
    while(true) {
        Particle.process();
    }
}

Thanks @peekay123 and @harrisonhjones for the help! Weird, those first 2 tries should have worked…

3 Likes

Hmm, I don't really see the particular difference between the not working

and the working

Can you point me to that?

@ScruffR Made some changes in other parts of the code that could be interfering (can’t post because it’s GIGANTIC)

1 Like