no synchronization between xbee

hello
i have to xbee S2 , one as a coordinator API connected to an arduino and the other a router AT,
my project is about sending a command to the router to light up a led. the coordinator send the data if i clicked a button.
the problem is the router don’t react immediately it takes a while to receive the data.
can anyone help me please
this the code i’am using

int led = 13;
const int bouton = 2;
void setup() {
  // put your setup code here, to run once:
pinMode(led, OUTPUT);
Serial.begin(9600);
pinMode(bouton, INPUT);
}
void loop() {
  // put your main code here, to run repeatedly:
   if(digitalRead(bouton)==HIGH)
  {
    digitalWrite(led,HIGH);
    setRemoteState(0x5);
    delay(500);
  }
     if(digitalRead(bouton)==LOW)
  {
      digitalWrite(led,LOW);
      setRemoteState(0x4);
      delay(500);
  
  }
}
void setRemoteState(char value){
  Serial.write(0x7E); // start byte
  Serial.write((byte)0x0);
  Serial.write(0x10);
  Serial.write(0x17);
  Serial.write((byte)0x0);
  // id of recipient or use 0xFFFF for broadcast
  Serial.write((byte)00);
  Serial.write((byte)00);
  Serial.write((byte)00);
  Serial.write((byte)00);
  Serial.write((byte)00);
  Serial.write((byte)00);
  Serial.write(0xFF);
  Serial.write(0xFF);
  // 16 bit of reciepent 
  Serial.write(0xFF);
  Serial.write(0xFE);  
  
   Serial.write(0x02); 
   
   Serial.write('D');
   Serial.write('2');
   
   Serial.write(value);
   
   long sum = 0x17 + 0xFF + 0xFF + 0xFF + 0xFE + 0x02 + 'D' + '2' + value;
   Serial.write(0xFF - ( sum & 0xFF) );
   Serial.print(sum,HEX);
}
   
   

Frequent broadcasts run into resource limitations on the XBee. Does the system always have delays/lag? Or does it work for the first few button presses and then start with delay/lag?

yes it works for only the first button press and after the second press the delay begins.

no it works in the first time and after that the delay begins

Looking through your code it looks like it will send a broadcast every 500 milliseconds to refresh according to the button state. Definitely too fast so you will need to move to Unicasts or decrease the frequency. Updating code to only send on change might help a little but brings its own issues if a packet is dropped and likewise if you press the button too quickly in sequence.