Hello!
Is there a way to determine if a photon 2 wakes up via GPIO or RTC from hibernation?
I'm trying to build a program for the Photon 2 that hibernates in one day intervals when external power is not applied.
The Photon 2 can only sleep for ~9 hours at a time. To get around this I was hoping to save the SystemSleepResult wakeupReason to a retained variable that I check in Setup() upon wakeup. Ideally Photon 2 would quickly re-enter hibernation every 9 hours until it's woken up by a GPIO signal.
The issue is that wakeupReason() always returns 0 when I wake from hibernation. Short of adding an external RTC, Is there a workaround for this issue?
Here is a sample code that reproduces the issue I am experiencing.
#include "Particle.h"
SYSTEM_MODE(MANUAL);
SYSTEM_THREAD(ENABLED);
SerialLogHandler logHandler(LOG_LEVEL_INFO);
retained SystemSleepResult result;
retained uint8_t firstwake = 0;
void preSetup() {
System.enableFeature(FEATURE_RETAINED_MEMORY);
};
STARTUP(preSetup());
void setup() {
Serial.begin(115200);
while(!Serial.isConnected());
Log.info("Start");
if(!firstwake) firstwake = 1;
else
{
if(result.wakeupReason() == SystemSleepWakeupReason::BY_RTC) Log("Woke up by RTC");
else if(result.wakeupReason() == SystemSleepWakeupReason::BY_GPIO) Log("Woke up by GPIO");
else Log("Woke up by unknown reason: %i",result.wakeupReason());
}
}
void loop() {
SystemSleepConfiguration hibernateSleepForV4;
hibernateSleepForV4
.mode(SystemSleepMode::HIBERNATE)
.gpio(WKP, RISING)
.gpio(D3, FALLING)
.duration(5000);
result =System.sleep(hibernateSleepForV4);
}