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:
hbujanda
Date:
Fri Jul 29 12:15:07 2016 +0200
Revision:
11:7e9486204a86
Parent:
10:0d9953619462
Automatic upload

Who changed what in which revision?

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