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
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
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
disconnect() functions shown in the linked post above.
So far I have done the following:
- 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.
- Shown the connection/disconnection code on its own does not freeze
- Shown my code without any connection/disconnection does not freeze
Particle.connected()before calling any cloud functions
- Logged using printf around the connect/disconnect code, this seems to solve the issue leading me to believe it may be timing related?
- 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
- Double checked all
newstatements have a matching
- Replaced unsafe functions e.g. strcpy with safer versions e.g. strlcpy
- 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.
I’m running with