Getting XBee MAC ADDRESS

Hello guys,

The problem that i have i that I want to get the XBee Mac Address, and i’ve already got it but it works like a loop, I just want to get once the mac address but it seems to be obtaining it in a loop, by the way my function is at the setup code. I hope someone could help me please. Greetings and regards.

String MAC_ADDRESS = "", _MAC_ADDRESS = "", MAC = ""; 
int i = 0; 
boolean StringComplete = false; 

void setup() 
{
  Serial.begin(115200);  
  XBeeBegin("0x40C541F3");   
  Serial.println(MAC_ADDRESS); 
}

void loop() 
{
  int a = 1; 
  int b = 2; 

  Serial.println(a+b); 
  delay(1500); 
}

void XBeeBegin ( String destiny_address )
{
  if ( (MAC_ADDRESS.length() < 8) && i == 0 )
  {
    XBee_ATMode ( destiny_address );  
  }
}

void XBee_ATMode ( String destiny_address )
{
  unsigned long Time = millis(); 
  
  Serial1.begin(115200); 
  Serial1.flush(); 
  delay(1500); 

  Serial1.print("+++"); 
  
  delay(1500); 

  Serial1.print("ATDH 0x0013A200\r"); 
  Serial1.print("ATDL " + destiny_address + "\r"); 
  Serial1.print("ATSL\r");
   
  delay(100); 

  if ( Serial1.available() )
  {
    delay(50); 
    MAC_ADDRESS = Serial1.readString(); 

    while ( MAC_ADDRESS.indexOf('K') > 0 )
    {
      MAC_ADDRESS.remove( 0,MAC_ADDRESS.indexOf('K') + 1 ); 
    }
  } 
  Serial1.print("ATWR\r"); 
  Serial1.print("ATCN\r"); 
  MAC_ADDRESS = MAC_ADDRESS.substring(1,9); 
  Serial1.end(); 
}

There is a much easier way to do this with the XCTU utility. You can download it from Digi.