ZigBee Modem Status example for mbed XBeeLib By Digi

Dependencies:   XBeeLib mbed

Description

This example shows how to register a function callback to be aware of modem status changes. This library will call the registered callback whenever the XBee module radio modem changes its status

See Handling modem status changes chapter for more information.

Common Setup

Make sure you have a valid Example Common Setup

Example Setup

This example does not require any additional setup.

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.

It you set up a network as described in the Common Setup section, you should see following modem status in the debug interface:

  • Modem Status 0x0: Corresponds to 'HwReset' meaning 'Hardware reset'
  • Modem Status 0x2: Corresponds to 'JoinedNW' meaning 'Joined network (ZigBee routers and end devices)'

Note: You may not see the HwReset modem status if the device is joining to the coordinator fast (within the call to xbee.init())

If you now unplug the network coordinator you should see following modem status in the debug interface:

  • Modem Status 0x3: Corresponds to 'Disassociated' meaning 'Disassociated (ZigBee)'
Committer:
spastor
Date:
Tue May 05 18:30:36 2015 +0200
Revision:
0:0c8d070617b1
Child:
1:d69b2dcc284f
Automatic upload

Who changed what in which revision?

UserRevisionLine numberNew contents of line
spastor 0:0c8d070617b1 1 /**
spastor 0:0c8d070617b1 2 * Copyright (c) 2015 Digi International Inc.,
spastor 0:0c8d070617b1 3 * All rights not expressly granted are reserved.
spastor 0:0c8d070617b1 4 *
spastor 0:0c8d070617b1 5 * This Source Code Form is subject to the terms of the Mozilla Public
spastor 0:0c8d070617b1 6 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
spastor 0:0c8d070617b1 7 * You can obtain one at http://mozilla.org/MPL/2.0/.
spastor 0:0c8d070617b1 8 *
spastor 0:0c8d070617b1 9 * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
spastor 0:0c8d070617b1 10 * =======================================================================
spastor 0:0c8d070617b1 11 */
spastor 0:0c8d070617b1 12
spastor 0:0c8d070617b1 13 #include "mbed.h"
spastor 0:0c8d070617b1 14 #include "XBeeLib.h"
spastor 0:0c8d070617b1 15 #if defined(ENABLE_LOGGING)
spastor 0:0c8d070617b1 16 #include "DigiLoggerMbedSerial.h"
spastor 0:0c8d070617b1 17 using namespace DigiLog;
spastor 0:0c8d070617b1 18 #endif
spastor 0:0c8d070617b1 19
spastor 0:0c8d070617b1 20 using namespace XBeeLib;
spastor 0:0c8d070617b1 21
spastor 0:0c8d070617b1 22 Serial *log_serial;
spastor 0:0c8d070617b1 23
spastor 0:0c8d070617b1 24 /** Callback function, invoked at modem status reception */
spastor 0:0c8d070617b1 25 static void modem_status_cb(AtCmdFrame::ModemStatus status)
spastor 0:0c8d070617b1 26 {
spastor 0:0c8d070617b1 27 log_serial->printf("\r\nModem Status: 0x%x\r\n", status);
spastor 0:0c8d070617b1 28 }
spastor 0:0c8d070617b1 29
spastor 0:0c8d070617b1 30 int main()
spastor 0:0c8d070617b1 31 {
spastor 0:0c8d070617b1 32 log_serial = new Serial(DEBUG_TX, DEBUG_RX);
spastor 0:0c8d070617b1 33 log_serial->baud(9600);
spastor 0:0c8d070617b1 34 log_serial->printf("Sample application to demo how to receive modem status changes with the XBeeZB\r\n\r\n");
spastor 0:0c8d070617b1 35 log_serial->printf(XB_LIB_BANNER);
spastor 0:0c8d070617b1 36
spastor 0:0c8d070617b1 37 #if defined(ENABLE_LOGGING)
spastor 0:0c8d070617b1 38 new DigiLoggerMbedSerial(log_serial, LogLevelInfo);
spastor 0:0c8d070617b1 39 #endif
spastor 0:0c8d070617b1 40
spastor 0:0c8d070617b1 41 XBeeZB xbee = XBeeZB(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 9600);
spastor 0:0c8d070617b1 42
spastor 0:0c8d070617b1 43 /* Register callbacks */
spastor 0:0c8d070617b1 44 xbee.register_modem_status_cb(&modem_status_cb);
spastor 0:0c8d070617b1 45
spastor 0:0c8d070617b1 46 RadioStatus const radioStatus = xbee.init();
spastor 0:0c8d070617b1 47 MBED_ASSERT(radioStatus == Success);
spastor 0:0c8d070617b1 48
spastor 0:0c8d070617b1 49 while (true) {
spastor 0:0c8d070617b1 50 xbee.process_rx_frames();
spastor 0:0c8d070617b1 51 wait_ms(100);
spastor 0:0c8d070617b1 52 log_serial->printf(".");
spastor 0:0c8d070617b1 53 }
spastor 0:0c8d070617b1 54
spastor 0:0c8d070617b1 55 delete(log_serial);
spastor 0:0c8d070617b1 56 }