DigiMesh Modem Status example for mbed XBeeLib By Digi

Dependencies:   XBeeLib mbed

Fork of XBeeZB_modem_status by Digi International Inc.

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'
Committer:
hbujanda
Date:
Fri Jul 29 12:15:30 2016 +0200
Revision:
10:47db8cbb2e2d
Parent:
9:51ef7cbb0037
Automatic upload

Who changed what in which revision?

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