Xbee & Arduino Leonardo

Hi all, i’ve thise issue:
I’m trying to set the communication between Arduino Leonardo and Xbee S1.
I’ve used the following code:

#include<SoftwareSerial.h>
#include<string.h>
String a;
SoftwareSerial mySerial(0, 1); // RX, TX
long boundRate = 9600;
void setup() {
  Serial.begin(boundRate);
  while (!Serial);                        // while not open, do nothing
  Serial1.begin(boundRate);
  mySerial.begin(boundRate);
}

void loop() {
  if(Serial1.available()) {
    /* CODE */
    a = Serial1.readString();
    Serial.println(a);
    Serial1.write("ok");
  }

  if (Serial.available()){
    Serial.println("mando: ");
    a = Serial.readString();  
    //Serial.println(a);
    for (int i = 0; i < a.length(); i++)
     {
       Serial1.write(a[i]);   // Push each char 1 by 1 on each loop pass
     }  

    //mySerial.write(Serial.read());
    
  }
}

The configuration is the fallowing:
I’ve a WaspMote Gateway (Connected through USB) in witch is plugged one Xbee Sensor, and arduino Leonardo in witch is plugged the other Xbee Sensor.
Using XCTU for testing the communication from both the sensor;
Using Arduino IDE for Upload the code.

NOW THE PROBLEM:
When Arduino is connected throgh USB, after uploading the code, it can correctly send and receive data and i can see it form the monitor of the IDE and the console log of xctu.
BUT WHEN I UNPLUG ARDUINO FROM USB IT CANNOT COMMUNICATE MORE!
I’m new with Arduino, and i don’t know if it’s because Serial is only for USB communication.
Any suggests?
Thanks!

I've used the following code:

That's crap. Why are you doing software serial on hardware serial pins?

Why are you trying to use the pins for hardware serial and software serial AT THE SAME TIME?

You are right, I FOUND THIS LINK, and I Solved :slight_smile:
https://learn.sparkfun.com/tutorials/xbee-shield-hookup-guide/example-communication-test