Connecting Xbee and processing and reading remote data


#1

Hello,

I am currently using processing, hooked up to a arduino Uno with an Xbee shield and an Xbee to top it all off. This setup is reading a mesh network of other xbee radios out there, and processing the data. What I want, however, is to get rid of the coordinator arduino and shield, and just simply plug the xbee into a usb connector then into the computer. Everything I have found is from Faludis 2007 book which no longer works with the newer versions of processing. I have the code below, but it never seems to compile and run.

import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

import org.apache.log4j.PropertyConfigurator;

import com.rapplogic.xbee.api.PacketListener;
import com.rapplogic.xbee.api.XBee;
import com.rapplogic.xbee.api.XBeeResponse;
import com.rapplogic.xbee.api.wpan.RxResponseIoSample;

XBee xbee;
Queue<XBeeResponse> queue = new ConcurrentLinkedQueue<XBeeResponse>();
boolean message;
XBeeResponse response;
  
void setup() {
  try { 
    //optional.  set up logging
    PropertyConfigurator.configure(dataPath("") + "log4j.properties");

    xbee = new XBee();
    // replace with your COM port
    xbee.open("COM6", 9600);

    xbee.addPacketListener(new PacketListener() {
      public void processResponse(XBeeResponse response) {
        queue.offer(response);
      }
    }
    );
  } 
  catch (Exception e) {
    System.out.println("XBee failed to initialize");
    e.printStackTrace();
    System.exit(1);
  }
}

void draw() {
  try {
    readPackets();
  } 
  catch (Exception e) {
    e.printStackTrace();
  }
}

void readPackets() throws Exception {

  while ((response = queue.poll()) != null) {
    // we got something!
    try {
      RxResponseIoSample ioSample = (RxResponseIoSample) response;

      println("We received a sample from " + ioSample.getSourceAddress());

      if (ioSample.containsAnalog()) {
        println("10-bit temp reading (pin 19) is " +
          ioSample.getSamples()[0].getAnalog1());
      }
    } 
    catch (ClassCastException e) {
      // not an IO Sample
    }
  }
}

I have tried numerous other example programs from the internet, but none seem to help my situation. I have also added the log4.jar and xbee api0.9 version files into the library, as well as dragged them into the program where they are loaded automatically.

Any help is greatly appreciated, thank you!