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.
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 |
#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.