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:
Thu Jul 28 10:26:22 2016 +0000
Revision:
10:8e6997fed0fe
Parent:
7:0fc2cb442d58
Child:
11:a5697b787955
Initial commit

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
hbujanda 10:8e6997fed0fe 22 //#error "Replace next define with the LSB of the remote module's 64-bit address (SL parameter)"
hbujanda 10:8e6997fed0fe 23 //#define REMOTE_NODE_ADDR64_LSB ((uint32_t)0x01234567)
hbujanda 10:8e6997fed0fe 24 #define REMOTE_NODE_ADDR64_LSB ((uint32_t)0x40E465E0)
hbujanda 10:8e6997fed0fe 25
hbujanda 5:a723d7cf493e 26
hbujanda 5:a723d7cf493e 27 #define REMOTE_NODE_ADDR64 UINT64(REMOTE_NODE_ADDR64_MSB, REMOTE_NODE_ADDR64_LSB)
hbujanda 5:a723d7cf493e 28
hbujanda 5:a723d7cf493e 29 using namespace XBeeLib;
hbujanda 5:a723d7cf493e 30
hbujanda 5:a723d7cf493e 31 Serial *log_serial;
hbujanda 5:a723d7cf493e 32
hbujanda 5:a723d7cf493e 33 int main()
hbujanda 5:a723d7cf493e 34 {
hbujanda 5:a723d7cf493e 35 log_serial = new Serial(DEBUG_TX, DEBUG_RX);
hbujanda 5:a723d7cf493e 36 log_serial->baud(9600);
hbujanda 10:8e6997fed0fe 37 log_serial->printf("Sample application to demo how to read and set local and remote AT parameters with XBeeDM\r\n\r\n");
hbujanda 5:a723d7cf493e 38 log_serial->printf(XB_LIB_BANNER);
hbujanda 5:a723d7cf493e 39
hbujanda 5:a723d7cf493e 40 #if defined(ENABLE_LOGGING)
hbujanda 5:a723d7cf493e 41 new DigiLoggerMbedSerial(log_serial, LogLevelInfo);
hbujanda 5:a723d7cf493e 42 #endif
hbujanda 5:a723d7cf493e 43
hbujanda 10:8e6997fed0fe 44 XBeeDM xbee = XBeeDM(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 9600);
hbujanda 5:a723d7cf493e 45
hbujanda 5:a723d7cf493e 46 RadioStatus radioStatus = xbee.init();
hbujanda 5:a723d7cf493e 47 MBED_ASSERT(radioStatus == Success);
hbujanda 5:a723d7cf493e 48
hbujanda 5:a723d7cf493e 49 AtCmdFrame::AtCmdResp cmdresp;
hbujanda 5:a723d7cf493e 50
hbujanda 5:a723d7cf493e 51 uint32_t value;
hbujanda 5:a723d7cf493e 52
hbujanda 5:a723d7cf493e 53 /* Read local device SL parameter */
hbujanda 5:a723d7cf493e 54 log_serial->printf("\r\nReading local device SL parameter:\r\n");
hbujanda 5:a723d7cf493e 55 cmdresp = xbee.get_param("SL", &value);
hbujanda 5:a723d7cf493e 56 if (cmdresp == AtCmdFrame::AtCmdRespOk) {
hbujanda 5:a723d7cf493e 57 log_serial->printf("OK. Local SL=%08x\r\n", value);
hbujanda 5:a723d7cf493e 58
hbujanda 5:a723d7cf493e 59 /* Get the local device 64 bit address to compare */
hbujanda 5:a723d7cf493e 60 const uint64_t LocalDeviceAddr64 = xbee.get_addr64();
spastor 7:0fc2cb442d58 61 MBED_ASSERT(value == (LocalDeviceAddr64 & 0xFFFFFFFF));
hbujanda 5:a723d7cf493e 62 } else {
hbujanda 5:a723d7cf493e 63 log_serial->printf("FAILED with %d\r\n", (int) cmdresp);
hbujanda 5:a723d7cf493e 64 }
hbujanda 5:a723d7cf493e 65
hbujanda 5:a723d7cf493e 66 /* Set local device NI parameter */
spastor 7:0fc2cb442d58 67 char ni_local[] = "ni_example_local";
spastor 7:0fc2cb442d58 68 log_serial->printf("\r\nSetting local device NI parameter to '%s':\r\n", ni_local);
spastor 7:0fc2cb442d58 69 cmdresp = xbee.set_param("NI", (uint8_t*)ni_local, strlen(ni_local));
hbujanda 5:a723d7cf493e 70 if (cmdresp == AtCmdFrame::AtCmdRespOk) {
hbujanda 5:a723d7cf493e 71 log_serial->printf("OK\r\n");
hbujanda 5:a723d7cf493e 72 } else {
hbujanda 5:a723d7cf493e 73 log_serial->printf("FAILED with %d\r\n", (int) cmdresp);
hbujanda 5:a723d7cf493e 74 }
hbujanda 5:a723d7cf493e 75
hbujanda 10:8e6997fed0fe 76 const RemoteXBeeDM remoteDevice = RemoteXBeeDM(REMOTE_NODE_ADDR64);
spastor 7:0fc2cb442d58 77
hbujanda 5:a723d7cf493e 78 /* Read remote device SL parameter */
hbujanda 5:a723d7cf493e 79 log_serial->printf("\r\nReading remote device SL parameter:\r\n");
hbujanda 5:a723d7cf493e 80 cmdresp = xbee.get_param(remoteDevice, "SL", &value);
hbujanda 5:a723d7cf493e 81 if (cmdresp == AtCmdFrame::AtCmdRespOk) {
hbujanda 5:a723d7cf493e 82 log_serial->printf("OK. Remote SL=%08x\r\n", value);
hbujanda 5:a723d7cf493e 83 MBED_ASSERT(value == REMOTE_NODE_ADDR64_LSB);
hbujanda 5:a723d7cf493e 84 } else {
hbujanda 5:a723d7cf493e 85 log_serial->printf("FAILED with %d\r\n", (int) cmdresp);
hbujanda 5:a723d7cf493e 86 }
hbujanda 5:a723d7cf493e 87
spastor 7:0fc2cb442d58 88 /* Set remote device NI parameter */
spastor 7:0fc2cb442d58 89 char ni_remote[] = "ni_example_remote";
spastor 7:0fc2cb442d58 90 log_serial->printf("\r\nSetting remote device NI parameter to '%s':\r\n", ni_remote);
spastor 7:0fc2cb442d58 91 cmdresp = xbee.set_param(remoteDevice, "NI", (uint8_t*)ni_remote, strlen(ni_remote));
spastor 7:0fc2cb442d58 92 if (cmdresp == AtCmdFrame::AtCmdRespOk) {
spastor 7:0fc2cb442d58 93 log_serial->printf("OK\r\n");
spastor 7:0fc2cb442d58 94 } else {
spastor 7:0fc2cb442d58 95 log_serial->printf("FAILED with %d\r\n", (int) cmdresp);
spastor 7:0fc2cb442d58 96 }
spastor 7:0fc2cb442d58 97
hbujanda 5:a723d7cf493e 98 delete(log_serial);
hbujanda 5:a723d7cf493e 99 }