For a battery operated setup I tried to use the System.sleep(SLEEP_MODE_DEEP, 10) function. Some time ago I was able to use it working very well. I don’t remember anymore the version of the firmware, I presume it was 4.5. Now however I can’t get it working anymore. I’m using the web compiler BTW.
Looking at the program below I expect it to make connection to WiFi, wait for 2 seconds, go to deep sleep mode (no light) and start again connecting to the WiFi after 10 seconds and the cycle continuoes endless.
Actually most of the times the Photon will not sleep at all but starts connecting to WiFi right after disconnecting from WiFi. Sometimes (mayby 1 in 20 resets) it will go to deep sleep but will never wake.
I tried all firmware versions but the results are the same, none of them works as expected. This might be due the fact that the bootcode of the Photon is updates to 4.7 and is not downgraded when I compile with an old firmware version.
I left the delay(2000) in the code since it’s necessary to maintain the WiFi connection for at least one second when you publish something, otherwise the WiFi is disconnected before the publish is finished.
Is this a bug? I my program not correct? Who can give the answer?
There are some issues with the sleep modes that crept in during updates but these are being worked on and are milestoned for 0.4.8.
But AFAIK these are mainly revolving about wake-on-interrupt, but I’ll test your sketch and maybe update the open issues accordingly.
Update:
OK, I’ve now tested your code with two 0.4.7 Photons and with my devices it works just fine.
So I can’t really see a problem with System.sleep(SLEEP_MODE_DEEP, wakeOnTime); - wake-on-interrupt/wake-on-pin tho’ does not work as expected.
One thing to consider is the power supply tho’. Are you powering your Photon off a USB port or a wall-wart/charger?
If you’ve got a charger, its DC might not be filtered well enough, causing some power fluctuations causing to wake prematurely.
Have you got any figures how long this would be, I've tested about an hour with the code above, and haven't seen a problem, but with different figures (running time, sleep time, test duration) things might look different, although they should not with DEEP_MODE_SLEEP and without backup RAM.
Thanks for testing the code.When I read the answers I realised one difference existed between our test setups. I did not expect it to matter but it did actually.
In my test I had the Photon connected to a SparkFun Photon Battery Shield (without a battery). This shield uses a MAX17043 connected to D0 and D1. With the shield the Photon resets immidiately, without the shield it works like it should ie it waits 10 seconds before resetting. The Photon was powered via USB from my laptop.
So it turns out that the System.sleep(SLEEP_MODE_DEEP, wakeOnTime) function is affected by having D0 and/or D1 connected. In the manual I could not find any clue to this behaviour. Can this be a bug?
Reading further in the manual I found the function System.sleep(uint16_t wakeUpPin, uint16_t edgeTriggerMode, long seconds). I thought that by moving the wakeUpPin to an unused pin (ie no D0/D1) as a workaround I would be able to get my requested behaviour of sleeping for 10 seconds and then a reset of the Photon because the Photon would no longer react to the D0 and D1 pins. I tried lot’s of combinations of the wakeUpPin and edgeTriggerMode but they all sleep endlessly instead of resetting after 10 seconden, this was without having the battery shield connected. Just to be sure I also grounded some the wakeUpPins but that made no difference like I expected. Is this one of the issues you mentionned above?
Thanks for confirming the issue. According to the System.sleep(uint16_t wakeUpPin, uint16_t edgeTriggerMode, long seconds) function, my issue there is not the not wakening on a pin but the time out which did not work.