You are here:
Sleep mode

Table of Contents

Using sleep mode

In order to conserve energy a node may be put to a ultra-low power mode (so called sleep mode). Sleep mode is available only for nodes that were configured as end device. It is NOT possible to put to sleep coordinator and routers, as the network operation relies on them being active all the time.

The RCM_Sleep function puts the end device into sleep mode. Successful entry into sleep mode is indicated by the RCM_RESULT_OK result code. Sometimes, however, the module may not be willing to go to sleep due to the current state of operation (in ex. the module is receiving or sending packet, or waiting for acknowledgment). In such case the RCM_Sleep function returns RCM_RESULT_BUSY, and the user is encouraged to try to enter sleep mode again after some time (usually some tens of ms).

Once the module enters sleep mode, it will stop to respond to API calls until it is woken up by the RCM_Wakeup function.

An example of RCM module configuration

The following example illustrates the usage of sleep modes:

#include "rcm.h"
// Structure holding information about the connection
static RCMConnection rcm;
// Declare a structure named frameBuffer, that will fit infinite SCOM packets
// Declare a structure named messageBufferInHeap that can fit unlimited number of RCM messages
int rcm_sleeping_example(IODevice iodevice)
int result = 0;
OSTime startTime;
RCMResult rcmResult;
// get current time
startTime = OS_GetSystemTime();
// try to open the connection using specified IODevice
if (RCM_RESULT_OK == RCM_Open(&rcm, iodevice, &frameBufferInHeap, &messageBufferInHeap, OS_GetSystemTime)) {
// connection opened, run it
if (RCM_RESULT_OK == RCM_Run(&rcm)) {
// threads run successfully
// configure the RCM module
RCM_SetUID(&rcm, 0x0123456789abcdef);
if (RCM_RESULT_OK == RCM_StartNetworking(&rcm)) {
// network established successfully
while (0 == result) {
// check connection
if (RCM_RESULT_OK != RCM_GetConnectionState(&rcm)) {
// connection broke down (hardware error?)
// exit with error code
result = 2;
// try to enter sleep mode, but if the module returns busy status - try again
do {
rcmResult = RCM_Sleep(&rcm);
} while (rcmResult == RCM_RESULT_BUSY);
if (RCM_RESULT_OK != rcmResult) {
// unable to go to sleep
result = 3;
// the radio module is now powered down - wait 3 seconds
// wake up the module
if (RCM_RESULT_OK != RCM_Wakeup(&rcm)) {
// unable to wake up the module
result = 4;
// check example timeout
if (OS_GetSystemTime() - startTime > 10000) {
// timeout
// stop the RCM threads
} else {
// error
result = 2;
// finally close the connection
} else {
// error
result = 1;
return result;
Go to Top