802.15.4 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's not expected to have communication with the coordinator or other remote devices. The device will not be able to receive packets and should save as much power as possible, therefore the radio is set into low power.

The example does following cycle endlessly:

  • Some sensor is read. For demonstration, a counter is incremented.
  • For demonstration, a message containing the data collected during sampling stage is sent to a remote device.
  • After job has been done the radio will go to sleep:
  • First radio is requested to go to sleep. When radio finally sleeps, then the application waits for the time configured in the SLEEP_SECONDS define (40 seconds).
  • This time can be increased as desired.
  • After that time, the application will awake the radio through the On/Sleep pin and another cycle will start by taking a sample.

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's 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.

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 remote device is receiving the frames by accessing the "Console" tab of the XCTU.
If the frames are successfully sent, they will be displayed there, every 40 seconds.

     Sensor sample: 0, next sample in 40 seconds
     Sensor sample: 1, next sample in 40 seconds
Committer:
hbujanda
Date:
Fri Jul 29 12:12:05 2016 +0200
Revision:
7:51c99fefe504
Parent:
4:8b3ec5997504
Automatic upload

Who changed what in which revision?

UserRevisionLine numberNew contents of line
spastor 3:93a60bb107fa 1 /**
spastor 3:93a60bb107fa 2 * Copyright (c) 2015 Digi International Inc.,
spastor 3:93a60bb107fa 3 * All rights not expressly granted are reserved.
spastor 3:93a60bb107fa 4 *
spastor 3:93a60bb107fa 5 * This Source Code Form is subject to the terms of the Mozilla Public
spastor 3:93a60bb107fa 6 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
spastor 3:93a60bb107fa 7 * You can obtain one at http://mozilla.org/MPL/2.0/.
spastor 3:93a60bb107fa 8 *
spastor 3:93a60bb107fa 9 * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
spastor 3:93a60bb107fa 10 * =======================================================================
spastor 3:93a60bb107fa 11 */
hbujanda 2:2e82f1b67c1c 12
spastor 3:93a60bb107fa 13 #ifndef __CONFIG_H_
hbujanda 2:2e82f1b67c1c 14 #define __CONFIG_H_
hbujanda 2:2e82f1b67c1c 15
hbujanda 2:2e82f1b67c1c 16 /** Library configuration options */
hbujanda 2:2e82f1b67c1c 17 #define ENABLE_LOGGING
hbujanda 2:2e82f1b67c1c 18 #define ENABLE_ASSERTIONS
hbujanda 2:2e82f1b67c1c 19 #define FRAME_BUFFER_SIZE 4
hbujanda 2:2e82f1b67c1c 20 #define MAX_FRAME_PAYLOAD_LEN 128
hbujanda 2:2e82f1b67c1c 21
hbujanda 2:2e82f1b67c1c 22 #define SYNC_OPS_TIMEOUT_MS 2000
hbujanda 2:2e82f1b67c1c 23
hbujanda 2:2e82f1b67c1c 24 //#define RADIO_TX NC /* TODO: specify your setup's Serial TX pin connected to the XBee module DIN pin */
hbujanda 2:2e82f1b67c1c 25 //#define RADIO_RX NC /* TODO: specify your setup's Serial RX pin connected to the XBee module DOUT pin */
hbujanda 2:2e82f1b67c1c 26 //#define RADIO_RTS NC /* TODO: specify your setup's Serial RTS# pin connected to the XBee module RTS# pin */
hbujanda 2:2e82f1b67c1c 27 //#define RADIO_CTS NC /* TODO: specify your setup's Serial CTS# pin connected to the XBee module CTS# pin */
hbujanda 2:2e82f1b67c1c 28 //#define RADIO_RESET NC /* TODO: specify your setup's GPIO (output) connected to the XBee module's reset pin */
hbujanda 2:2e82f1b67c1c 29 //#define RADIO_SLEEP_REQ NC /* TODO: specify your setup's GPIO (output) connected to the XBee module's SLEEP_RQ pin */
hbujanda 2:2e82f1b67c1c 30 //#define RADIO_ON_SLEEP NC /* TODO: specify your setup's GPIO (input) connected to the XBee module's ON_SLEEP pin */
hbujanda 2:2e82f1b67c1c 31 //#define DEBUG_TX NC /* TODO: specify your setup's Serial TX for debugging */
hbujanda 2:2e82f1b67c1c 32 //#define DEBUG_RX NC /* TODO: specify your setup's Serial RX for debugging (optional) */
hbujanda 2:2e82f1b67c1c 33
hbujanda 2:2e82f1b67c1c 34 #if !defined(RADIO_TX)
hbujanda 2:2e82f1b67c1c 35 #error "Please define RADIO_TX pin"
hbujanda 2:2e82f1b67c1c 36 #endif
hbujanda 2:2e82f1b67c1c 37
hbujanda 2:2e82f1b67c1c 38 #if !defined(RADIO_RX)
hbujanda 2:2e82f1b67c1c 39 #error "Please define RADIO_RX pin"
hbujanda 2:2e82f1b67c1c 40 #endif
hbujanda 2:2e82f1b67c1c 41
hbujanda 2:2e82f1b67c1c 42 #if !defined(RADIO_RESET)
hbujanda 2:2e82f1b67c1c 43 #define RADIO_RESET NC
hbujanda 2:2e82f1b67c1c 44 #warning "RADIO_RESET not defined, defaulted to 'NC'"
hbujanda 2:2e82f1b67c1c 45 #endif
hbujanda 2:2e82f1b67c1c 46
hbujanda 2:2e82f1b67c1c 47 #if defined(ENABLE_LOGGING)
hbujanda 2:2e82f1b67c1c 48 #if !defined(DEBUG_TX)
hbujanda 2:2e82f1b67c1c 49 #error "Please define DEBUG_TX"
hbujanda 2:2e82f1b67c1c 50 #endif
hbujanda 2:2e82f1b67c1c 51 #if !defined(DEBUG_RX)
hbujanda 2:2e82f1b67c1c 52 #define DEBUG_RX NC
hbujanda 2:2e82f1b67c1c 53 #warning "DEBUG_RX not defined, defaulted to 'NC'"
hbujanda 2:2e82f1b67c1c 54 #endif
hbujanda 2:2e82f1b67c1c 55 #endif
hbujanda 2:2e82f1b67c1c 56
hbujanda 2:2e82f1b67c1c 57 #endif /* __CONFIG_H_ */