Photon going offline then backonline intermittently

I have a program that is running on a Photon. I noticed that the Photon loses connectivity for 1 second. It is intermittent but noticeable. Generally speaking, it reconnects back in about 1 second.

What may be causing that? Any input to help resolve this problem is appreciated.

Probably your code :wink:

Sorry for that, but we have answered this kind of question already hundreds of times with all sorts of possible reasons, but if you show your code we might spot the one reason that applies to your issue and saves us the extra reiteration of all the non-issues.

Most likely reason: Blocking code.

Thank you @Scruffr. Indeed, I saw multiple posts with similar headings but those did not apply.

I will check again for blocking code. But being new in this, what are examples of such instances? I know the following instances cause blocking:

  1. Multiple publishes.
  2. Delay statements
  3. .connect statements

What else …?

Any code that keeps the flow trapped (e.g. loops) and doesn’t call Particle.process() or delay() (which implicitly calls Particle.process()) - among others.

1 Like

Hello @ScruffR

With your input from the previous message, I found out why the Photon was losing connectivity and recycling.

The reason is that I am using the Thingspeak library (writeFields) function and was using this function with small intervals (I found out that Thingspeak likes updates to be more than 15 seconds apart).

However, in my application, I receive data from a sensor at uncontrolled intervals (depending on the Environment). So is there an example that shows how I can queue the .writeField statements to give Thingspeak a chance to accept them?

In a different application that did not use Thingspeak (just Particle.Publish), I used the PublishQueue library. However, in this case, I am not sure what to do.

I would appreciate any help in that regard and thanks in advance.

I haven’t got an off the shelf solution, but if you look at the implementation of the Particle.publish() queue you could reuse that code to implement your own Thingspeak queue.
Or maybe @thingspeak can chime in on this.

There are a few examples in the ThingSpeak documentation that show how to collect several samples in a buffer and then post them all as a bulk update. You can bulk update about every 15 seconds with multiple messages. Here is an example for a particle photon. For your application, you can asynchronously store your updates and then send the bulk update request when your buffer gets to a certain length.

1 Like