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:
Fri Jul 29 12:10:49 2016 +0200
Revision:
11:5e3da09ec988
Parent:
10:776b6cf3e506
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 #define REMOTE_NODE_ADDR64_MSB ((uint32_t)0x0013A200)
spastor 8:7b4771c9689c 21
hbujanda 10:776b6cf3e506 22 #error "Replace next define with the LSB of the remote module's 64-bit address (SL parameter)"
hbujanda 10:776b6cf3e506 23 #define REMOTE_NODE_ADDR64_LSB ((uint32_t)0x01234567)
spastor 8:7b4771c9689c 24
hbujanda 10:776b6cf3e506 25 #error "Replace next define with the remote module's 16-bit address (MY parameter)"
hbujanda 10:776b6cf3e506 26 #define REMOTE_NODE_ADDR16 ((uint16_t)0x1111)
hbujanda 6:193fc0aec946 27
hbujanda 6:193fc0aec946 28 #define REMOTE_NODE_ADDR64 UINT64(REMOTE_NODE_ADDR64_MSB, REMOTE_NODE_ADDR64_LSB)
hbujanda 6:193fc0aec946 29
hbujanda 6:193fc0aec946 30 using namespace XBeeLib;
hbujanda 6:193fc0aec946 31
hbujanda 6:193fc0aec946 32 Serial *log_serial;
hbujanda 6:193fc0aec946 33
hbujanda 6:193fc0aec946 34 int main()
hbujanda 6:193fc0aec946 35 {
hbujanda 6:193fc0aec946 36 log_serial = new Serial(DEBUG_TX, DEBUG_RX);
hbujanda 6:193fc0aec946 37 log_serial->baud(9600);
hbujanda 6:193fc0aec946 38 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 39 log_serial->printf(XB_LIB_BANNER);
hbujanda 6:193fc0aec946 40
hbujanda 6:193fc0aec946 41 #if defined(ENABLE_LOGGING)
hbujanda 6:193fc0aec946 42 new DigiLoggerMbedSerial(log_serial, LogLevelInfo);
hbujanda 6:193fc0aec946 43 #endif
hbujanda 6:193fc0aec946 44
hbujanda 6:193fc0aec946 45 XBee802 xbee = XBee802(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 9600);
hbujanda 6:193fc0aec946 46
hbujanda 6:193fc0aec946 47 RadioStatus radioStatus = xbee.init();
hbujanda 6:193fc0aec946 48 MBED_ASSERT(radioStatus == Success);
hbujanda 6:193fc0aec946 49
hbujanda 6:193fc0aec946 50 AtCmdFrame::AtCmdResp cmdresp;
hbujanda 6:193fc0aec946 51 uint32_t value;
hbujanda 6:193fc0aec946 52
hbujanda 6:193fc0aec946 53 /* Read local device SL parameter */
hbujanda 6:193fc0aec946 54 log_serial->printf("\r\nReading local device SL parameter:\r\n");
hbujanda 6:193fc0aec946 55 cmdresp = xbee.get_param("SL", &value);
hbujanda 6:193fc0aec946 56 if (cmdresp == AtCmdFrame::AtCmdRespOk) {
hbujanda 6:193fc0aec946 57 log_serial->printf("OK. Local SL=%08x\r\n", value);
hbujanda 6:193fc0aec946 58
hbujanda 6:193fc0aec946 59 /* Get the local device 64 bit address to compare */
hbujanda 6:193fc0aec946 60 const uint64_t LocalDeviceAddr64 = xbee.get_addr64();
hbujanda 6:193fc0aec946 61
spastor 8:7b4771c9689c 62 MBED_ASSERT(value == (LocalDeviceAddr64 & 0xFFFFFFFF));
hbujanda 6:193fc0aec946 63 } else {
hbujanda 6:193fc0aec946 64 log_serial->printf("FAILED with %d\r\n", (int) cmdresp);
hbujanda 6:193fc0aec946 65 }
hbujanda 6:193fc0aec946 66
hbujanda 6:193fc0aec946 67 /* Set local device NI parameter */
spastor 8:7b4771c9689c 68 char ni_local[] = "param config example";
spastor 8:7b4771c9689c 69 log_serial->printf("\r\nSetting local device NI parameter to '%s':\r\n", ni_local);
spastor 8:7b4771c9689c 70 cmdresp = xbee.set_param("NI", (uint8_t*)ni_local, strlen(ni_local));
hbujanda 6:193fc0aec946 71 if (cmdresp == AtCmdFrame::AtCmdRespOk)
hbujanda 6:193fc0aec946 72 log_serial->printf("OK\r\n");
hbujanda 6:193fc0aec946 73 else
hbujanda 6:193fc0aec946 74 log_serial->printf("FAILED with %d\r\n", (int) cmdresp);
hbujanda 6:193fc0aec946 75
spastor 8:7b4771c9689c 76 const RemoteXBee802 remoteDevice64b = RemoteXBee802(REMOTE_NODE_ADDR64);
spastor 8:7b4771c9689c 77 const RemoteXBee802 remoteDevice16b = RemoteXBee802(REMOTE_NODE_ADDR16);
spastor 8:7b4771c9689c 78
hbujanda 6:193fc0aec946 79 /* Read remote device SL parameter using 64b addressing */
hbujanda 6:193fc0aec946 80 log_serial->printf("\r\nReading remote device SL parameter using 64b address:\r\n");
hbujanda 6:193fc0aec946 81 cmdresp = xbee.get_param(remoteDevice64b, "SL", &value);
hbujanda 6:193fc0aec946 82 if (cmdresp == AtCmdFrame::AtCmdRespOk) {
hbujanda 6:193fc0aec946 83 log_serial->printf("OK. Remote SL=%08x\r\n", value);
hbujanda 6:193fc0aec946 84 MBED_ASSERT(value == REMOTE_NODE_ADDR64_LSB);
hbujanda 6:193fc0aec946 85 } else {
hbujanda 6:193fc0aec946 86 log_serial->printf("FAILED with %d\r\n", (int) cmdresp);
hbujanda 6:193fc0aec946 87 }
hbujanda 6:193fc0aec946 88
hbujanda 6:193fc0aec946 89 /* Read remote device SL parameter using 16b addressing */
hbujanda 6:193fc0aec946 90 log_serial->printf("\r\nReading remote device SL parameter using 16b address:\r\n");
hbujanda 6:193fc0aec946 91 cmdresp = xbee.get_param(remoteDevice16b, "SL", &value);
hbujanda 6:193fc0aec946 92 if (cmdresp == AtCmdFrame::AtCmdRespOk) {
hbujanda 6:193fc0aec946 93 log_serial->printf("OK. Remote SL=%08x\r\n", value);
hbujanda 6:193fc0aec946 94 MBED_ASSERT(value == REMOTE_NODE_ADDR64_LSB);
hbujanda 6:193fc0aec946 95 } else {
hbujanda 6:193fc0aec946 96 log_serial->printf("FAILED with %d\r\n", (int) cmdresp);
hbujanda 6:193fc0aec946 97 }
hbujanda 6:193fc0aec946 98
spastor 8:7b4771c9689c 99 /* Set remote device NI parameter */
spastor 8:7b4771c9689c 100 char ni_remote[] = "ni_example_remote";
spastor 8:7b4771c9689c 101 log_serial->printf("\r\nSetting remote device NI parameter to '%s':\r\n", ni_remote);
spastor 8:7b4771c9689c 102 cmdresp = xbee.set_param(remoteDevice64b, "NI", (uint8_t*)ni_remote, strlen(ni_remote));
spastor 8:7b4771c9689c 103 if (cmdresp == AtCmdFrame::AtCmdRespOk) {
spastor 8:7b4771c9689c 104 log_serial->printf("OK\r\n");
spastor 8:7b4771c9689c 105 } else {
spastor 8:7b4771c9689c 106 log_serial->printf("FAILED with %d\r\n", (int) cmdresp);
spastor 8:7b4771c9689c 107 }
spastor 8:7b4771c9689c 108
hbujanda 6:193fc0aec946 109 delete(log_serial);
hbujanda 6:193fc0aec946 110 }