802.15.4 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.
  • The remote device 16-bit address by customizing the REMOTE_NODE_ADDR16 define with the remote XBee module 16-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.
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. This test is done using both 64-bit and 16-bit addressing for demonstration
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:
spastor
Date:
Fri May 08 11:51:07 2015 +0200
Revision:
3:8ede49929739
Parent:
0:3d9a49f93daa
Automatic upload

Who changed what in which revision?

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