I am working on an RFID system that uses four series 1 xbees. For each of the three doors there is a circuit board with an Atmega 328 chip and an xbee set as an end device. For the “server” there is one xbee linked wired to a serial port connecter of the server PC and it is set as a coordinator. Each xbee uses the xbee adapter from Adafruit. The baud rates of each xbee are set to 9600 and the guard times are the standard 1s.
The client code for each door is written in C for Arduino (I am using the Duemilanove) and the server code is written in java for Processing. Both sets of code compile and run fine. However, when I test the code (server and 1 client) the Update_Data and Add_Card functions work some of the time (at random I think).
The xbee communication works like this:
- AT commands are used to switch the server’s ATDL to the correct client (ATMY 1-3).
- The server sends an command coded as an int (1-4) to the client.
- The client sends the command back to the server as an acknowledgment.
- The server waits roughly three seconds for the acknowledgement and exits if it does not receive it.
- The command is executed on the client side
The program outputs information to the screen letting me know if the function worked, timed out, etc. The thing I cannot figure out is why communication times out sometimes and works other times.
That is my main concern. I also am wondering how reducing guard times and would affect this problem (quicker would be preferred).
My final question relates to serial communication. I want to keep the scanned card data (transferred to the Atmega chip via softserial, then to the server xbee, and back to the client xbee for updates) as serial data. I used type casting to keep xbee.read() as bytes, but I think that there is an issue there as well.
I would be very grateful if anyone knows the answers to any of these problems.
RFID_door_client.pde (5.49 KB)
RFID_Server.pde (11.1 KB)