sleep() [ Sleep ]

SystemSleepResult class

Since 1.5.0:

The SystemSleepResult class is a superset of the older SleepResult class and contains additional information when using System.sleep() with the newer API.

wakeupReason() (SystemSleepResult)

SystemSleepWakeupReason wakeupReason() const;

SystemSleepConfiguration config;
      .gpio(D2, FALLING)
SystemSleepResult result = System.sleep(config);
if (result.wakeupReason() == SystemSleepWakeupReason::BY_GPIO) {
  // Waken by pin 
  pin_t whichPin = result.wakeupPin();

Returns the reason for wake. Constants include:

Constant Purpose
SystemSleepWakeupReason::UNKNOWN Unknown reason
SystemSleepWakeupReason::BY_GPIO GPIO pin
SystemSleepWakeupReason::BY_RTC Time-based
SystemSleepWakeupReason::BY_LPCOMP Analog value
SystemSleepWakeupReason::BY_USART Serial
SystemSleepWakeupReason::BY_CAN CAN bus
SystemSleepWakeupReason::BY_BLE BLE
SystemSleepWakeupReason::BY_NETWORK Network (cellular or Wi-Fi)

wakeupPin() (SystemSleepResult)

pin_t wakeupPin() const;

If wakeupReason() is SystemSleepWakeupReason::BY_GPIO returns which pin caused the wake. See example under wakeupReason(), above.

error() (SystemSleepResult)

system_error_t error() const;

If there was an error, returns the system error code. 0 is no error.

toSleepResult() (SystemSleepResult)

SleepResult toSleepResult();
operator SleepResult();

Returns the previous style of SleepResult. There is also an operator to automatically convert to a SleepResult.