Photon 2 wake from hibernation by RTC results in WakeUpReason = 0

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); 
}

Hi, I imagine you can use resetReason as discussed here and there:

Best,

EDIT: Oh I see now, this does not help - sorry

I believe the wake reason can't be saved when using HIBERNATE sleep mode on RTL872x devices due to a hardware limitation. The wake reason should work properly in STOP and ULP modes.

No worries, it's the thought that counts. :wink:

1 Like

Okay.

I think other developers would benefit from this info being added to the Particle firmware reference.

Thanks for confirming my suspicions,
Cethalon