ZigBee AT Commands example for mbed XBeeLib By Digi

Dependencies:   XBeeLib mbed

This example shows how to read and change configuration parameters of either the local XBee module or a remote XBee module.

See Configuring local and remote modules chapter for more information.

Common Setup

Make sure you have a valid Example Common Setup

Example Setup

Application

You have to configure the remote device 64-bit address by customizing the REMOTE_NODE_ADDR64_MSB and REMOTE_NODE_ADDR64_LSB defines with the remote XBee module 64-bit address.

Running the example

Build and deploy the example to the mbed module.
Reset the mbed module so the example starts. You should see the example debug information through the debug interface configured in the 'Local Setup' chapter.
Once joined to the coordinator, the application will do following operations:

OperationXBee moduleparameterVerification
ReadlocalSLThe result is asserted against the known local module SL value. So just check the assertion passed
SetlocalNIClick 'discover remote devices' on the X-CTU connected to the remote. Should discover the local XBee module with the new NI (ni_example_local)
ReadremoteSLThe result is asserted against the known remote module SL value. So just check the assertion passed
SetremoteNIRefresh the 'NI' parameter in the X-CTU connected to the remote and check it has changed to the new NI (ni_example_remote)
Committer:
hbujanda
Date:
Fri Jul 29 12:12:29 2016 +0200
Revision:
10:2ca09be89d07
Parent:
7:0fc2cb442d58
Automatic upload

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hbujanda 5:a723d7cf493e 1 /**
hbujanda 5:a723d7cf493e 2 * Copyright (c) 2015 Digi International Inc.,
hbujanda 5:a723d7cf493e 3 * All rights not expressly granted are reserved.
hbujanda 5:a723d7cf493e 4 *
hbujanda 5:a723d7cf493e 5 * This Source Code Form is subject to the terms of the Mozilla Public
hbujanda 5:a723d7cf493e 6 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
hbujanda 5:a723d7cf493e 7 * You can obtain one at http://mozilla.org/MPL/2.0/.
hbujanda 5:a723d7cf493e 8 *
hbujanda 5:a723d7cf493e 9 * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
hbujanda 5:a723d7cf493e 10 * =======================================================================
hbujanda 5:a723d7cf493e 11 */
hbujanda 5:a723d7cf493e 12
hbujanda 5:a723d7cf493e 13 #include "mbed.h"
hbujanda 5:a723d7cf493e 14 #include "XBeeLib.h"
hbujanda 5:a723d7cf493e 15 #if defined(ENABLE_LOGGING)
hbujanda 5:a723d7cf493e 16 #include "DigiLoggerMbedSerial.h"
hbujanda 5:a723d7cf493e 17 using namespace DigiLog;
hbujanda 5:a723d7cf493e 18 #endif
hbujanda 5:a723d7cf493e 19
hbujanda 5:a723d7cf493e 20 #define REMOTE_NODE_ADDR64_MSB ((uint32_t)0x0013A200)
spastor 7:0fc2cb442d58 21
spastor 7:0fc2cb442d58 22 #error "Replace next define with the LSB of the remote module's 64-bit address (SL parameter)"
spastor 7:0fc2cb442d58 23 #define REMOTE_NODE_ADDR64_LSB ((uint32_t)0x01234567)
hbujanda 5:a723d7cf493e 24
hbujanda 5:a723d7cf493e 25 #define REMOTE_NODE_ADDR64 UINT64(REMOTE_NODE_ADDR64_MSB, REMOTE_NODE_ADDR64_LSB)
hbujanda 5:a723d7cf493e 26
hbujanda 5:a723d7cf493e 27 using namespace XBeeLib;
hbujanda 5:a723d7cf493e 28
hbujanda 5:a723d7cf493e 29 Serial *log_serial;
hbujanda 5:a723d7cf493e 30
hbujanda 5:a723d7cf493e 31 int main()
hbujanda 5:a723d7cf493e 32 {
hbujanda 5:a723d7cf493e 33 log_serial = new Serial(DEBUG_TX, DEBUG_RX);
hbujanda 5:a723d7cf493e 34 log_serial->baud(9600);
hbujanda 5:a723d7cf493e 35 log_serial->printf("Sample application to demo how to read and set local and remote AT parameters with XBeeZB\r\n\r\n");
hbujanda 5:a723d7cf493e 36 log_serial->printf(XB_LIB_BANNER);
hbujanda 5:a723d7cf493e 37
hbujanda 5:a723d7cf493e 38 #if defined(ENABLE_LOGGING)
hbujanda 5:a723d7cf493e 39 new DigiLoggerMbedSerial(log_serial, LogLevelInfo);
hbujanda 5:a723d7cf493e 40 #endif
hbujanda 5:a723d7cf493e 41
hbujanda 5:a723d7cf493e 42 XBeeZB xbee = XBeeZB(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 9600);
hbujanda 5:a723d7cf493e 43
hbujanda 5:a723d7cf493e 44 RadioStatus radioStatus = xbee.init();
hbujanda 5:a723d7cf493e 45 MBED_ASSERT(radioStatus == Success);
hbujanda 5:a723d7cf493e 46
hbujanda 5:a723d7cf493e 47 /* Wait until the device has joined the network */
hbujanda 5:a723d7cf493e 48 log_serial->printf("Waiting for device to join the network: ");
hbujanda 5:a723d7cf493e 49 while (!xbee.is_joined()) {
hbujanda 5:a723d7cf493e 50 wait_ms(1000);
hbujanda 5:a723d7cf493e 51 log_serial->printf(".");
hbujanda 5:a723d7cf493e 52 }
hbujanda 5:a723d7cf493e 53 log_serial->printf("OK\r\n");
hbujanda 5:a723d7cf493e 54
hbujanda 5:a723d7cf493e 55 AtCmdFrame::AtCmdResp cmdresp;
hbujanda 5:a723d7cf493e 56
hbujanda 5:a723d7cf493e 57 uint32_t value;
hbujanda 5:a723d7cf493e 58
hbujanda 5:a723d7cf493e 59 /* Read local device SL parameter */
hbujanda 5:a723d7cf493e 60 log_serial->printf("\r\nReading local device SL parameter:\r\n");
hbujanda 5:a723d7cf493e 61 cmdresp = xbee.get_param("SL", &value);
hbujanda 5:a723d7cf493e 62 if (cmdresp == AtCmdFrame::AtCmdRespOk) {
hbujanda 5:a723d7cf493e 63 log_serial->printf("OK. Local SL=%08x\r\n", value);
hbujanda 5:a723d7cf493e 64
hbujanda 5:a723d7cf493e 65 /* Get the local device 64 bit address to compare */
hbujanda 5:a723d7cf493e 66 const uint64_t LocalDeviceAddr64 = xbee.get_addr64();
spastor 7:0fc2cb442d58 67 MBED_ASSERT(value == (LocalDeviceAddr64 & 0xFFFFFFFF));
hbujanda 5:a723d7cf493e 68 } else {
hbujanda 5:a723d7cf493e 69 log_serial->printf("FAILED with %d\r\n", (int) cmdresp);
hbujanda 5:a723d7cf493e 70 }
hbujanda 5:a723d7cf493e 71
hbujanda 5:a723d7cf493e 72 /* Set local device NI parameter */
spastor 7:0fc2cb442d58 73 char ni_local[] = "ni_example_local";
spastor 7:0fc2cb442d58 74 log_serial->printf("\r\nSetting local device NI parameter to '%s':\r\n", ni_local);
spastor 7:0fc2cb442d58 75 cmdresp = xbee.set_param("NI", (uint8_t*)ni_local, strlen(ni_local));
hbujanda 5:a723d7cf493e 76 if (cmdresp == AtCmdFrame::AtCmdRespOk) {
hbujanda 5:a723d7cf493e 77 log_serial->printf("OK\r\n");
hbujanda 5:a723d7cf493e 78 } else {
hbujanda 5:a723d7cf493e 79 log_serial->printf("FAILED with %d\r\n", (int) cmdresp);
hbujanda 5:a723d7cf493e 80 }
hbujanda 5:a723d7cf493e 81
spastor 7:0fc2cb442d58 82 const RemoteXBeeZB remoteDevice = RemoteXBeeZB(REMOTE_NODE_ADDR64);
spastor 7:0fc2cb442d58 83
hbujanda 5:a723d7cf493e 84 /* Read remote device SL parameter */
hbujanda 5:a723d7cf493e 85 log_serial->printf("\r\nReading remote device SL parameter:\r\n");
hbujanda 5:a723d7cf493e 86 cmdresp = xbee.get_param(remoteDevice, "SL", &value);
hbujanda 5:a723d7cf493e 87 if (cmdresp == AtCmdFrame::AtCmdRespOk) {
hbujanda 5:a723d7cf493e 88 log_serial->printf("OK. Remote SL=%08x\r\n", value);
hbujanda 5:a723d7cf493e 89 MBED_ASSERT(value == REMOTE_NODE_ADDR64_LSB);
hbujanda 5:a723d7cf493e 90 } else {
hbujanda 5:a723d7cf493e 91 log_serial->printf("FAILED with %d\r\n", (int) cmdresp);
hbujanda 5:a723d7cf493e 92 }
hbujanda 5:a723d7cf493e 93
spastor 7:0fc2cb442d58 94 /* Set remote device NI parameter */
spastor 7:0fc2cb442d58 95 char ni_remote[] = "ni_example_remote";
spastor 7:0fc2cb442d58 96 log_serial->printf("\r\nSetting remote device NI parameter to '%s':\r\n", ni_remote);
spastor 7:0fc2cb442d58 97 cmdresp = xbee.set_param(remoteDevice, "NI", (uint8_t*)ni_remote, strlen(ni_remote));
spastor 7:0fc2cb442d58 98 if (cmdresp == AtCmdFrame::AtCmdRespOk) {
spastor 7:0fc2cb442d58 99 log_serial->printf("OK\r\n");
spastor 7:0fc2cb442d58 100 } else {
spastor 7:0fc2cb442d58 101 log_serial->printf("FAILED with %d\r\n", (int) cmdresp);
spastor 7:0fc2cb442d58 102 }
spastor 7:0fc2cb442d58 103
hbujanda 5:a723d7cf493e 104 delete(log_serial);
hbujanda 5:a723d7cf493e 105 }