0

I've been trying to send data from coordinator XBee to Xbee in router AT mode. It works.

However there is too much delay at an unacceptable duration. How to solve the delay problem?

int led = 0;
int ledX = 13;
int pin = 5;
int bs;
String store[20];
void setup() {
 pinMode(led,OUTPUT);
 pinMode(pin,INPUT);
Serial.begin(9600);
}

void loop() {
 // bs = digitalRead(5);
  //if(bs == LOW){
  digitalWrite(led,HIGH);
  setRemoteState(0x05);
  delay(1000);

  //}
  //else if(bs == HIGH){
  digitalWrite(led,LOW );
  setRemoteState(0x04);
  delay(1000);
  //}

}
void setRemoteState(char value){
Serial.write(0x7E); //start of the frame
Serial.write((byte)0); // byte length
Serial.write(0x10); //high part 16 in decimal
Serial.write(0x17); // AT command request
Serial.write((byte)0); // frame ID dont need any ack
Serial.write((byte)0);
Serial.write((byte)0);
Serial.write((byte)0);
Serial.write((byte)0);
Serial.write((byte)0);
Serial.write((byte)0);
Serial.write(0xFF);
Serial.write(0xFF);

Serial.write(0xFF);
Serial.write(0xFE);

Serial.write(0x02); 

Serial.write('D');
Serial.write('3'); //change pin D3

Serial.write(value);

long sum = 0x17 + 0xFF + 0xFF + 0xFF + 0xFE + 0x02 + 'D' + '3' + value;
Serial.write(0xFF - (sum &0xFF) );

}

Above is my code that i have implemented inside my arduino

1 Answers1

0

How much delay are you seeing? After you transmit the last byte into the coordinator, how many milliseconds elapse before you see data on the router?

What's an acceptable level? This is low-speed (250kbps) radio network which may need to bounce your message across multiple nodes. Expecting latency under 100ms is probably unrealistic.

If you're running the XBee modules at 9600 baud, increase the baud rate to 115200bps to reduce the time spent sending into one XBee and receiving on the other.

tomlogic
  • 11,489
  • 3
  • 33
  • 59
  • delay is up to 10s which is unreasonable. I have changed the baud rate to 115200 but still no improvement, i've also upload my code, can you tell by looking at it ? – Muhammad Jan 11 '17 at 20:35
  • You're sending broadcast messages (address 0x000000000000FFFF), and will be better off using the router's MAC address. Also, you're sending every second even if the input hasn't changed. Keep track of the I/O state and only transmit when it changes. That will definitely help. – tomlogic Jan 12 '17 at 22:22