result.wakeupPin() doesn't return a value

I’m trying to determine which pin is the reason for my device waking up, but the below code doesn’t work.
only the 'whichpin" prints in the Log and no int
The if/else block doesn’t trigger at all either.

I’m following the example here: Sleep 2.0 Question: SystemSleepResult or SleepResult - #6 by rickkas7

#include "Arduino.h"
#undef min
#undef max
#include "Particle.h"

const pin_t MY_LED = D7;
const pin_t REED_PIN = D6;
SystemSleepConfiguration config;
SerialLogHandler logHandler(LOG_LEVEL_INFO);
void dmy()

  digitalWrite(MY_LED, HIGH);

void setup() {

  pinMode(MY_LED, OUTPUT);
  attachInterrupt(REED_PIN, dmy, FALLING);

void loop() {
  static uint32_t ms = 0;
  Serial.printlnf("Loop started");

                    .gpio(WKP, FALLING)
                    .gpio(REED_PIN, FALLING)
                    .network(NETWORK_INTERFACE_CELLULAR, SystemSleepNetworkFlag::INACTIVE_STANDBY);
  if (millis() - ms > 5000) {
    digitalWrite(MY_LED, LOW);
    ms = millis();
  Serial.printlnf("I'm awake");
  SystemSleepResult result = System.sleep(config);
  if (result.wakeupReason() == SystemSleepWakeupReason::BY_GPIO) {

    pin_t whichPin = result.wakeupPin();"whichpin", whichPin);
    if(whichPin == D6){"D6 Wakeup received");
    }else if(whichPin == D8){"D8 Wakeup received");

That’s not how works, it’s sprintf-style formatting:

Will not work:"whichpin", whichPin);

Use this instead:"whichpin %d", (int)whichPin);
1 Like

Thank you @rickkas7 for the super fast response!

I had also messed up by basically calling sleep twice to store the result instead of store the result from the first sleep :man_facepalming:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.