I’m using the xbee java library to receive datat from another xbee connected to an arduino. It seems like I got some thing but itn’t clear can any one give somme help to read the data ?
this is the java code:
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import com.rapplogic.xbee.api.ApiId;
import com.rapplogic.xbee.api.XBee;
import com.rapplogic.xbee.api.XBeeAddress64;
import com.rapplogic.xbee.api.XBeeException;
import com.rapplogic.xbee.api.XBeeResponse;
import com.rapplogic.xbee.api.XBeeTimeoutException;
import com.rapplogic.xbee.api.zigbee.ZNetRxResponse;
import com.rapplogic.xbee.api.zigbee.ZNetTxRequest;
import com.rapplogic.xbee.api.zigbee.ZNetTxStatusResponse;
import com.rapplogic.xbee.util.ByteUtils;
import com.rapplogic.xbee.api.zigbee.ZNetRxIoSampleResponse;
public class collector {
private final static Logger log = Logger.getLogger(collector.class);
XBee xbee = new XBee();
private collector() throws Exception {
try{
xbee.open("COM4", 9600);
System.out.println("connection successfully opened");
}catch (Exception e){
System.out.println("** Error opening XBee port: " + e + " **");
}
}
public void run() {
try{
// we wait here until a packet is received.
XBeeResponse response = xbee.getResponse();
// System.out.println("Received response " + response.toString());
if (response.getApiId() == ApiId.ZNET_RX_RESPONSE) {
// we received a packet from ZNetSenderTest.java
ZNetRxResponse rx = (ZNetRxResponse) response;
System.out.println("Received RX packet, option is " + rx.getOption() + ", sender 64 address is " + ByteUtils.toBase16(rx.getRemoteAddress64().getAddress()) + ", remote 16-bit address is " + ByteUtils.toBase16(rx.getRemoteAddress16().getAddress()) + ", data is " + ByteUtils.toBase16(rx.getData()));
//payload = rx.getData();
//int uint8 = payload & 0xFF;
// System.out.println("Data received: ");
}
}catch(Exception e){
System.out.println("Error receiving response: " + e);
xbee.close();
}
}
public static void main(String[] args) throws Exception {
PropertyConfigurator.configure("log4j.properties");
new collector();
}
}
and this what i got:
packet from XBee: apiId=ZNET_RX_RESPONSE (0x90),length=14,checksum=0x59,error=false,remoteAddress64=0x00 0x13 0xa2 0x00 0x40 0x3d 0x02 0xa0,remoteAddress16=0x78 0x32,option=PACKET_ACKNOWLEDGED,data=0x48 0x4f
[2016-02-09 09:29:50,814] [XBee Packet Parser Thread] [DEBUG] [com.rapplogic.xbee.api.XBeePacketParser] Notifying API user that packets are ready