ZigBee Power Management using Pin Sleep example for mbed XBeeLib By Digi

Dependencies:   XBeeLib mbed

Description

This example characterizes a device that, after taking samples from some sensors and sending the information collected through the radio, does nothing for a long period of time that could range from several minutes to several hours.
In that long period of inactivity it is not expected to have communication with the coordinator, so the device will not be able to receive packets and can to save as much power as possible; so the radio is set into low power mode.

The example does the following cycle endlessly:

  • Some sensor is read. For demonstration, a counter is incremented.
  • A message containing the collected data is sent to the coordinator.
  • After the data has been sent, the radio will go to sleep:
  • First, the radio is requested to go to sleep. When radio finally sleeps, then the application waits for the time configured in the SLEEP_SECONDS macro. By default it is set to 40 seconds but it can be changed as desired.
  • After that time, the application will awake the radio through the On/Sleep pin and another cycle starts.

Setup

Application

Define RADIO_SLEEP_REQ and RADIO_ON_SLEEP in config.h file according to the mbed micro-controller GPIOs that will be used to control the XBee module power.

Hardware

It is necessary to wire following connections from the mbed micro-controller to the XBee radio according to the configuration done in the application:

  • From the mbed micro-controller RADIO_SLEEP_REQ to the XBee module SLEEP_RQ pin (pin 9 on THT modules, pin 10 on SMT modules) will allow the mbed micro-controller to request the radio to sleep or awake.
  • From the mbed micro-controller RADIO_ON_SLEEP to XBee module ON/SLEEP# pin (pin 13 on THT modules, pin 26 on SMT modules) will allow the mbed micro-controller to know if the radio is awake or slept.

Firmware

In S2B modules, router firmware will not work for this example, because routers don't support sleep modes.
Make sure the XBee module has end-device firmware.
To flash a new firmware onto an XBee module, you need to use the XCTU software.

On S2C XBee modules, the SLEEP_RQ and ON/SLEEP# pins can be used not only for power management but also as a GPIO. To run this example they have to be configured as power management functionality (mode 1):

  • SLEEP_RQ pin: "D8"=1
  • ON/SLEEP# pin: "D9"=1

Network

Make sure the coordinator has the 'Cyclic Sleep Period' (SP) and at 'Number of Cyclic Sleep Periods' (SN) options values configured so that (3*SP*10*SN) is greater than the XBee module sleep time (in this example 40 s = 40000 ms).

If SP parameter in coordinator is pre-established for example to 0x1F4=500 based on other devices requirements, SN should be configured in coordinator for this example as:

  • MaxPinSleepTime= 3 * SP * 10 * SN
  • SN= MaxPinSleepTime / 3 / SP / 10
  • SN = 40000 / 3 / 500 / 10 = 2.666 -> Rounding high -> 3 = 0x3

Remember to change this parameter in the coordinator if SLEEP_SECONDS is changed in the example.

Demo run

While the demo is running, you will see the frames sent by the XBee module through the serial console terminal.

Verify that the coordinator is receiving the frames by accessing the "Console" tab of the X-CTU.
If the frames are successfully sent, they will be displayed there. One message like the ones below should be seen every 40 seconds.

     Sensor sample: 0, next sample in 40 seconds
     Sensor sample: 1, next sample in 40 seconds

config.h

Committer:
hbujanda
Date:
2016-07-29
Revision:
7:d6ce8bb743db
Parent:
4:247facc3db2a

File content as of revision 7:d6ce8bb743db:

/**
 * Copyright (c) 2015 Digi International Inc.,
 * All rights not expressly granted are reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
 * =======================================================================
 */

#ifndef __CONFIG_H_
#define __CONFIG_H_

/** Library configuration options */
#define ENABLE_LOGGING
#define ENABLE_ASSERTIONS
#define FRAME_BUFFER_SIZE           4
#define MAX_FRAME_PAYLOAD_LEN       128

#define SYNC_OPS_TIMEOUT_MS         2000

//#define RADIO_TX                NC /* TODO: specify your setup's Serial TX pin connected to the XBee module DIN pin */
//#define RADIO_RX                NC /* TODO: specify your setup's Serial RX pin connected to the XBee module DOUT pin */
//#define RADIO_RTS               NC /* TODO: specify your setup's Serial RTS# pin connected to the XBee module RTS# pin */
//#define RADIO_CTS               NC /* TODO: specify your setup's Serial CTS# pin connected to the XBee module CTS# pin */
//#define RADIO_RESET             NC /* TODO: specify your setup's GPIO (output) connected to the XBee module's reset pin */
//#define RADIO_SLEEP_REQ         NC /* TODO: specify your setup's GPIO (output) connected to the XBee module's SLEEP_RQ pin */
//#define RADIO_ON_SLEEP          NC /* TODO: specify your setup's GPIO (input) connected to the XBee module's ON_SLEEP pin */
//#define DEBUG_TX                NC /* TODO: specify your setup's Serial TX for debugging */
//#define DEBUG_RX                NC /* TODO: specify your setup's Serial RX for debugging (optional) */

#if !defined(RADIO_TX)
    #error "Please define RADIO_TX pin"
#endif

#if !defined(RADIO_RX)
    #error "Please define RADIO_RX pin"
#endif

#if !defined(RADIO_RESET)
    #define RADIO_RESET             NC
    #warning "RADIO_RESET not defined, defaulted to 'NC'"
#endif

#if defined(ENABLE_LOGGING)
    #if !defined(DEBUG_TX)
        #error "Please define DEBUG_TX"
    #endif
    #if !defined(DEBUG_RX)
        #define DEBUG_RX                NC
        #warning "DEBUG_RX not defined, defaulted to 'NC'"
    #endif
#endif

#endif /* __CONFIG_H_ */