Could someone explain this code that sets up the software serial port data rate? I understand most of it. The part I don't understand is the is the code in for void loop. How does that set the data rate for the software serial port? I thought mySerial.begin(9600) did that? Please help.

#include &lt;SoftwareSerial.h&gt;

SoftwareSerial mySerial(2, 3); // RX, TX

void setup()
{
    // Open serial communications and wait for port to open:
    Serial.begin(9600);
    while (!Serial) {
        ; // wait for serial port to connect. Needed for Leonardo only
    }


    Serial.println("Goodnight moon!");

    // set the data rate for the SoftwareSerial port
    mySerial.begin(9600);
    // set master
    mySerial.print("AT+ROLE1");
    delay(10000);


}

void loop() // run over and over
{

    // set the data rate for the SoftwareSerial port
    mySerial.print("test I am master  ");
    delay(10000);
    ***if (mySerial.available())
    Serial.write(mySerial.read());
    if (Serial.available())
    mySerial.write(Serial.read());***
}
You're confusing "data rate" with "baud rate".

The baud rate is the speed at which bytes are transmitted over the wires, and is set with mySerial.begin(9600);.

The data rate is the speed at which data is sent over the serial port, and that is set by the delay(10000); which dictates how often "test I am master  " is sent and any incoming data is checked for and echoed.