DigiMesh Send Data example for mbed XBeeLib By Digi

Dependencies:   XBeeLib mbed

Fork of XBeeZB_Send_Data by Digi International Inc.

Description

This example shows how to send data to a remote XBeeDM 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

Application

Broadcast messages doesn't require any configuration, but for unicast messages to a specific node 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 first send a broadcast message and finally a couple of unicast messages to the configured remote XBee module.

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:
spastor
Date:
Fri May 08 11:53:05 2015 +0200
Revision:
2:e17ec1d60e80
Parent:
0:6cb09a6542ff
Automatic upload

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hbujanda 0:6cb09a6542ff 1 /**
hbujanda 0:6cb09a6542ff 2 * Copyright (c) 2015 Digi International Inc.,
hbujanda 0:6cb09a6542ff 3 * All rights not expressly granted are reserved.
hbujanda 0:6cb09a6542ff 4 *
hbujanda 0:6cb09a6542ff 5 * This Source Code Form is subject to the terms of the Mozilla Public
hbujanda 0:6cb09a6542ff 6 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
hbujanda 0:6cb09a6542ff 7 * You can obtain one at http://mozilla.org/MPL/2.0/.
hbujanda 0:6cb09a6542ff 8 *
hbujanda 0:6cb09a6542ff 9 * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
hbujanda 0:6cb09a6542ff 10 * =======================================================================
hbujanda 0:6cb09a6542ff 11 */
hbujanda 0:6cb09a6542ff 12
hbujanda 0:6cb09a6542ff 13 #include "mbed.h"
hbujanda 0:6cb09a6542ff 14 #include "XBeeLib.h"
hbujanda 0:6cb09a6542ff 15 #if defined(ENABLE_LOGGING)
hbujanda 0:6cb09a6542ff 16 #include "DigiLoggerMbedSerial.h"
hbujanda 0:6cb09a6542ff 17 using namespace DigiLog;
hbujanda 0:6cb09a6542ff 18 #endif
hbujanda 0:6cb09a6542ff 19
hbujanda 0:6cb09a6542ff 20 // TODO Replace with the MSB of the remote module's 64-bit address (SH parameter)
hbujanda 0:6cb09a6542ff 21 #define REMOTE_NODE_ADDR64_MSB ((uint32_t)0x0013A200)
hbujanda 0:6cb09a6542ff 22 // TODO Replace with the LSB of the remote module's 64-bit address (SL parameter)
hbujanda 0:6cb09a6542ff 23 #define REMOTE_NODE_ADDR64_LSB ((uint32_t)0x40D2B03E)
hbujanda 0:6cb09a6542ff 24
spastor 2:e17ec1d60e80 25 #define REMOTE_NODE_ADDR64 UINT64(REMOTE_NODE_ADDR64_MSB, REMOTE_NODE_ADDR64_LSB)
spastor 2:e17ec1d60e80 26
hbujanda 0:6cb09a6542ff 27 using namespace XBeeLib;
hbujanda 0:6cb09a6542ff 28
hbujanda 0:6cb09a6542ff 29 Serial *log_serial;
hbujanda 0:6cb09a6542ff 30
hbujanda 0:6cb09a6542ff 31 static void send_data_to_coordinator(XBeeZB& xbee)
hbujanda 0:6cb09a6542ff 32 {
hbujanda 0:6cb09a6542ff 33 const char data[] = "send_data_to_coordinator";
hbujanda 0:6cb09a6542ff 34 const uint16_t data_len = strlen(data);
hbujanda 0:6cb09a6542ff 35
hbujanda 0:6cb09a6542ff 36 const TxStatus txStatus = xbee.send_data_to_coordinator((const uint8_t *)data, data_len);
hbujanda 0:6cb09a6542ff 37 if (txStatus == TxStatusSuccess)
hbujanda 0:6cb09a6542ff 38 log_serial->printf("send_data_to_coordinator OK\r\n");
hbujanda 0:6cb09a6542ff 39 else
hbujanda 0:6cb09a6542ff 40 log_serial->printf("send_data_to_coordinator failed with %d\r\n", (int) txStatus);
hbujanda 0:6cb09a6542ff 41 }
hbujanda 0:6cb09a6542ff 42
hbujanda 0:6cb09a6542ff 43 static void send_broadcast_data(XBeeZB& xbee)
hbujanda 0:6cb09a6542ff 44 {
hbujanda 0:6cb09a6542ff 45 const char data[] = "send_broadcast_data";
hbujanda 0:6cb09a6542ff 46 const uint16_t data_len = strlen(data);
hbujanda 0:6cb09a6542ff 47
hbujanda 0:6cb09a6542ff 48 const TxStatus txStatus = xbee.send_data_broadcast((const uint8_t *)data, data_len);
hbujanda 0:6cb09a6542ff 49 if (txStatus == TxStatusSuccess)
hbujanda 0:6cb09a6542ff 50 log_serial->printf("send_broadcast_data OK\r\n");
hbujanda 0:6cb09a6542ff 51 else
hbujanda 0:6cb09a6542ff 52 log_serial->printf("send_broadcast_data failed with %d\r\n", (int) txStatus);
hbujanda 0:6cb09a6542ff 53 }
hbujanda 0:6cb09a6542ff 54
hbujanda 0:6cb09a6542ff 55 static void send_data_to_remote_node(XBeeZB& xbee, const RemoteXBeeZB& RemoteDevice)
hbujanda 0:6cb09a6542ff 56 {
hbujanda 0:6cb09a6542ff 57 const char data[] = "send_data_to_remote_node";
hbujanda 0:6cb09a6542ff 58 const uint16_t data_len = strlen(data);
hbujanda 0:6cb09a6542ff 59
hbujanda 0:6cb09a6542ff 60 const TxStatus txStatus = xbee.send_data(RemoteDevice, (const uint8_t *)data, data_len);
hbujanda 0:6cb09a6542ff 61 if (txStatus == TxStatusSuccess)
hbujanda 0:6cb09a6542ff 62 log_serial->printf("send_data_to_remote_node OK\r\n");
hbujanda 0:6cb09a6542ff 63 else
hbujanda 0:6cb09a6542ff 64 log_serial->printf("send_data_to_remote_node failed with %d\r\n", (int) txStatus);
hbujanda 0:6cb09a6542ff 65 }
hbujanda 0:6cb09a6542ff 66
hbujanda 0:6cb09a6542ff 67 static void send_explicit_data_to_remote_node(XBeeZB& xbee, const RemoteXBeeZB& RemoteDevice)
hbujanda 0:6cb09a6542ff 68 {
hbujanda 0:6cb09a6542ff 69 char data[] = "send_explicit_data_to_remote_node";
hbujanda 0:6cb09a6542ff 70 const uint16_t data_len = strlen(data);
hbujanda 0:6cb09a6542ff 71 const uint8_t dstEP = 0xE8;
hbujanda 0:6cb09a6542ff 72 const uint8_t srcEP = 0xE8;
hbujanda 0:6cb09a6542ff 73 const uint16_t clusterID = 0x0011;
hbujanda 0:6cb09a6542ff 74 const uint16_t profileID = 0xC105;
hbujanda 0:6cb09a6542ff 75
hbujanda 0:6cb09a6542ff 76 const TxStatus txStatus = xbee.send_data(RemoteDevice, dstEP, srcEP, clusterID, profileID, (const uint8_t *)data, data_len);
hbujanda 0:6cb09a6542ff 77 if (txStatus == TxStatusSuccess)
hbujanda 0:6cb09a6542ff 78 log_serial->printf("send_explicit_data_to_remote_node OK\r\n");
hbujanda 0:6cb09a6542ff 79 else
hbujanda 0:6cb09a6542ff 80 log_serial->printf("send_explicit_data_to_remote_node failed with %d\r\n", (int) txStatus);
hbujanda 0:6cb09a6542ff 81 }
hbujanda 0:6cb09a6542ff 82
hbujanda 0:6cb09a6542ff 83 int main()
hbujanda 0:6cb09a6542ff 84 {
hbujanda 0:6cb09a6542ff 85 log_serial = new Serial(DEBUG_TX, DEBUG_RX);
hbujanda 0:6cb09a6542ff 86 log_serial->baud(9600);
hbujanda 0:6cb09a6542ff 87 log_serial->printf("Sample application to demo how to send unicast and broadcast data with the XBeeZB\r\n\r\n");
hbujanda 0:6cb09a6542ff 88 log_serial->printf(XB_LIB_BANNER);
hbujanda 0:6cb09a6542ff 89
hbujanda 0:6cb09a6542ff 90 #if defined(ENABLE_LOGGING)
hbujanda 0:6cb09a6542ff 91 new DigiLoggerMbedSerial(log_serial, LogLevelInfo);
hbujanda 0:6cb09a6542ff 92 #endif
hbujanda 0:6cb09a6542ff 93
hbujanda 0:6cb09a6542ff 94 XBeeZB xbee = XBeeZB(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 9600);
hbujanda 0:6cb09a6542ff 95
hbujanda 0:6cb09a6542ff 96 RadioStatus radioStatus = xbee.init();
hbujanda 0:6cb09a6542ff 97 MBED_ASSERT(radioStatus == Success);
hbujanda 0:6cb09a6542ff 98
hbujanda 0:6cb09a6542ff 99 /* Wait until the device has joined the network */
hbujanda 0:6cb09a6542ff 100 log_serial->printf("Waiting for device to join the network: ");
hbujanda 0:6cb09a6542ff 101 while (!xbee.is_joined()) {
hbujanda 0:6cb09a6542ff 102 wait_ms(1000);
hbujanda 0:6cb09a6542ff 103 log_serial->printf(".");
hbujanda 0:6cb09a6542ff 104 }
hbujanda 0:6cb09a6542ff 105 log_serial->printf("OK\r\n");
hbujanda 0:6cb09a6542ff 106
spastor 2:e17ec1d60e80 107 const RemoteXBeeZB remoteDevice = RemoteXBeeZB(REMOTE_NODE_ADDR64);
hbujanda 0:6cb09a6542ff 108
hbujanda 0:6cb09a6542ff 109 send_data_to_coordinator(xbee);
hbujanda 0:6cb09a6542ff 110 send_broadcast_data(xbee);
hbujanda 0:6cb09a6542ff 111 send_data_to_remote_node(xbee, remoteDevice);
hbujanda 0:6cb09a6542ff 112 send_explicit_data_to_remote_node(xbee, remoteDevice);
hbujanda 0:6cb09a6542ff 113
hbujanda 0:6cb09a6542ff 114 delete(log_serial);
hbujanda 0:6cb09a6542ff 115 }