Using the test code above, but switching out
while (Particle.connected() == false) with if
(waitFor(Particle.connected, MAX_WAIT_FOR_CLOUD)) and using my
bCloudConnected variable just before sleep at
if (Particle.connected()) to avoid that function call seems to solve the network hung problem as the the Photon will recover on the next wake-up cycle and connect to the cloud.
But oddly, with no cloud connection possible, when falling out of the
Particle.disconnect(); // stop trying to connect
WiFi.off(); // abort this attempt and save power
does NOT terminate the attempt at connection and does NOT turn the WiFi off. Those calls seem to have no affect. This is true, just before sleep as well with no cloud connection. It goes to sleep in the looking for cloud state. It wakes up in that state also but the code changes noted do something that allows the device to break out of network hung and connect to the cloud. I also stretched out the delay after cloud disconnect (or in our case: stop trying to connect) to 3s to make sure to allow time for disconnect to no avail.
Then I tried not calling
Particle.disconnect() at all and just calling
WiFi.off(). This also does not abort the cloud connect attempt and does not turn the WiFi off.
So I will need some extended testing to make sure network hung is gone for good. But now there is a secondary issue that raises it’s head - how do we really abort the cloud connect attempt?