Arduino, XBee-API, Maxbotix sensor and trying to measure water !

Hi - I hope I am posting this in the correct place on the forums.

I have been thinking for a while about how to measure water in my water tanks using an ultrasonic sensor. I have chosen the Maxbotix sensor as they make a water proof model.

My intention is to measure the water level in 4 of our home water tanks and then use an Arduino to turn on and off pumps and solenoid valves depending on the level of water in the tanks. I will also send the data up to Pachube (now that its free !!) to remotely monitor the levels and history.

To do this I have decided to run XBee’s and Arduino’s on each water tank and send all data back to a computer which also has an XBee attached.

I had hoped to use the XBee-API (Java) to interface the hardware to the software. Now, I am not a Java developer - I am in learning mode so brear with me here !

I have two XBee’s in API mode and I am trying to get the XBee-API code to a point where I can confirm they can ‘talk’ to each other via seom very simple Java code. I can’t even manage to do this ! I have a feeling it has to do with paths and classpaths but I am not sure. I don;t even know how to make use of the example code in the XBee-API examples folder.

Is there anyone out there who has used Andrew Rapps code who may be able to help me at least get to a point where my paths and classpath options are correct. I think if I can get to that stage I might be able to fumble my way through the project and do some learning along the way.

So here is my code (probably very wrong...)

package com.rapplogic.xbee.examples.zigbee;

import com.rapplogic.xbee.api.XBee;
import com.rapplogic.xbee.api.XBeeAddress16;
import com.rapplogic.xbee.api.XBeeAddress64;
import com.rapplogic.xbee.api.XBeeException;
import com.rapplogic.xbee.api.XBeeTimeoutException;
import com.rapplogic.xbee.api.zigbee.ZNetTxRequest;
import com.rapplogic.xbee.api.zigbee.ZNetTxStatusResponse;
import com.rapplogic.xbee.util.ByteUtils;


class XBeeTest {
  public static void main(String[] args){
    System.out.println("Here we go");



    // replace with your coordinator com/baud
    xbee.open("/dev/tty.usbmodemfd1321", 9600);

    // replace with SH + SL of your end device
    XBeeAddress64 address = new XBeeAddress64(0, 0x13, 0xa2, 0, 0x40, 0x0a, 0x3e, 0x02);

    // pin 20 corresponds to D0, and 5 activates the output (Digital output high) 
    RemoteAtRequest request = new RemoteAtRequest(address, "D0", new int[] {5});

    // turn on LED
    RemoteAtResponse response = (RemoteAtResponse) xbee.sendSynchronous(request, 10000);

    if (response.isOk()) {
            // success
    }

    // pause for 2 seconds
    Thread.sleep(2000);

    // command to turn off pin 20
    request = new RemoteAtRequest(address, "D0", new int[] {4});

    // send the command
    response = (RemoteAtResponse) xbee.sendSynchronous(request, 10000);

    if (response.isOk()) {
            // success
            System.out.println("LED is off");       
    }



  }
}

Here is my folder structure:

Here is what I am using to compile:

MacBookPro:Java Code xxxxxxxx$ javac -classpath .:./log4j.jar:./RXTXcomm.jar:./xbee-api-0.9.jar ./XBeeTest.java

And here is the complier output:

MacBookPro:Java Code xxxxxxx$ javac -classpath .:./log4j.jar:./RXTXcomm.jar:./xbee-api-0.9.jar ./XBeeTest.java 
./XBeeTest.java:21: cannot find symbol
symbol  : variable xbee
location: class com.rapplogic.xbee.examples.zigbee.XBeeTest
    xbee.open("/dev/tty.usbmodemfd1321", 9600);
    ^
./XBeeTest.java:27: cannot find symbol
symbol  : class RemoteAtRequest
location: class com.rapplogic.xbee.examples.zigbee.XBeeTest
    RemoteAtRequest request = new RemoteAtRequest(address, "D0", new int[] {5});
    ^
./XBeeTest.java:27: cannot find symbol
symbol  : class RemoteAtRequest
location: class com.rapplogic.xbee.examples.zigbee.XBeeTest
    RemoteAtRequest request = new RemoteAtRequest(address, "D0", new int[] {5});
                                  ^
./XBeeTest.java:30: cannot find symbol
symbol  : class RemoteAtResponse
location: class com.rapplogic.xbee.examples.zigbee.XBeeTest
    RemoteAtResponse response = (RemoteAtResponse) xbee.sendSynchronous(request, 10000);
    ^
./XBeeTest.java:30: cannot find symbol
symbol  : class RemoteAtResponse
location: class com.rapplogic.xbee.examples.zigbee.XBeeTest
    RemoteAtResponse response = (RemoteAtResponse) xbee.sendSynchronous(request, 10000);
                                 ^
./XBeeTest.java:30: cannot find symbol
symbol  : variable xbee
location: class com.rapplogic.xbee.examples.zigbee.XBeeTest
    RemoteAtResponse response = (RemoteAtResponse) xbee.sendSynchronous(request, 10000);
                                                   ^
./XBeeTest.java:40: cannot find symbol
symbol  : class RemoteAtRequest
location: class com.rapplogic.xbee.examples.zigbee.XBeeTest
    request = new RemoteAtRequest(address, "D0", new int[] {4});
                  ^
./XBeeTest.java:43: cannot find symbol
symbol  : class RemoteAtResponse
location: class com.rapplogic.xbee.examples.zigbee.XBeeTest
    response = (RemoteAtResponse) xbee.sendSynchronous(request, 10000);
                ^
./XBeeTest.java:43: cannot find symbol
symbol  : variable xbee
location: class com.rapplogic.xbee.examples.zigbee.XBeeTest
    response = (RemoteAtResponse) xbee.sendSynchronous(request, 10000);
                                  ^
9 errors
MacBookPro:Java Code xxxxxxx$

Now, I am not a Java developer - I am in learning mode so brear with me here !

No problem, since the Arduino is not programmed in Java.

You are trying to build a PC application, it appears, using Java. Not really an Arduino question. Well, OK.

    xbee.open("/dev/tty.usbmodemfd1321", 9600);

Here, you are trying to call the open method of the xbee object. Where is this xbee object created?

Right you are - that was the problem.

This whole project will rely on Arduinos out at each water tank to dote depth calculation and then send results to the java app running on the Mac (or Sheeva plug or similar). The arduino will also be used for I/O to trigger optoisolated relays etc for turning on and off pumps and water valves.

As soon as I get my head around java code I can move on to the Arduino code.

They have an water proff sensor???

Could you please tell me wich one is it ? because i want to measure water level in tanks too and it might reach the sensor when the tank is full.

Does anyone knows wich one it is? I gave it a look on their website but didn't find anything.

Thank you !