I have four series one xbees in a network. One is set as the coordinator and the other three are end devices. All the configurations to get them to communicate are correct. They are operating at a baud rate of 9600.
Each end device is connected to an RFID scanner (baud rate is 9600) and an Atmega328 chip. When an RFID card is swiped across the scanner, the code is read and 6 bytes are transmitted to the coordinator that is connected to a computer. The coordinator is run by a program written in Processing. This all works just fine. However, when I want to send an array containing all the id's for acceptable cards, I run into problems.
The card list is stored as a 360 byte array on the Atmega chip and as 360 int array on the computer. This is because java only deals in signed bytes and the c code uses unsigned bytes. When I send data to the end device, I just type cast it to a byte.
I don't know why, but I don't think the end device is reading the correct data. I'm doing this in the AT mode for now, but I might switch to the API mode if I can figure it out.
Here is the section of code on the end device that receives the 360 byte list (in c):
int i=0;
while(i<200) { //this is a timeout counter in case things go wrong
delay(100); //used to make blue LED flash slower
digitalWrite(ledBlue, LOW);
if(Serial.available() > 0){ //checks serial port
if(Serial.read() == EXECUTE) { //coordinator xbee saying it is ready to transmit
Serial.write(EXECUTE); //telling coordinator that end device is ready to receive
while(i<360){ //get next 360 bytes from serial
if(Serial.available()>0){ //check serial port
cards[i] = (byte)Serial.read(); //store id data in array
i++; //increment counter
}
}
i=0; //reset counter so it can act as timeout counter
numcards = Serial.read(); //store number of card id's
}
if(Serial.read() == CONTINUE){ //coordinator telling end device to continue normal operation
Serial.write(CONTINUE); //end device confirming command
break; //jump out of loop
}
}
delay(100); //another delay for LED flashing
digitalWrite(ledBlue, HIGH);
i++; //increment timeout counter
}
Here is the coordinator code that transmits the list of id's (in java):
if(send_command(EXECUTE)) { //tells end device to prepare to receive data, continues if end device responds
println("----Update List-----");
for(int j=0; j<360; j++){
if(j%6 == 0) {
print("\n"); //output for testing
ccard = (j/6)+1;
println(" -Card " + ccard + "- ");
}
print(cards[j] + " ");
xbee.write(cards[j]); //sends the id numbers
delay(100);
}
print("\n");
println("--------------------");
println("Current Number of Saved Cards: " + current_number);
xbee.write(current_number); //sends the number of id's
}
}
}
for(int i=1; i<2; i++){
if(connected[i-1]){ //ignore this for now
connect_to_door(i); //this makes sure it transmits to the correct end device
send_command(RESUME); //tells end device to continue normal operation
}
}
Any thoughts?