It's been some time since my last post so in order to pick up from where I left off here's a very brief overview of the cutdown version of the software used to communicate with the remote XBee with the TMP36 temperature sensor. The software code to which it refers can be found here.
It doesn't explain the intricacies of the object hierarchy being used to communicate with the XBee although this is important. This documentation can be found here. In brief there is an object class called Xbee which is used to communicate with the Xbee module. Then there are a set of classes that model the data packets returned by the XBee. The classes are often hierarchical and designed to make it possible to drill down into the returned data.
And so to overview of the software code.
Tell the compiler where to find the software classes referenced in this program. (import statements)
Create an object that represents an XBee module.(XBee xbee = new XBee();)
Display a window to communicate through. (although logging is output to the console as well).
Create a font.
Setup the logging and output to the console.
Open the serial port to the Xbee connected to the computer that will communicate with the remote battery powered XBee. (xbee.open(mySerialPort, 9600);)
Put a grey background on the window
Create an object to store the data returned from the XBee and the address of the sending XBee. (SensorData data = new SensorData();)
Wait for a response from the XBee connected to the computer.(XBeeResponse response = xbee.getResponse();)
Check the response is a packet carrying data from a remote XBee.(if (response.getApiId() == ApiId.ZNET_IO_SAMPLE_RESPONSE && !response.isError()))
Get the address and save it.(int[] addressArray = ioSample.getRemoteAddress64().getAddress();)
Get the data and save it.(value = ioSample.getAnalog0();)
Convert the voltage measured by the remote XBee from the TMP36 into a temperature.(float temperatureCelsius = (data.value-500)/10;
)
Go back to waiting for a response and do it all again.
No comments:
Post a Comment