Hi, I am currently working on developing an intelligent car park sysem for my final year project using Wireless Sensor Networks (WSN).
On one end I have the Arduino+XBee Shield+XBee powered by a 9V adapter. 6 ultrasonic sensors are connected to Arduino, and sensor data will be sent wirelessly to a computer using an XBee connected via USB on the computer.
What I would like to do now is to have the data displayed on the X-CTU on the receiver end of the XBee (the one connected to the computer) to be sent to the Microsoft SQL database. However, I have searched all over the internet and could not find any relevant answers.
The XBee will appear as a virtual serial port on the system. You can write an application in a language of your choice that opens up the serial port and reads the incoming data. Your application should receive the same data you were previously seeing in the X-CTU terminal. It can then parse the data and store it however it wants in the SQL Server.
As cpopp stated, you don’t need to read from X-CTU, you should read from the Serial Port where your X-Stick is. Once you achieve this in your program, you will read binary data in the same format you see in X-CTU.
The data output format will depend on how you configure your X-Stick (API or AT, refer to Reference Manual on how to parse them). I suppose that your application will receive data from more than one device, so AT will not be enough, but you can start with that as it is easier to parse (again, refer to the Ref Manual).
Hope it was helpful. Best regards,
P/S: The programming language makes no difference, as long as you can open the serial port. This may help you getting started if you prefer Processing, but you can do it as well in C/C++, Python, Java, etc.
I have done programming successfully on Processing to read data from the Serial Port where my XBee is connected, and it is now able to read the data as how it would using the X-CTU.
Now that I have that done, I still do not understand how I could parse the XBee in order for it to be able to store the data on MS SQL. I tried searching the internet but could not find information that I could comprehend.
If there is no XBee library for Processing you will have to build your own parser. If you only want to receive frames from other XBees, implementing ZigBee Receive Packet frames (Frame Type 0x90) should be enough for start, consult Reference Manual to know its structure so you can guess the data offset.
There is XBee library for Processing, but how can I parse the data so that it can be saved on MS SQL? Do I program it on Processing, or do I configure XBee? How do I implement ZigBee Receive Packet frames? I’m still trying to understand how to parse.
As Sebastian said, once you have the binary data you will have to parse it byte a byte. To know how to do it you will have to refer to the XBee Reference Manual. As an example:
All XBee API packets start with byte 0x7E, this is the header of the frame. You will know where is the start of the packet by identifying this byte inside your binary data array.
Following the packet header, next 2 bytes will be the payload length, so you will have to read that ammount of bytes to get the complete payload. For example if you read 0x00 0x0a means that the payload size is 10 bytes and you will have to read the following 10 bytes to get the payload.
This data depends on the type of packet that is received. Inside the payload, first byte determines the packet type. In your case, you will have to wait for Frame type 0x90 (which is the ZigBee Receive Packet type). Next 8 bytes determine the 64 bit address of the XBee device that sent the packet. Next 2 bytes are the 16 bit address of the XBee device that sent the packet. Next byte is a bitfield with the receive options flags. And now, the rest of the bytes until payload is complete will be the data you really want (the data that is transmitted from the other XBee device).
To finish, the last byte after the payload is the packet checksum.
There are a lot more of details to take in consideration, but as an start you can follow that pattern.