DigiMesh IO Sampling Callback example for mbed XBeeLib By Digi

Dependencies:   XBeeLib mbed

Fork of XBeeZB_IO_Sample_Callback by Digi International Inc.

This example shows how to monitor remote XBee modules DigitalInputs and ADCs. The remote XBee module sends packets periodically to the local XBee module containing the value of its DigitalInputs and ADCs. This library process those packets and calls a user registered function callback so the user can handle them.

See Handling IO Data Samples from other modules chapter for more information.

Common Setup

Make sure you have a valid Example Common Setup

Example Setup

Application

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.

Hardware

On the Remote XBee module, wire following peripherals to the pins specified on the table and schematics, or change the application pins according to your hardware setup:

LinePinValue
DIO2/ADC218ADC (Analog Input)
DIO3/ADC317Digital Input

/media/uploads/hbujanda/dio_adc_schem.png

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 do following operations:

  • Register the function callback that will be called by the library when corresponding IO sample frame is received.
  • Configure the remote XBee module pins according to the table above.
  • Configure the sample rate.
  • Configure remote XBee module to send IO Samples to local XBee module
  • Periodically ask the XBee library to process received frames

When a IO Sample frame is received the user callback does:

  • Read DIO3_AD3 digital value
  • Read DIO2_AD2 analog value
Revision:
10:5e8f8db1f994
Parent:
7:f4af8c290fd4
Child:
11:d0952218884b
--- a/main.cpp	Thu Jul 28 10:19:25 2016 +0200
+++ b/main.cpp	Thu Jul 28 10:31:19 2016 +0000
@@ -19,8 +19,10 @@
 
 #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)0x01234567)
+//#define REMOTE_NODE_ADDR64_LSB  ((uint32_t)0x40F86A88)
+#define REMOTE_NODE_ADDR64_LSB  ((uint32_t)0x40E465E0)
 
 #define REMOTE_NODE_ADDR64      UINT64(REMOTE_NODE_ADDR64_MSB, REMOTE_NODE_ADDR64_LSB)
 
@@ -28,7 +30,7 @@
 
 Serial *log_serial;
 
-static void io_data_cb(const RemoteXBeeZB& remote, const IOSampleZB& sample_data)
+static void io_data_cb(const RemoteXBeeDM& remote, const IOSampleDM& sample_data)
 {
     const uint64_t remote_addr64 = remote.get_addr64();
 
@@ -37,16 +39,16 @@
     RadioStatus radioStatus;
 
     DioVal dio3;
-    radioStatus = sample_data.get_dio(XBeeZB::DIO3_AD3, &dio3);
+    radioStatus = sample_data.get_dio(XBeeDM::DIO3_AD3, &dio3);
     if (radioStatus != Success)
-        log_serial->printf("sample_data.get_dio(XBeeZB::DIO3_AD3, &dio3) FAILED\r\n");
+        log_serial->printf("sample_data.get_dio(XBeeDM::DIO3_AD3, &dio3) FAILED\r\n");
     else
         log_serial->printf("DIO3 Digital value %d\r\n", dio3);
 
     uint16_t ad2;
-    radioStatus = sample_data.get_adc(XBeeZB::DIO2_AD2, &ad2);
+    radioStatus = sample_data.get_adc(XBeeDM::DIO2_AD2, &ad2);
     if (radioStatus != Success)
-        log_serial->printf("sample_data.get_adc(XBeeZB::DIO2_AD2, &ad2) FAILED\r\n");
+        log_serial->printf("sample_data.get_adc(XBeeDM::DIO2_AD2, &ad2) FAILED\r\n");
     else
         log_serial->printf("AD2 Analog value %04x\r\n", ad2);
 }
@@ -55,14 +57,14 @@
 {
     log_serial = new Serial(DEBUG_TX, DEBUG_RX);
     log_serial->baud(9600);
-    log_serial->printf("Sample application to demo how to receive IO Sample Data from a RemoteXBeeZB node\r\n\r\n");
+    log_serial->printf("Sample application to demo how to receive IO Sample Data from a RemoteXBeeDM node\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);
 
     /* Register callback */
     xbee.register_io_sample_cb(&io_data_cb);
@@ -71,23 +73,14 @@
     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 RemoteXBeeZB remoteDevice = RemoteXBeeZB(REMOTE_NODE_ADDR64);
+    const RemoteXBeeDM remoteDevice = RemoteXBeeDM(REMOTE_NODE_ADDR64);
     log_serial->printf("Configuring remote Device (%08X:%08X) DIO3_AD3 as Input and DIO2_AD2 as ADC\r\n", REMOTE_NODE_ADDR64_MSB, REMOTE_NODE_ADDR64_LSB);
-    radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO3_AD3, DigitalInput);
+    radioStatus = xbee.set_pin_config(remoteDevice, XBeeDM::DIO3_AD3, DigitalInput);
     MBED_ASSERT(radioStatus == Success);
     log_serial->printf("Enabling remote Device (%08X:%08X) internal Pull-up resistor on DIO3_AD3\r\n", REMOTE_NODE_ADDR64_MSB, REMOTE_NODE_ADDR64_LSB);
-    radioStatus = xbee.set_pin_pull_up(remoteDevice, XBeeZB::DIO3_AD3, true);
+    radioStatus = xbee.set_pin_pull_up(remoteDevice, XBeeDM::DIO3_AD3, true);
     MBED_ASSERT(radioStatus == Success);
-    radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO2_AD2, Adc);
+    radioStatus = xbee.set_pin_config(remoteDevice, XBeeDM::DIO2_AD2, Adc);
     MBED_ASSERT(radioStatus == Success);
 
     log_serial->printf("Configuring remote Device (%08X:%08X) to send samples every 5 seconds\r\n", REMOTE_NODE_ADDR64_MSB, REMOTE_NODE_ADDR64_LSB);