ZB 13: Send AT commands
This example shows how to send AT commands to the XBee modules

Required Materials

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

Notes

- The coordinator must be turned on - The battery has to be connected. - This example can be executed in Waspmote v12

Code

1
/*
2
* ------ [ZB_13] - send AT command --------
3
*
4
* Explanation: This example shows how to send AT commmands to the
5
* XBee modules
6
*
7
* Copyright (C) 2012 Libelium Comunicaciones Distribuidas S.L.
8
* http://www.libelium.com
9
*
10
* This program is free software: you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation, either version 3 of the License, or
13
* (at your option) any later version.
14
*
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
19
*
20
* You should have received a copy of the GNU General Public License
21
* along with this program. If not, see .
22
*
23
* Version: 0.1
24
* Design: David Gascón
25
* Implementation: Yuri Carmona
26
*/
27
28
#include <WaspXBeeZB.h>
29
30
void setup()
31
{
32
// init USB port
33
USB.ON();
34
USB.println("ZB_13 example");
35
36
37
//////////////////////////
38
// 1. init XBee
39
//////////////////////////
40
xbeeZB.ON();
41
42
delay(3000);
43
44
45
//////////////////////////
46
// 2. check XBee's network parameters
47
//////////////////////////
48
checkNetworkParams();
49
50
51
USB.println(F("-----------------------------"));
52
53
54
//////////////////////////
55
// 3. Request channel
56
//////////////////////////
57
if(!xbeeZB.sendCommandAT("CH#"))
58
{
59
USB.print(F("Channel: "));
60
USB.printHex(xbeeZB.commandAT[0]);
61
USB.println();
62
}
63
else
64
{
65
USB.println("at error");
66
}
67
68
69
//////////////////////////
70
// 4. Request operating 16b pan id
71
//////////////////////////
72
if(!xbeeZB.sendCommandAT("OI#"))
73
{
74
USB.print(F("Operating 16-b PANID: "));
75
USB.printHex(xbeeZB.commandAT[0]);
76
USB.printHex(xbeeZB.commandAT[1]);
77
USB.println();
78
}
79
else
80
{
81
USB.println("at error");
82
}
83
84
85
//////////////////////////
86
// 4. Request operating 64b pan id
87
//////////////////////////
88
if(!xbeeZB.sendCommandAT("OP#"))
89
{
90
USB.print(F("Operating 64-b PANID: "));
91
USB.printHex(xbeeZB.commandAT[0]);
92
USB.printHex(xbeeZB.commandAT[1]);
93
USB.printHex(xbeeZB.commandAT[2]);
94
USB.printHex(xbeeZB.commandAT[3]);
95
USB.printHex(xbeeZB.commandAT[4]);
96
USB.printHex(xbeeZB.commandAT[5]);
97
USB.printHex(xbeeZB.commandAT[6]);
98
USB.printHex(xbeeZB.commandAT[7]);
99
USB.println();
100
}
101
else
102
{
103
USB.println("at error");
104
}
105
106
//////////////////////////
107
// 4. Request encryption mode
108
//////////////////////////
109
if(!xbeeZB.sendCommandAT("EE#"))
110
{
111
USB.print(F("encryption mode: "));
112
USB.printHex(xbeeZB.commandAT[0]);
113
USB.println();
114
}
115
else
116
{
117
USB.println("at error");
118
}
119
120
USB.println(F("-----------------------------"));
121
}
122
123
void loop()
124
{
125
// Do nothing
126
delay(5000);
127
}
128
129
130
131
132
133
134
135
/*******************************************
136
*
137
* checkNetworkParams - Check operating
138
* network parameters in the XBee module
139
*
140
*******************************************/
141
void checkNetworkParams()
142
{
143
// 1. get operating 64-b PAN ID
144
xbeeZB.getOperating64PAN();
145
146
// 2. wait for association indication
147
xbeeZB.getAssociationIndication();
148
149
while( xbeeZB.associationIndication != 0 )
150
{
151
delay(2000);
152
153
// get operating 64-b PAN ID
154
xbeeZB.getOperating64PAN();
155
156
USB.print(F("operating 64-b PAN ID: "));
157
USB.printHex(xbeeZB.operating64PAN[0]);
158
USB.printHex(xbeeZB.operating64PAN[1]);
159
USB.printHex(xbeeZB.operating64PAN[2]);
160
USB.printHex(xbeeZB.operating64PAN[3]);
161
USB.printHex(xbeeZB.operating64PAN[4]);
162
USB.printHex(xbeeZB.operating64PAN[5]);
163
USB.printHex(xbeeZB.operating64PAN[6]);
164
USB.printHex(xbeeZB.operating64PAN[7]);
165
USB.println();
166
167
xbeeZB.getAssociationIndication();
168
}
169
170
USB.println(F("\nJoined a network!"));
171
172
173
}
Copied!

Output

1
E#
2
ZB_13 example
3
4
Joined a network!
5
-----------------------------
6
Channel: 0E
7
Operating 16-b PANID: 7C7A
8
Operating 64-b PANID: 1122334455667788
9
encryption mode: 00
10
-----------------------------
Copied!
Last modified 2yr ago