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:
hbujanda
Date:
Thu May 14 16:21:52 2015 +0200
Revision:
6:193fc0aec946
Child:
8:7b4771c9689c
Automatic upload

Who changed what in which revision?

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