Photon freezes when connecting to the Particle cloud

I am running code on a Photon that connects to the Particle cloud once an hour to send data. However the Photon is freezing between ~1 and ~10 hours after a reset, once frozen the LED is either solid breathing blue or solid breathing white. The freeze always happens between 0 and 3 seconds after I call Particle.connect(), during this time I am doing some other “non-related” stuff and polling Particle.connected()

The issue is not with the Particle functions as a standalone connect/disconnect program shown here runs without issue.

My code runs fine when I leave the connection up and don’t call connect() or disconnect(). I have a Photon that’s been up for 6 days with no issue.

The freeze occurs when I run my code in conjunction with the connect() and disconnect() functions shown in the linked post above.

So far I have done the following:

  1. Printed out the memory usage using freeMemory() - this never falls below 50,000 so I don’t think the issue is caused by a memory leak.
  2. Shown the connection/disconnection code on its own does not freeze
  3. Shown my code without any connection/disconnection does not freeze
  4. Checked Particle.connected() before calling any cloud functions
  5. Logged using printf around the connect/disconnect code, this seems to solve the issue leading me to believe it may be timing related?
  6. Currently running a test wherein the connection code blocks (using waitUntil(Particle.connected))until a connection is established - I want to see whether I may be doing something during the connection code that causes the freeze. This is currently running for ~5 hours without freeze
  7. Double checked all new statements have a matching delete
  8. Replaced unsafe functions e.g. strcpy with safer versions e.g. strlcpy
  9. Tried various different transmit intervals from 1 to 60 mins

I am doing lots of manual memory allocation, using the heap for large objects etc. Could a NULL pointer, off by one error, dangling pointer etc, cause a freeze or would it be more likely to cause an SOS? I’m pretty sure its not memory related as the code runs fine without the connect/disconnect stuff in and the memory usage returned by freeMemory() is fairly stable.

How else can I debug this? Are there any things I should be looking out for? Are there any things I should not be doing whilst waiting for Particle.connecting() to return true?

I would be really grateful for any tips or hints from people with more experience than me who have fixed something like this before as I am pretty stuck. I am currently at the point where I have 10 Photons running with the same code but with different sections commented out to try and nail down what is causing the freeze, this is all taking ages as they run for hours before freezing.




Showing the code is a good first step :wink:

1 Like