HM-10 Name error using String

Hello,

I have been trying to edit the HM10 bluetooth device name using a string but it doesn't work.

Using Arduino Mega, hm-10 connected to serial3. Changed baud to 115200.

void setup() {
  Serial.begin(115200);


  Serial3.begin(115200);

  Serial.println("AT+NAME?");
  Serial3.print("AT+NAME?");
  waitForResponse();


  Serial.println("Done!");


}



void loop() {

}
void waitForResponse() {
  delay(1000);
  while (Serial3.available()) {
    Serial.write(Serial3.read());
  }
  Serial.write("\n");
}

The Above code, gives me the Name of the bluetooth. which works great.

String string1 = "\"AT+NAME?\"";

void setup() {
  Serial.begin(115200);


  Serial3.begin(115200);

  Serial.println("AT+NAME?");
  Serial3.print("AT+NAME?");
  waitForResponse();

 Serial.println(string1);
  Serial3.print(string1);
  waitForResponse();



  Serial.println("Done!");


}



void loop() {

}
void waitForResponse() {
  delay(1000);
  while (Serial3.available()) {
    Serial.write(Serial3.read());
  }
  Serial.write("\n");
}

In this case, the AT+NAME? works fine. but the bluetooth doesn't respond to string1.

I have read that the line ending should've be a carriage return so I tried ending the line with \r,\n, and \r\n but nothing worked out.

Has anyone come across this before? what worked for you? I want to be able to send AT commands using string.

If you have any other questions, let me know.

Perhaps you should read the documentation on what Serial.println( ) can take as an argument.

.

It seems to me that you have too much quotation marks.

What happens if you change this:

String string1 = "\"AT+NAME?\"";

to this?

String string1 = "AT+NAME?";

One other thing is that is not a very good idea use the object String. You can use a string and do the same (a string is an array of chars in other hand String is an object). So, you can try to change the above to:

char string1[10] = "AT+NAME?";

Thanks Luisilva,

String string1 = "AT+NAME?"; worked for me.

I don't know why I haven't thought of it before. or maybe I assumed something else.

Anyway. thank you :)