802.15.4 Send Data example for mbed XBeeLib By Digi

Dependencies:   XBeeLib mbed

Description

This example shows how to send data to a remote XBee802 module. The application creates a message for a remote XBee module. This library encodes and sends it to the local XBee module through the serial port. Then the local XBee module sends the packet to the remote XBee module through the air.

The example shows how to send both unicast and broadcast messages.

See Sending data to another module chapter for more information.

Common Setup

Make sure you have a valid Example Common Setup

Example Setup

XBee modules

To evaluate the 16-bit addressing mode you have to configure the local XBee module and the remote XBee module with unique values... for example 0x1111 for the local and 0x2222 for the remote.

Application

Broadcast messages doesn't require any configuration, but for the unicast messages 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.
  • The remote device 16-bit address by customizing the REMOTE_NODE_ADDR16 define with the remote XBee module 16-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 first send a broadcast message and finally a couple of unicast messages to the configured remote XBee module (first using 64-bit addressing mode and then using 16-bit addressing mode).

Verify that the remote XBee module is receiving the frames by accessing the "Console" tab of the X-CTU. You should see there the broadcast and unicast messages.

Committer:
hbujanda
Date:
Thu May 14 16:22:41 2015 +0200
Revision:
5:1b2d489605b1
Child:
7:ab86cae2e208
Automatic upload

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hbujanda 5:1b2d489605b1 1 /**
hbujanda 5:1b2d489605b1 2 * Copyright (c) 2015 Digi International Inc.,
hbujanda 5:1b2d489605b1 3 * All rights not expressly granted are reserved.
hbujanda 5:1b2d489605b1 4 *
hbujanda 5:1b2d489605b1 5 * This Source Code Form is subject to the terms of the Mozilla Public
hbujanda 5:1b2d489605b1 6 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
hbujanda 5:1b2d489605b1 7 * You can obtain one at http://mozilla.org/MPL/2.0/.
hbujanda 5:1b2d489605b1 8 *
hbujanda 5:1b2d489605b1 9 * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
hbujanda 5:1b2d489605b1 10 * =======================================================================
hbujanda 5:1b2d489605b1 11 */
hbujanda 5:1b2d489605b1 12
hbujanda 5:1b2d489605b1 13 #include "mbed.h"
hbujanda 5:1b2d489605b1 14 #include "XBeeLib.h"
hbujanda 5:1b2d489605b1 15 #if defined(ENABLE_LOGGING)
hbujanda 5:1b2d489605b1 16 #include "DigiLoggerMbedSerial.h"
hbujanda 5:1b2d489605b1 17 using namespace DigiLog;
hbujanda 5:1b2d489605b1 18 #endif
hbujanda 5:1b2d489605b1 19
hbujanda 5:1b2d489605b1 20 // TODO Replace with the MSB of the remote module's 64-bit address (SH parameter)
hbujanda 5:1b2d489605b1 21 #define REMOTE_NODE_ADDR64_MSB ((uint32_t)0x0013A200)
hbujanda 5:1b2d489605b1 22 // TODO Replace with the LSB of the remote module's 64-bit address (SL parameter)
hbujanda 5:1b2d489605b1 23 #define REMOTE_NODE_ADDR64_LSB ((uint32_t)0x40D2B03E)
hbujanda 5:1b2d489605b1 24 // TODO Replace with the remote module's 16-bit address (MY parameter)
hbujanda 5:1b2d489605b1 25 #define REMOTE_NODE_ADDR16 ((uint16_t)0x1111)
hbujanda 5:1b2d489605b1 26
hbujanda 5:1b2d489605b1 27 #define REMOTE_NODE_ADDR64 UINT64(REMOTE_NODE_ADDR64_MSB, REMOTE_NODE_ADDR64_LSB)
hbujanda 5:1b2d489605b1 28
hbujanda 5:1b2d489605b1 29 using namespace XBeeLib;
hbujanda 5:1b2d489605b1 30
hbujanda 5:1b2d489605b1 31 Serial *log_serial;
hbujanda 5:1b2d489605b1 32
hbujanda 5:1b2d489605b1 33 static void send_broadcast_data(XBee802& xbee)
hbujanda 5:1b2d489605b1 34 {
hbujanda 5:1b2d489605b1 35 const char data[] = "send_broadcast_data";
hbujanda 5:1b2d489605b1 36 const uint16_t data_len = strlen(data);
hbujanda 5:1b2d489605b1 37
hbujanda 5:1b2d489605b1 38 const TxStatus txStatus = xbee.send_data_broadcast((const uint8_t *)data, data_len);
hbujanda 5:1b2d489605b1 39
hbujanda 5:1b2d489605b1 40 if (txStatus == TxStatusSuccess)
hbujanda 5:1b2d489605b1 41 log_serial->printf("send_broadcast_data OK\r\n");
hbujanda 5:1b2d489605b1 42 else
hbujanda 5:1b2d489605b1 43 log_serial->printf("send_broadcast_data failed with %d\r\n", (int) txStatus);
hbujanda 5:1b2d489605b1 44 }
hbujanda 5:1b2d489605b1 45
hbujanda 5:1b2d489605b1 46 static void send_data_to_remote_node(XBee802& xbee, const RemoteXBee802& RemoteDevice)
hbujanda 5:1b2d489605b1 47 {
hbujanda 5:1b2d489605b1 48 const char data[] = "send_data_to_remote_node";
hbujanda 5:1b2d489605b1 49 const uint16_t data_len = strlen(data);
hbujanda 5:1b2d489605b1 50
hbujanda 5:1b2d489605b1 51 const TxStatus txStatus = xbee.send_data(RemoteDevice, (const uint8_t *)data, data_len);
hbujanda 5:1b2d489605b1 52
hbujanda 5:1b2d489605b1 53 if (txStatus == TxStatusSuccess)
hbujanda 5:1b2d489605b1 54 log_serial->printf("send_data_to_remote_node OK\r\n");
hbujanda 5:1b2d489605b1 55 else
hbujanda 5:1b2d489605b1 56 log_serial->printf("send_data_to_remote_node failed with %d\r\n", (int) txStatus);
hbujanda 5:1b2d489605b1 57 }
hbujanda 5:1b2d489605b1 58
hbujanda 5:1b2d489605b1 59 int main()
hbujanda 5:1b2d489605b1 60 {
hbujanda 5:1b2d489605b1 61 log_serial = new Serial(DEBUG_TX, DEBUG_RX);
hbujanda 5:1b2d489605b1 62 log_serial->baud(9600);
hbujanda 5:1b2d489605b1 63 log_serial->printf("Sample application to demo how to send unicast and broadcast data with the XBee802\r\n\r\n");
hbujanda 5:1b2d489605b1 64 log_serial->printf(XB_LIB_BANNER);
hbujanda 5:1b2d489605b1 65
hbujanda 5:1b2d489605b1 66 #if defined(ENABLE_LOGGING)
hbujanda 5:1b2d489605b1 67 new DigiLoggerMbedSerial(log_serial, LogLevelInfo);
hbujanda 5:1b2d489605b1 68 #endif
hbujanda 5:1b2d489605b1 69
hbujanda 5:1b2d489605b1 70 XBee802 xbee = XBee802(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 9600);
hbujanda 5:1b2d489605b1 71
hbujanda 5:1b2d489605b1 72 RadioStatus radioStatus = xbee.init();
hbujanda 5:1b2d489605b1 73 MBED_ASSERT(radioStatus == Success);
hbujanda 5:1b2d489605b1 74
hbujanda 5:1b2d489605b1 75 const RemoteXBee802 remoteDevice64b = RemoteXBee802(REMOTE_NODE_ADDR64);
hbujanda 5:1b2d489605b1 76 const RemoteXBee802 remoteDevice16b = RemoteXBee802(REMOTE_NODE_ADDR16);
hbujanda 5:1b2d489605b1 77
hbujanda 5:1b2d489605b1 78 send_broadcast_data(xbee);
hbujanda 5:1b2d489605b1 79 send_data_to_remote_node(xbee, remoteDevice64b);
hbujanda 5:1b2d489605b1 80 send_data_to_remote_node(xbee, remoteDevice16b);
hbujanda 5:1b2d489605b1 81
hbujanda 5:1b2d489605b1 82 delete(log_serial);
hbujanda 5:1b2d489605b1 83 }