ZB Coord API for XBee: This XBee library drives Digi XBee ZB Modules in API Operation mode. Most commands include remote communication's are supported by the functions of this library. You can control XBee devices through the API software modules in this, without using any AT commands. Please refer to the following page and some of sample codes:

Dependents:   sample02_sw xbee_aging sample01_led sample04_sens

XBee library 'ZB Coord API'

/media/uploads/bokunimowakaru/nucleoboard.jpg

Nucleo Board + Arduino Wireless Shield + XBee ZB Module + LCD

This XBee liblary is developed for Digi XBee ZB Modules on Nucleo F401RE Micro Computer Board through Arduino Wireless Shield.

Quote:

When you will use this liblary for anything other than Nucleo microcomputer board, please change the 4th line of xbee/xbee.cpp. The above code is only for STM32 Nucleo board.

  • RawSerial _xbee_serial(SERIAL_TX, SERIAL_RX);

/media/uploads/bokunimowakaru/nucleo_xbee.jpg

Hardware Jumper Settings

The hardware soldering jumper setting for the serial ports is necessary for Nucleo board.

  • Set OPEN for SB14(TX)
  • Set SHORT jumper for SB62
  • Set SHORT jumper for SB63

/media/uploads/bokunimowakaru/nucleo_jp.jpg

Examples

Sample Code 01 LED

An XBee ZB Coordinator on a Nucleo Board controls LEDs on the other XBee ZB device.

#include "xbee.h"
DigitalOut myled(LED1);
 
int main(){
    // Please set MAC Address to access your remote XBee device.
    byte dev_gpio[]   = {0x00,0x13,0xA2,0x00,0x40,0x30,0xC1,0x6F};
    
    myled = 1;                          // set Higher Level(3.3V) for LED port on NUCLEO
    xbee_init( 0 );                     // Initialize XBee COM Port Settings
    xbee_atnj( 0xFF );                  // Enable Network Join
    myled = 0;                          // set Lower Level(0.0V) for LED port on NUCLEO
    
    while(1){ 
        myled = 1;                      // set Higher Level(3.3V) for LED port on NUCLEO
        xbee_gpo(dev_gpio,11,1);        // set H Level for GPO port 11 on remote xbee
        xbee_gpo(dev_gpio,12,1);        // set H Level for GPO port 12 on remote xbee
        wait(1);
        myled = 0;                      // set Lower Level(0.0V) for LED port on NUCLEO
        xbee_gpo(dev_gpio,11,0);        // set L Level for GPO port 11 on remote xbee
        xbee_gpo(dev_gpio,12,0);        // set L Level for GPO port 12 on remote xbee
        wait(1);
    }
}

http://mbed.org/users/bokunimowakaru/code/sample01_led/

Sample Code 02 Switch

To push buttons (or switches) on an XBee ZB device report the conditions of input ports on it to a Nucleo board, and display them on a LCD.

#include "xbee.h"
#include "TextLCD.h"
TextLCD lcd(PA_9, PC_7, PB_5, PB_4, PB_10, PA_8); // rs, e, d4-d7
  
int main(){
    byte data;
    int i;
    XBEE_RESULT xbee_result;
    byte dev_gpio[]   = {0x00,0x13,0xA2,0x00,0x40,0x30,0xC1,0x6F};
    
    lcd.cls(); lcd.printf("Sample 2 SW");
    xbee_init( 0x00 ); 
    lcd.cls(); lcd.printf("ATNJ");
    xbee_atnj( 0xFF ); 
    lcd.cls(); lcd.printf("gpio init");
    xbee_gpio_init(dev_gpio);           // Send GPIO mode settings to remote device.
    lcd.cls(); lcd.printf("DONE");
    
    while(1){
        data = xbee_rx_call( &xbee_result );
        if( xbee_result.MODE == MODE_GPIN){     // When a GPIO packet is recieved,
            lcd.cls();
            for( i=7; i>=0 ; i--) lcd.printf( "%c",(char)( (int)'0' + ((data>>i) & 0x01) ) );
                                        // Display the recieved data.
        }
    }
}

http://mbed.org/users/bokunimowakaru/code/sample02_sw/

Sample Code 04 Sensor

Measured results of an XBee wireless sensor device are displayed a LCD on Nucleo board with an XBee coordinator which is in API mode.

#include <xbee.h>
#include "TextLCD.h"
#define FORCE_INTERVAL  100
TextLCD lcd(PA_9, PC_7, PB_5, PB_4, PB_10, PA_8); // rs, e, d4-d7
byte dev_sens[8];   // IEEE Address
 
int main(){
    int i;
    int dev_en = 0;                 // Device Detection Flag
    XBEE_RESULT xbee_result;            // Stracture for recieved data
    int trig=0;
    float value;

    lcd.cls(); lcd.printf("Sample 4 SENS");
    xbee_init( 0x00 ); 
    lcd.cls(); lcd.printf("Searching:SENSOR");
    if( xbee_atnj(10) ){                // Enable Network Join during 10 seconds.
        lcd.cls(); lcd.printf("Found a device");
        xbee_from( dev_sens );          // Get address of remote device. 
        dev_en = 1;
        xbee_gpio_config( dev_sens, 1 , AIN ); // Analog Input mode to port 1 on remote device
        xbee_gpio_config( dev_sens, 2 , AIN ); // Analog Input mode to port 2 on remote device
    }else{
        lcd.cls(); lcd.printf("Failed:no dev.");
    }
    wait(1);
    lcd.cls();
    
    while(1){
        if(dev_en){ 
            if(trig<=0){
                lcd.locate(12,0); lcd.printf("Trig"); wait(0.1);
                xbee_force(dev_sens);           // Send a request command to remote device.
                trig = FORCE_INTERVAL;
                lcd.locate(12,0); lcd.printf("    ");
            }
        }else{
            lcd.cls(); lcd.printf("Waiting for XBee");
            wait(0.5);
            lcd.cls();
        }
        trig--;
 
        xbee_rx_call( &xbee_result );       // Check a recieved packet.
        switch( xbee_result.MODE ){         // Check the packet type.
            case MODE_RESP:                 // the responce for the request in xbee_force().
            case MODE_GPIN:                 // Report data from remote xbee device.
                if( bytecmp( dev_sens , &(xbee_result.FROM[0]) ,8 ) == 0 && xbee_result.STATUS == STATUS_OK ){
                    value = xbee_sensor_result( &xbee_result, LIGHT);
                    lcd.locate(0,0); lcd.printf( "%.1f Lux   ",value);
                    value = xbee_sensor_result( &xbee_result, TEMP);
                    lcd.locate(0,1); lcd.printf( "%.1f C   ",value);
                }
                break;
            case MODE_IDNT:             // Commissioning Button Report is recieved.
                lcd.cls(); lcd.printf("found a new dev");
                for( i=0;i<8;i++ ) dev_sens[i]=xbee_result.FROM[i];
                                        // Save MAC address of reported device.
                dev_en = 1;             // Flag on (A sensor is detected.)
                trig = 0;
                xbee_gpio_config( dev_sens, 1 , AIN ); // Set Analog Mode to port 1 on remote XBee
                xbee_gpio_config( dev_sens, 2 , AIN ); // Set Analog Mode to port 2 on remote XBee
                lcd.cls();
                break;
            default:
                break;
        }
    }
}

http://mbed.org/users/bokunimowakaru/code/sample04_sens/

no such method: docs