ZUNO_SETUP_SLEEPING_MODE()

This macro defines how Z-Uno will manage power mode. It is very important to define correct mode because the behavior of the device changes dramatically depending on it. At the start, we recommend you to debug and develop your program using ZUNO_SLEEPING_MODE_ALWAYS_AWAKE mode, because that’s the easiest one.

If not specified in the project, ZUNO_SETUP_SLEEPING_MODE(ZUNO_SLEEPING_MODE_ALWAYS_AWAKE) is assumed.
ZUNO_SETUP_SLEEPING_MODE(mode) mode Mode to manage power There is only three possible values available:
  • ZUNO_SLEEPING_MODE_ALWAYS_AWAKE — device is always awake, reachable and helps to form mesh network acting as router (default mode). Used for mains powered devices.
  • ZUNO_SLEEPING_MODE_SLEEPING — device wakes up by user request (interrupt) or periodically. Does not help to form mesh. Used for battery powered devices.
  • ZUNO_SLEEPING_MODE_SLEEPING — device wakes up by user request (interrupt) or periodically. Does not help to form mesh. Used for battery powered devices. For Z-Uno V2 there are 2 variants of deep sleep mode: EM2 and EM4. EM2 provides most peripherals avaliable during it, fast wakeup, RAM retention, but it's not so effective as EM4. EM4 is most effective energy saving mode. It provides minimal consumption current about 5-7 microamps. Commonly sleeping devices are sensors or remote controls in Z-Wave network.
  • ZUNO_SLEEPING_MODE_FREQUENTLY_AWAKE — device wakes up by user request (interrupt) or on packet received. Always available but does not help to form mesh. Used for battery powered devices. In Z-Wave this type of devices is called FLiRS FLiRS is less power effective compared to previous "sleeping" type. This type commonly is used for battery powred actuators (not sensors) devices like sirens, doorlocks, valves and etc.
FLiRS — Frequently Listening Routing Slaves — the device periodically quits the sleeping mode on a short period and checks, whether a message is sent to the device. If no packets are present for this device on air, the device goes back into the sleeping mode. Awakening interval is 1 second.
In sleeping mode periodical wakeup is configured via the Z-Wave controller using the Wake Up Command Class. The period is a factor of 4 minutes, minumum is 4 minutes. Interrupt can wake up the device at any time. User can configurate custom wakeup interval using zunoSetCustomWUPTimer() function for FLiRS and sleeping modes. You are able to wake up device from sleeping EM2 or FLIRS mode device using any pin, you need just bind this pin to interrupt controller using attachInterrupt() function. If you need to wakeup device from sleeping EM4 mode you are able to do it only by means of these pins: #2, #4(A1), #11, #16(PW4), #18, #23(BTN). You can add needed pin to "wakeup" list by means of zunoEM4EnablePinWakeup() function. By default pins #18 and BTN are already binded to wakeup device from EM2/EM4 modes. Note that in sleeping and FLiRS mode devices should be explicitely sent into sleeping state. This is done using zunoSendDeviceToSleep() function. Once called, loop will not be called anymore and Z-Uno will finalize all jobs to go into sleep mode. Note that in sleeping and FLiRS mode during power consumption (deep sleep) state Z-Uno memory is not maintained. Hence it is cleaned all the time. If you want to keep some variables across sleeps you have to use NZRAM memory (very fast and do not consume enery) or EEPROM (slow and takes energy to read and write, but survive even during power off - this is a so called non-volatile memory). Note that if you selected sleeping EM4 mode and the device wasn't included to network it doesn't go deeper then EM2 mode because of SmartStart technology. So it doesn't call setup() function on each wakeup as it described below. . Note that in sleeping EM2 and FLiRS modes during power consumption (deep sleep) state Z-Uno memory is not cleaned. So your logic feels like it doesn't stop and you don't need to save & restore you variables in EEPROM. The setup() function doesn't call when devices wakes up, because you don't need to reinitialize hardware. If you need to call your code when device wakes up please use system handler ZUNO_HANDLER_WUP. Note that in sleeping EM4 mode during power consumption (deep sleep) state Z-Uno memory is not maintained. Hence it is cleaned all the time. If you want to keep some variables across sleeps you have to use EEPROM. This memory survives even during power off - this is a so called non-volatile memory. If device is in sleeping mode, the USB port is not available for uploading new sketch. Device should be woken up or turned into rescue mode before uploading new sketch. If device is in sleeping mode, the USB port is available if you connect to it, because Z-Uno 2 has separate USB controller. Device will be booted into bootloader mode when you try to open its serial port. You don't need to make any special things to flash sketch inside sleeping or FLIRS device. After changing sleeping mode Z-Uno must be excluded and included back. Z-Uno will not adopt sleeping mode change without being excluded. (A debug configuration parameter can disable this restriction).
ZUNO_SETUP_SLEEPING_MODE(ZUNO_SLEEPING_MODE_SLEEPING);
ZUNO_SETUP_SLEEPING_MODE(ZUNO_SLEEPING_MODE_ALWAYS_AWAKE);
ZUNO_SETUP_SLEEPING_MODE(ZUNO_SLEEPING_MODE_FREQUENTLY_AWAKE);
Mode setup() called loop() called Wakes up Routing for other Z-Wave devices
on interrupt periodically on command received
ZUNO_SLEEPING_MODE_ALWAYS_AWAKE once after power on eternally Yes
ZUNO_SLEEPING_MODE_SLEEPING on each wake up on each wake up if user selected EM4 mode or once after power on if selected EM2 mode. until zunoSendDeviceToSleep() is called Yes Yes No No
ZUNO_SLEEPING_MODE_FREQUENTLY_AWAKE on each wake up once after power on until zunoSendDeviceToSleep() is called Yes No Yes Yes No
Multichannel sleeping sensor example. This wakes up every 300 seconds using custom wakeup timer interval and sends reports to controller. You can try EM4/EM2 modes.


#define SLEEP_MODE SLEEP_MODE_EM4 // You can select from SLEEP_MODE_EM2, SLEEP_MODE_EM4
#define WAKEUP_CUSTOM_INTERVAL 300 // Every 300 seconds
ZUNO_SETUP_SLEEPING_MODE(ZUNO_SLEEPING_MODE_SLEEPING); // It's sleeping device 
// This is a sample of 3-channel sensor
ZUNO_SETUP_CHANNELS(
        ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp),
        ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_RELATIVE_HUMIDITY, SENSOR_MULTILEVEL_SCALE_PERCENTAGE_VALUE, SENSOR_MULTILEVEL_PRECISION_ONE_DECIMAL, SENSOR_MULTILEVEL_PRECISION_ZERO_DECIMALS, getterHum),
        ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_BAROMETRIC_PRESSURE, SENSOR_MULTILEVEL_SCALE_KILO_PASCAL, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_ZERO_DECIMALS, getterBarPa)
);

#define MY_SERIAL Serial // You can use any UART for output you want, just modify this line
uint32_t loop_count = 0; // variable that illustrates that RAM is alive during EM2 

// core will call this function every time zuno wakes from EM2 mode
// instead of setup()
void _wakeHandler(void){
    // Timer doesn't stop 
    MY_SERIAL.print("EM2 wakeup time =");
    MY_SERIAL.println(millis());
    // Check what is the reason of wakeup from EM2
    MY_SERIAL.print("WAKEUP REASON:");
    MY_SERIAL.println(zunoGetWakeReason(), HEX);
}
void setup() {
  // Set UART to output debug data
  MY_SERIAL.begin(115200);
  MY_SERIAL.println("SETUP WAS CALLED");
  // Check what is the reason of startup/wakeup from EM4
  MY_SERIAL.print("WAKEUP REASON:");
  MY_SERIAL.println(zunoGetWakeReason(), HEX);
  // setup handler for EM2 mode only
  zunoAttachSysHandler(ZUNO_HANDLER_WUP, 0, (void*) &_wakeHandler);
}
void loop() {
  MY_SERIAL.print("uptime =");
  MY_SERIAL.println(millis());
  MY_SERIAL.print("loop count =");
  MY_SERIAL.println(loop_count);
 
 if(zunoIsSleepLocked()) { // Does sleep latch is locked?
    // Here we do all sleep uninterruptable logic
    // Report all the channels
    zunoSendReport(1); // Report will block sleep anyway
    zunoSendReport(2);
    zunoSendReport(3);
    zunoSetCustomWUPTimer(WAKEUP_CUSTOM_INTERVAL);
    MY_SERIAL.println("I am ready to sleep!");
    zunoSendDeviceToSleep(SLEEP_MODE); // This just says I am ready but it doesn't stop usercode momentally & completely
                                        // User sleep latch is opened
 }
 // Here you can do something that could be interrupted by sleep mode
 // ...
 loop_count++; // Increment variable
 delay(1000);
}
// Getters 
int getterTemp() {
  return 2100+rand()%1000;
}
int getterHum() {
  return rand()%100;
}
int getterBarPa() {
  return rand()%10000;
}

    
FLIRS switchbinary LED-light example.

    byte switchValue=0;
    ZUNO_SETUP_SLEEPING_MODE(ZUNO_SLEEPING_MODE_FREQUENTLY_AWAKE);
    ZUNO_SETUP_CHANNELS(ZUNO_SWITCH_BINARY(&switchValue,NULL));
    #define MY_SERIAL Serial 
    uint32_t loop_count = 0; // the variable that illustrates that RAM is alive during FLiRS mode too
    
    void setup(){
        MY_SERIAL.begin();
        MY_SERIAL.print("BOOT REASON:");
        MY_SERIAL.println(zunoGetWakeReason(), HEX);
        zunoAttachSysHandler(ZUNO_HANDLER_WUP, 0, (void*) &_wakeHandler);
        pinMode(LED_BUILTIN, OUTPUT);
    }
    void _wakeHandler(void){
        MY_SERIAL.print("wake time:");
        MY_SERIAL.println(millis());
        MY_SERIAL.print("loop count =");
        MY_SERIAL.println(loop_count);
        MY_SERIAL.print("WAKEUP REASON:");
        MY_SERIAL.println(zunoGetWakeReason(), HEX);
    }
    void loop(){
        if(zunoIsSleepLocked()){
            // Here we do all sleep uninterruptable logic
            digitalWrite(LED_BUILTIN, switchValue != 0); // Apply switch value from controller to builtin LED
            MY_SERIAL.print("go sleep time:");
            MY_SERIAL.println(millis()); // Print moment when we are ready to go to sleep
            MY_SERIAL.print("loop count =");
            MY_SERIAL.println(loop_count);
            zunoSendDeviceToSleep(); // We don't need parameter for FLiRS here, Z-Uno will ingore parameter anyway
        }
        // Here you can do something that could be interrupted by sleep mode
        // ...
        loop_count++; // Increment variable
    }
zunoAttachSysHandler()
zunoEM4EnablePinWakeup()
zunoSendDeviceToSleep()
zunoSetCustomWUPTimer()
zunoGetWakeReason()
Get more information about Z-Wave.