Hello,
I use the ESP8266 device to communicate over Wifi to my HTTP server.
It's all right when I send data to the ESP8266 (the command "AT+CIFSR"), but I've a problem when I try to read data.
First try:
String sendData1(SoftwareSerial *serial, String dataChar, int delayWait, char* findReponseString){
String response = "";
serial->println(dataChar);
long int time = millis();
while((time+delayWait) > millis()){
while(serial->available()) {
char r = serial->read();
if (r == '\n') {
} else if(r == '\r') {
} else {
response += r;
}
delay(100);
}
}
return response;
}
The usage of "serial->read();" causes corrupted data.
I can read in the serial monitor this String:
+CIFSR:STAMAC,"5c:cf:7f:10:d6:ab"
And I get this String with the function "sendData1":
+CIFSR:STAM@�,"5c:cf:7f
(and nothing else after)
Second try:
String sendData2(SoftwareSerial *serial, String dataChar, int delayWait, char* findReponseString){
String response = "";
serial->println(dataChar);
long int time = millis();
while((time+delayWait) > millis()){
while(serial->available()) {
String part = serial->readString();
response += part;
delay(100);
}
}
return response;
}
Here, the usage of "serial->readString();" is a little bit better.
I can read in the serial monitor this String:
+CIFSR:STAMAC,"5c:cf:7f:10:d6:ab"
And I get this String with the function "sendData2":
+CIFSR:STAMAC,"5c:cf;7f:16
There is a ";" replacing the ":" character and there is not the full string that I read in the serial monitor.
So my question is: How to read data from the ESP8266 ?
Thanks for helping.