Product family: XBP24-ZB Function set: ZigBee Coordinator API Firmware version: 21A7
Hello, I am currently using Digi's XBee Java Library with API (AP=1) and it works properly. However, another node of my network is associated with an Arduino and I want to use 'Arduino Library for communicating with XBee in API mode' (https://github.com/andrewrapp/xbee-arduino). That Arduino Library requires API Escaped operating mode (API 2). It was not supposed to be a problem, since XBee Java Library supports API 2. Nevertheless, I got an error when trying to open the serial connection with the XBee.
package com.digi.xbee.example;
import com.digi.xbee.api.XBeeDevice;
import com.digi.xbee.api.exceptions.XBeeException;
public class MainApp {
/* Constants */
// TODO Replace with the port where your sender module is connected to.
private static final String PORT = "COM4";
// TODO Replace with the baud rate of your sender module.
private static final int BAUD_RATE = 9600;
private static final String DATA_TO_SEND = "Hello XBee World!";
public static void main(String[] args) {
XBeeDevice myDevice = new XBeeDevice(PORT, BAUD_RATE);
byte[] dataToSend = DATA_TO_SEND.getBytes();
try {
myDevice.open();
System.out.format("Sending broadcast data: '%s'", new String(dataToSend));
myDevice.sendBroadcastData(dataToSend);
System.out.println(" >> Success");
} catch (XBeeException e) {
System.out.println(" >> Error");
e.printStackTrace();
System.exit(1);
} finally {
myDevice.close();
}
}
}
Error com.digi.xbee.api.exceptions.TimeoutException: There was a timeout while executing the requested operation. at com.digi.xbee.api.AbstractXBeeDevice.sendXBeePacket(AbstractXBeeDevice.java:989) at com.digi.xbee.api.AbstractXBeeDevice.sendATCommand(AbstractXBeeDevice.java:806) at com.digi.xbee.api.AbstractXBeeDevice.sendParameter(AbstractXBeeDevice.java:1983) at com.digi.xbee.api.AbstractXBeeDevice.getParameter(AbstractXBeeDevice.java:1925) at com.digi.xbee.api.AbstractXBeeDevice.readDeviceInfo(AbstractXBeeDevice.java:365) at com.digi.xbee.api.XBeeDevice.open(XBeeDevice.java:219) at com.digi.xbee.example.MainApp.main(MainApp.java:20)
Is there any difference between API and API 2 when programming with this Java Library?
The baud rate and API mode on each module in a network do not need to match, they're just used for serial communication with the local host. Note that the XBee module's ATAP
setting needs to match whichever API mode you're trying to use in your host software.
Keep using the working ATAP=1
with the Java library, and use ATAP=2
with the Arduino. API Mode 2 is just an "escaped" mode where certain bytes in the payload are escaped as a way to tell them apart from the 0x7E frame start character.
You can even run the Java end at 115200 or 57600bps, and keep the Arduino end at 9600bps. You can run modules with "AT mode" firmware and communicate with them from a module using "API mode". The radio module buffers data and it's sent over-the-air at 250kbps, regardless of your host settings.