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"
SYSTEM_MODE(MANUAL);
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);
pinMode(REED_PIN, INPUT_PULLUP);
attachInterrupt(REED_PIN, dmy, FALLING);
Serial.begin(57600);
}
void loop() {
static uint32_t ms = 0;
Serial.printlnf("Loop started");
delay(1000);
config.mode(SystemSleepMode::STOP)
.duration(1min)
.flag(SystemSleepFlag::WAIT_CLOUD)
.gpio(WKP, FALLING)
.gpio(REED_PIN, FALLING)
.network(NETWORK_INTERFACE_CELLULAR, SystemSleepNetworkFlag::INACTIVE_STANDBY);
if (millis() - ms > 5000) {
digitalWrite(MY_LED, LOW);
Serial.printlnf("Sleeping");
System.sleep(config);
ms = millis();
}
Serial.printlnf("I'm awake");
SystemSleepResult result = System.sleep(config);
if (result.wakeupReason() == SystemSleepWakeupReason::BY_GPIO) {
pin_t whichPin = result.wakeupPin();
Log.info("whichpin", whichPin);
if(whichPin == D6){
Log.info("D6 Wakeup received");
}else if(whichPin == D8){
Log.info("D8 Wakeup received");
}
delay(1000);
}
}