ZB 08: Set low power mode
This program shows how to set different a low power states in XBee-ZigBee End Devices modules

Required Materials

1 x Waspmote 1 x Battery 1 x MiniUSB wire 1 x XBee-ZigBee module

Notes

- This example is valid only for End Devices firmwares (which are not supported by Libelium) - In the case of using the XBee module after waking up it is necessary to wait for the module to join the network this may last for several seconds depending on each case - The battery has to be connected. - This example can be executed in Waspmote v12

Code

1
/*
2
* ------ [ZB_08] - set low power state in XBee module --------
3
*
4
* Explanation: This program shows how to set different a low power
5
* states in XBee-ZigBee End Devices modules
6
*
7
* SM=1: Pin Sleep Mode
8
*
9
* Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L.
10
* http://www.libelium.com
11
*
12
* This program is free software: you can redistribute it and/or modify
13
* it under the terms of the GNU General Public License as published by
14
* the Free Software Foundation, either version 3 of the License, or
15
* (at your option) any later version.
16
*
17
* This program is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
* GNU General Public License for more details.
21
*
22
* You should have received a copy of the GNU General Public License
23
* along with this program. If not, see .
24
*
25
* Version: 0.3
26
* Design: David Gascón
27
* Implementation: Yuri Carmona
28
*/
29
30
#include <WaspXBeeZB.h>
31
32
void setup()
33
{
34
// init USB port
35
USB.ON();
36
USB.println(F("ZB_08 example"));
37
38
// init XBee
39
xbeeZB.ON();
40
41
////////////////////////////////////
42
// 1. Set sleep mode
43
////////////////////////////////////
44
45
// 1.1. it is supposed that XBee SM=1 (Pin hibernate)
46
xbeeZB.wake();
47
48
// 1.2. set sleep mode
49
xbeeZB.setSleepMode(1);
50
51
// check flag
52
if( xbeeZB.error_AT == 0 )
53
{
54
USB.println(F("sleep mode set"));
55
}
56
else
57
{
58
USB.println(F("Error while setting sleep mode"));
59
}
60
61
62
// 1.3. set sleep mode
63
xbeeZB.getSleepMode();
64
USB.print("sleep mode:");
65
USB.println(xbeeZB.sleepMode,HEX);
66
67
// 1.4. wake XBee up
68
xbeeZB.wake();
69
70
// 1.5. get firmware version
71
xbeeZB.getSoftVersion();
72
USB.print(F("XBee module firmware version:"));
73
USB.print(xbeeZB.softVersion[0],HEX);
74
USB.println(xbeeZB.softVersion[1],HEX);
75
USB.println();
76
77
}
78
79
80
81
void loop()
82
{
83
////////////////////////////////////
84
// 1. Set sleep mode
85
////////////////////////////////////
86
87
// 1.1. put XBee to sleep
88
xbeeZB.sleep();
89
USB.println(F("1. XBee in sleep mode"));
90
91
// 1.2. set red LED during sleep time
92
USB.println(F("RED LED switched on"));
93
Utils.setLED(LED0, LED_ON);
94
95
// 1.3. wait 20 seconds in sleep mode
96
USB.println(F("While XBee is in sleep mode --> wait for 20 seconds...\n"));
97
delay(20000);
98
99
100
////////////////////////////////////
101
// 2. Wake up the XBee module
102
////////////////////////////////////
103
104
// 2.1. wake XBee up
105
xbeeZB.wake();
106
USB.println(F("2. XBee wakes-up"));
107
108
// 2.2. switch LED off when leaving sleep mode
109
USB.println(F("RED LED switched off"));
110
Utils.setLED(LED0, LED_OFF);
111
112
// 2.3. wait 5 seconds
113
USB.println(F("While XBee is in normal mode --> wait for 5 seconds...\n"));
114
delay(5000);
115
116
/* In the case of using the XBee module after waking up
117
it is necessary to wait for the module to join the network
118
this may last for several seconds depending on each case*/
119
}
Copied!

Output

1
E#
2
ZB_08 example
3
sleep mode set
4
sleep mode:1
5
XBee module firmware version:29A7
6
XBee module is an End Device
7
1. XBee in sleep mode
8
RED LED switched on
9
While XBee is in sleep mode --> wait for 20 seconds...
10
11
2. XBee wakes-up
12
RED LED switched off
13
While XBee is in normal mode --> wait for 5 seconds...
14
...
Copied!
Last modified 2yr ago