I recently built a wireless wireless monitor that uses XBee to transmit data. I'm trying to get Tweet A Watt data from Processing for use in prototyping visual energy feedback. Using the XBee API library for processing ( http://www.faludi.com/code/xbee-api-library-for-processing/ ), I made some progress, but ran into an obstacle that I would appreciate any input.
My processing sketch looks like this:
import xbee.*;
import processing.serial.*;
Serial port;
XBeeReader xbee;
int rssi = 0;
int address = 0;
int samples = 0;
int[] analog;
void setup() {
port = new Serial(this, Serial.list()[0], 9600);
xbee = new XBeeReader(this, port);
xbee.startXBee();
}
void draw() {}
public void xBeeEvent(XBeeReader xbee) {
XBeeDataFrame data = xbee.getXBeeReading();
println("");
println("LOOP " + hour() + ":" + minute() + ":" + second());
address = data.getAddress16();
println("API ID: " + address);
rssi = data.getRSSI();
println("RSSI: " + rssi);
samples = data.getTotalSamples();
println("Total Samples: " + samples);
for (int i=0; i < samples; i++) {
analog = data.getAnalog(i);
print("[");
for (int j=0; j < analog.length; j++) {
print(analog[j]);
if (j < analog.length - 1) { print(", "); }
}
print("]");
if (i < samples - 1) { print(", "); }
else { println(""); }
}
}
Everything works as expected. XBeeEvent is called every 2s and displays the correct values for the API ID, RSSI, and Total Samples (19). However, when I output the contents of the analog readings, I seem to get the first sample repeated 19 times. See this example:
LOOP 10:37:57
API ID: 1
RSSI: -61
Total Samples: 19
[512, -1, -1, -1, 688, -1], [512, -1, -1, -1, 688, -1], [512, -1, -1, -1, 688, -1], [512, -1, -1, -1, 688, -1], [512, -1, -1, -1, 688, -1], [512, -1, -1, -1, 688, -1], [512, -1, -1, -1, 688, -1], [512, -1, -1, -1, 688, -1], [512, -1, -1, -1, 688, -1], [512, -1, -1, -1, 688, -1], [512, -1, -1, -1, 688, -1], [512, -1, -1, -1, 688, -1], [512, -1, -1, -1, 688, -1], [512, -1, -1, -1, 688, -1], [512, -1, -1, -1, 688, -1], [512, -1, -1, -1, 688, -1], [512, -1, -1, -1, 688, -1], [512, -1, -1, -1, 688, -1], [512, -1, -1, -1, 688, -1]
LOOP 10:38:59
API ID: 1
RSSI: -61
Total Samples: 19
[503, -1, -1, -1, 561, -1], [503, -1, -1, -1, 561, -1], [503, -1, -1, -1, 561, -1], [503, -1, -1, -1, 561, -1], [503, -1, -1, -1, 561, -1], [503, -1, -1, -1, 561, -1], [503, -1, -1, -1, 561, -1], [503, -1, -1, -1, 561, -1], [503, -1, -1, -1, 561, -1], [503, -1, -1, -1, 561, -1], [503, -1, -1, -1, 561, -1], [503, -1, -1, -1, 561, -1], [503, -1, -1, -1, 561, -1], [503, -1, -1, -1, 561, -1], [503, -1, -1, -1, 561, -1], [503, -1, -1, -1, 561, -1], [503, -1, -1, -1, 561, -1], [503, -1, -1, -1, 561, -1], [503, -1, -1, -1, 561, -1]
, 19 . Python script Tweet A Watt (wattcher.py) XBee, 19 . , "".
API XBee getAnalog() getAnalog (n) :
getAnalog() – returns an array of integers that represents the current state of each analog channel with -1 indicating that the channel is not configured for analog. Use this when there is only one sample per frame.
getAnalog(int n) – returns the nth sample of analog data as an array of integers with -1 indicating that the channel is not configured for analog.
getAnalog (int n) . , "" , XBeeDataFrame data = xbee.getXBeeReading();?
Serial , API XBee ( (http://www.tigoe.net/pcomp/code/category/Processing/8), (http://processing.org/reference/libraries/serial/Serial.html) (http://ssdl.stanford.edu/ssdl/images/stories/AA236/0708A/Lab/Rover/Parts/xbeeproproductmanual.pdf), .
- XBee, API XBee , . , , . , , Adafruit ( The Tweet A Watt - http://forums.adafruit.com/viewtopic.php?f=40&t=16067&sid=4e34727fa59b7c7d589564d2d6b85e46) (http://processing.org/discourse/yabb2/YaBB.pl?num=1276111549), , , .
, , . .