i can't seem to get this figured out, I'm using an esp-01 serial to send data to an Arduino nano with software serial on the nano's side to receive the data, however when I do a comparison against the string sent I cant get the if statement to proceed, even thou the string are the same.
any help is appreciated.
both set to baud 9600
ESP code:
Serial.println("foo");
delay(500);
Arduino Code
#include <SoftwareSerial.h>
SoftwareSerial softSerial(10, 11);
String SendMeData = "foo";
bool gotdata = false;
void setup() {
Serial.begin(115200);
softSerial.begin(9600);
void loop() {
while (gotdata == false) {
if(softSerial.available() > 0){
String datafromESP = softSerial.readStringUntil('\n');
}
if (firstData == SendMeData) Serial.println("Rcd Foo data... do something"); gotdata = true;
//delay(500);
Serial.println("Waiting for ESP");
Serial.println(datafromESP); //debug info
Serial.println(SendMeData); //debug info
}
}
Serial.println("foo");
==>
Serial.print("foo"); //3 ASCII frames are being sent for three characters
Serial.println(); //next 2 ASCII frames are being sent for two charcaters
==>
Serial.print("foo"); //3 frames
Serial.print('\r'); //next 1 frame
Serial.print('\n'); //next 1 frame
So, this code String datafromESP = softSerial.readStringUntil('\n'); at the receiver is saving ASCII codes for four-charcaters as @sterretje has mentioned in his Post-3.
The above flaw could be corrected by the following code or by the code of @sterretje of Post-3. String datafromESP = softSerial.readStringUntil('\r');