2010-06-10 66 views
3

我最近建立了一個使用XBee進行數據傳輸的Tweet A Watt(http://www.ladyada.net/make/tweetawatt/)無線電力監視器。我試圖將Tweet A Watt數據加入處理中,以用於創建一些視覺能量反饋原型。使用XBee API庫進行處理(http://www.faludi.com/code/xbee-api-library-for-processing/),我已經取得了一些進展,但碰到了一個障礙,我會感激任何輸入。將XBee數據讀入處理

我處理草圖看起來是這樣的:

/* 
XBee Communication Prototype 
XBee API Library by Daniel Shiffman and Rob Faludi: http://www.faludi.com/code/xbee-api-library-for-processing/ 
Sample XBee communication code adapted from Tom Igoe: http://www.tigoe.net/pcomp/code/category/Processing/148 
*/ 

//import the xbee and serial libraries: 
import xbee.*; 
import processing.serial.*; 

// set up Xbee parameters: 
Serial port; 
XBeeReader xbee; 
int rssi = 0;  // received signal strength 
int address = 0;  // sender's address 
int samples = 0;  // total number of samples 
int[] analog;  // values from the analog I/O pins 

void setup() { 
    // set up xbee 
    port = new Serial(this, Serial.list()[0], 9600); 
    xbee = new XBeeReader(this, port); 
    xbee.startXBee(); 
} 

void draw() {}  

// called every time an XBee event is received: every 2s in the case of the Tweet A Watt 
public void xBeeEvent(XBeeReader xbee) {  
    // Grab a frame of data 
    XBeeDataFrame data = xbee.getXBeeReading(); 

    println(""); 
    println("LOOP " + hour() + ":" + minute() + ":" + second()); 

    // Get the transmitter address 
    address = data.getAddress16(); 
    println("API ID: " + address);  

    // Get the RSSI 
    rssi = data.getRSSI(); 
    println("RSSI: " + rssi);  

    // Get total number of samples 
    samples = data.getTotalSamples(); 
    println("Total Samples: " + samples);  

    // Output the Analog readings for each sample  
    // ONLY GETS FIRST SAMPLE - How do I access all 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(""); } 
    } 
}

這一切都按預期工作。 xBeeEvent每2秒調用一次,並輸出API ID,RSSI和Total Samples(19)的正確值。但是,當輸出模擬讀數的內容時,我似乎正在重複19次獲得第一個樣本。看到這個示例輸出:

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次。從TweetA Watt軟件( wattcher.py)運行原始Python腳本輸出XBee數據包的類似讀數,但是具有19個不同的樣本。這是我正在處理的狀態。

在的XBee API庫中,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();時,我只是得到一個「框架」數據的問題。

我也試過直接讀取串行數據包,而無需使用的XBee API庫(參照(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數據包,XBee API庫或讀取處理中的串行數據可以提供幫助,那麼將不勝感激。我期望數據在那裏,我只是不會我意識到這是一個相當具體的問題,我已經將它發佈在Adafruit(TweetA工具包的製造商 - http://forums.adafruit.com/viewtopic.php?f=40&t=16067&sid=4e34727fa59b7c7d589564d2d6b85e46)和Processing(http://processing.org/discourse/yabb2/YaBB.pl?num=1276111549)論壇中,但是在幾十次我沒有看到的觀點之後任何重新所以我想我會把網投得更寬一些。

如果我遺漏了任何有用的信息,請告訴我。在此先感謝您的幫助。

回答