DigiMesh AT Commands example for mbed XBeeLib By Digi

Dependencies:   XBeeLib mbed

Fork of XBeeZB_AT_Commands by Digi International Inc.

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.
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:
Wed Apr 29 17:58:33 2015 +0200
Revision:
0:fd8c52820c01
Child:
2:2b01597ab634
Automatic upload

Who changed what in which revision?

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