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.

Revision:
10:0d9953619462
Parent:
7:d685568a3bc8
Child:
11:7e9486204a86
--- a/main.cpp	Thu Jul 28 10:19:46 2016 +0200
+++ b/main.cpp	Thu Jul 28 10:18:39 2016 +0000
@@ -19,8 +19,8 @@
 
 #define REMOTE_NODE_ADDR64_MSB  ((uint32_t)0x0013A200)
 
-#error "Replace next define with the LSB of the remote module's 64-bit address (SL parameter)"
-#define REMOTE_NODE_ADDR64_LSB  ((uint32_t)0x01234567)
+//#error "Replace next define with the LSB of the remote module's 64-bit address (SL parameter)"
+#define REMOTE_NODE_ADDR64_LSB  ((uint32_t)0x40E465E0)
 
 #define REMOTE_NODE_ADDR64      UINT64(REMOTE_NODE_ADDR64_MSB, REMOTE_NODE_ADDR64_LSB)
 
@@ -28,19 +28,7 @@
 
 Serial *log_serial;
 
-static void send_data_to_coordinator(XBeeZB& xbee)
-{
-    const char data[] = "send_data_to_coordinator";
-    const uint16_t data_len = strlen(data);
-
-    const TxStatus txStatus = xbee.send_data_to_coordinator((const uint8_t *)data, data_len);
-    if (txStatus == TxStatusSuccess)
-        log_serial->printf("send_data_to_coordinator OK\r\n");
-    else
-        log_serial->printf("send_data_to_coordinator failed with %d\r\n", (int) txStatus);
-}
-
-static void send_broadcast_data(XBeeZB& xbee)
+static void send_broadcast_data(XBeeDM& xbee)
 {
     const char data[] = "send_broadcast_data";
     const uint16_t data_len = strlen(data);
@@ -52,7 +40,7 @@
         log_serial->printf("send_broadcast_data failed with %d\r\n", (int) txStatus);
 }
 
-static void send_data_to_remote_node(XBeeZB& xbee, const RemoteXBeeZB& RemoteDevice)
+static void send_data_to_remote_node(XBeeDM& xbee, const RemoteXBeeDM& RemoteDevice)
 {
     const char data[] = "send_data_to_remote_node";
     const uint16_t data_len = strlen(data);
@@ -64,7 +52,7 @@
         log_serial->printf("send_data_to_remote_node failed with %d\r\n", (int) txStatus);
 }
 
-static void send_explicit_data_to_remote_node(XBeeZB& xbee, const RemoteXBeeZB& RemoteDevice)
+static void send_explicit_data_to_remote_node(XBeeDM& xbee, const RemoteXBeeDM& RemoteDevice)
 {
     char data[] = "send_explicit_data_to_remote_node";
     const uint16_t data_len = strlen(data);
@@ -84,29 +72,20 @@
 {
     log_serial = new Serial(DEBUG_TX, DEBUG_RX);
     log_serial->baud(9600);
-    log_serial->printf("Sample application to demo how to send unicast and broadcast data with the XBeeZB\r\n\r\n");
+    log_serial->printf("Sample application to demo how to send unicast and broadcast data with the XBeeDM\r\n\r\n");
     log_serial->printf(XB_LIB_BANNER);
 
 #if defined(ENABLE_LOGGING)
     new DigiLoggerMbedSerial(log_serial, LogLevelInfo);
 #endif
 
-    XBeeZB xbee = XBeeZB(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 9600);
+    XBeeDM xbee = XBeeDM(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 9600);
 
     RadioStatus radioStatus = xbee.init();
     MBED_ASSERT(radioStatus == Success);
 
-    /* Wait until the device has joined the network */
-    log_serial->printf("Waiting for device to join the network: ");
-    while (!xbee.is_joined()) {
-        wait_ms(1000);
-        log_serial->printf(".");
-    }
-    log_serial->printf("OK\r\n");
+    const RemoteXBeeDM remoteDevice = RemoteXBeeDM(REMOTE_NODE_ADDR64);
 
-    const RemoteXBeeZB remoteDevice = RemoteXBeeZB(REMOTE_NODE_ADDR64);
-
-    send_data_to_coordinator(xbee);
     send_broadcast_data(xbee);
     send_data_to_remote_node(xbee, remoteDevice);
     send_explicit_data_to_remote_node(xbee, remoteDevice);