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:
Fri Jul 29 12:14:19 2016 +0200
Revision:
11:a5697b787955
Parent:
10:8e6997fed0fe
Automatic upload

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