asd09
March 6, 2022, 3:01am
1
EDITED:
I want to print this on one line:
cmd = Serial.readString();
if (cmd.indexOf("PASSWORD:") > -1) {
password = cmd.substring(9);
Serial.println(password);
delay(100);
Serial.println("AT+PSWD=" "\"" + password + "\"");
}
but I got this:
10:37:10.796 -> AT+PSWD="1234
10:37:10.796 -> "
What is the problem?
LarryD
March 6, 2022, 3:09am
2
Try:
Serial.print("AT+PSWD=");
Serial.print(password);
Serial.println("’");
Guessing, password contains a linefeed after the number, likely if it was read from the serial input.
asd09
March 6, 2022, 3:32am
4
yes, it was read from the serial. What is the solution for this?
asd09
March 6, 2022, 4:07am
6
The apostrophe is still on the second line
Honestly, I never used Serial.readstring() rather using an input like:
do{
if(Serial.available()>0){
input = Serial.read();
cArray[i]=input;
i++;
}
}while(input != '\r');
Maybe try trimming your password variable:
trim() - Arduino Reference
asd09
March 6, 2022, 4:33am
8
I got an idea from trim.
int passwordlength = cmd.length();
password = cmd.substring(9,passwordlength-2);
Thanks!
asd09:
I got an idea from trim.
As long as you are happy!
Good luck!
Display with Streaming.h macro, it will simply your printing and it is a macro, so no program space is required, all happens with preprocessor.
Ray
asd09:
This:
"AT+PSWD=" "\"" + password + "\""
Is not this, what you meant?
"AT+PSWD=" + "\"" + password + "\""
You left out an operator. +
a7
alto777:
This:
"AT+PSWD=" "\"" + password + "\""
Is not this, what you meant?
"AT+PSWD=" + "\"" + password + "\""
You left out an operator. +
The first relies on the compiler, which will combine the two quoted texts together into a single text. This compiler behavior is convenient when embedding a hex value into a text literal using \x to prevent the subsequent ASCII characters from being interpreted as part of the hex value:
"test \x0A" "feedback" // without the extra quotes the entire next word is taken as part of the hex value
< edit >
Unless you absolutely need to have a single text string, I much prefer just printing each part individually, even with the fastest serial speed the receiving device will never see any difference.
Serial.print("AT+PSWD=\"");
Serial.print(password);
Serial.println("\"");
And I miss printf . Well, I don't, because I found a short easy way to get it back.
But THX for 'splaining the " implicit string literal concatenation", file that under learned something today!
a7
system
Closed
September 2, 2022, 2:21pm
13
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.