Delay function and/or reboot not working as expected

Hi,

I’ve got basically a TWO LINE program, that I was using just to test the Spark.publish functions, and it led me into a problem with the delay statement…

Sorry I’m not sure how to make a “pretty” text box for my code here, but here’s what I have:

void setup()
{
  Spark.publish("Testing App Initializing");
}
void loop()
{
  Spark.publish("Waiting for commands");
  delay(2000);
}

So… The first time I uploaded, I get the “Testing App Initiallizing” showing up on my dashboard, then every 2 seconds, a “Waiting for commands” gets published…so, everything is as expected. But, then when I wanted to start implementing some business logic here, I decided to increase the delay to 20000, so it would only show every 20 seconds instead of every two, and I uploaded the code.

I am not physically with my photon right not, so I can’t physically boot it, but I do see on the dashboard that the device goes offline, and back online, but it never shows my “initializing” message again, and it doesn’t change the delay - I continue to get my status updates every 2 seconds.

I THINK what is happening is that the device isn’t rebooting after getting new code uploaded, but I can’t find a way to force it to reboot. What is the proper process for uploading and activating new code? It obviously rebooted itself when I initially installed the first code, because it automatically began running my publish commands, but now it’s not changing!

Any help would be greatly appreciated… This Photon looks extremely promising if I can get past some of this little stuff!!

-Steve

It might not be flashing, Try changing the Firmware version in the webIDE to 0.4.3, its a drop down menu on the left.

firmware 0.4.4 doesn’t support over the air flashing. Last I checked.

Thanks for the quick reply… My web client shows the pull-down with 2 options:
0.3.4
latest (0.3.4)

So… Apparently I am only able to do it with 0.3.4…

When you say that 0.4.3 doesn’t support ota flashing, did you transpose numbers, or is there a much more recent version if I use some local programming tool? I can RDP into the machine which it’s hooked up to (for power) but so far, everything I’ve done, even the initial download of the first, working version of the code, was over the air…

Thanks!
-Steve

So… I managed to get it to work, but I dont know how… Or, rather, I dont know exactly what caused it.

I did notice that sometimes, the flash command would come back “failed”, and although I could get a success, it still did not actually work.

Since it was intermittently failing anyway, I logged into my home computer, and turned off a bunch of things that were taking Internet bandwidth, and then I clicked flash repeatedly, until I saw several successes, and all of a sudden, the initialization message displayed again, and the new timeout has taken effect.

I am wondering if the Spark.publish, happening every 2 seconds, was interrupting my upload somehow (or corrupting it) causing it not to take effect, and I had to be persistent until I managed to randomly time an upload in between the 2 second intervals?? I dont know… just a theory. In any case, with the 20 second delay in place, I can successfully and reliably re-flash it, although I haven’t turned on my file transfer processes again yet to see if it was a bandwidth constraint…

I’ll update this thread if I learn anything else, or if someone has the answer, I’d love to hear…

Some things here.

When you say you only see this option

then I’d guess you have not selected a Photon but a Core as target device.

Second, Photon firmware 0.4.4 does allow OTA flashing of application code, if 0.4.4 system firmware is already installed. Otherwise - for the time being - it’s only possible via Particle Build (Web IDE) and not via Particle Dev or CLI, since they don’t trigger the auto-update of system firmware.
But be aware, if your system firmware needs to be updated OTA this will take a considerable time (up to 10 min) during which you should leave the device alone.

Next, if you want your device to show maximum responsiveness you should rather go for “soft delay” than for delay()

e.g.

uint32_t msDelay;

...
void loop()
{
  if (millis() - msDelay > 20000)
  {
    Spark.publish("Waiting for commands");
    msDelay = millis();
  }
}
1 Like

I’m not sure where you got that from, but I can assure you that 0.4.4 DOES allow OTA firmware flashing.

And please DON’T go back to 0.4.3 unless you’ve got a really good reason to do so. 0.4.4 had a great deal of bugfixes that makes sure the photon is more stable, as well as fixing some previously broken functionalities.

3 Likes