I have a few photons and an electron that sends data to the cloud. Both use the same code, but the photons hang frequently (once a day). Usually the light is breathing green which means no cloud connection, but sometimes they are breathing cyan but there is no data being transmitted. I have added a couple of techniques from the community to prevent just thing thing but it does not work. Would appreciate any help!
Lease time is 1 day. Dynamic assignment but “sticky” i.e. same IP for the same MAC unless it runs out. I did say hangs once a day, but sometimes a bit more frequent than that i.e. 2-3 times.
Since your loop() has no considerable delay (which is a good thing normally) the above code block will cause you trouble.
Due to the fact that the cloud connection process will take several seconds but your loop() will execute thousands of times meanwhile, you will constantly knock the connection back in the process.
Make this a one shot process or add a waitFor(Particle.connected, sampletime_ms); after the Particle.connect() statement.
Thanks for the response. I am using only one thread i.e. not using SYSTEM_THREAD(ENABLED).
So it is a one shot process, therefore would not Particle.connect() block ?
It looks like Particle.connect() has a timeout of 5 seconds ? When I deliberately block the Photon’s IP address and therefore disconnect it from the cloud the Serial monitor shows:
Also I noticed that when I reenable the blocked IP address, then while the Photon is reconnecting to the cloud, Particle.connect() returns very quickly giving lots of loops (100’s ?) in a 30 seconds interval.
Still does not explain why the Photon itself disconnects periodically from the cloud and this loop and the watchdog does not allow it to reconnect.
Also unlike when I blocked the IP address and then removed the block, it recovered as expected with the Particle.connect() command. But when it looses cloud connectivity on its own, it NEVER reconnects, even though I have that check in the loop AND the Application Watchdog.
Do you have the ability to test with just one Internet connection input source instead of two? That may be the cause of problem for some unknown reason.
Trying a different access point would also let you know if it’s possibly your special router or not.
Unfortunately I've tried just about everything including a different physical location and therefore different AP and internet connection, still the same symptom. Also saw elsewhere in the forum
"Alas, it is not enough to use non-blocking delays with millis(). I use it everywhere, but despite that I was always loosing cloud connectivity after a while with several such non-blocking functions. After loosing cloud connectivity the Photon did not reconnect by itself and I had to reset it."
Seems like others have this issue as well even of the code in loop does not have a delay ?
Has something to do with coding because I have a Photon here that has ALWAYS reconnected automatically after letting it run for about at least 6 months. The Photon has been rock solid for me in all respects.
I have a similar problem with my photon locking up every few days. I have enabled the HW watchdog and have a simple logger using the static RAM that records what the photon was doing before it locked up. Once locked up, the watchdog will expire and the photon will reboot. When it comes back up, I can query the static RAM and learn what it was doing just prior to locking up.
I would like someone to inspect CloudClass::publish() in spark_wiring_cloud.cpp (line 52 in my version). The line in question is:
Oops, I hit enter too soon! Note that the wait() function is called w/o any parameters. Digging through spark_wiring_async.h and you’ll find FutureImpleBase::wait( ). With no parameters, the timeout will be set to 0 which means “never timeout”.
My logging indicates that the photon had just called a function that sometimes issues Particle.publish( ) when an error occurs. So far the evidence points to Particle.publish() never returning… That wait() could be the problem.
Under certain circumstances Particle.publish will block for up to 5 minutes, but it does eventually return. That's presumably longer than your watchdog timer.
This post explains a variety of conditions in which Particle.publish will block and how to avoid them:
I’m having the same problem (Photons disconnect once a day or so, never to reconnect). It only does this at one customer site but I’ve got other devices at that site which stay online.
After reading this thread, I tried adding the watchdog example straight out of the link above into void setup() . This caused my program to hang and never proceed to the main loop.
Router is Airport Extreme. The Photons have DHCP reservations in the Extreme, so they always get the same IP after reboot.
It’s on a ranch and they have flaky internet. 10-20 disconnection events per day are reported by Particle Console (and also by some IP cameras at the same site).
The cameras always come back, and 2 Raspberry Pi units I have there also come back although I had to implement some code that would ping 8.8.8.8 and if not found, restart wifi.