Reading +IPD response from serial.read() using Arduino UNO
Posted: Tue Apr 24, 2018 4:19 am
I have a python server running on my PC and I am using an Arduino Uno (wifi enabled by a ESP8266 chip) as the client.I can make the the server and client communicate using AT commands as shown below:
The string "bbb" is recieved on the server and the server responds back, which is shown in the serial monitor as:
I want to read this response and use it back in the code for further conditional statements. But i am unable to do this. So far i have tried these methods.
1st method by using esp.readString() as shown below:
2nd by using esp.read() as shown below:
These two methods returned with incomplete information in the response string buffer ie i only get:
I can not get the entire response in the buffer as mentioned in the start i.e the string is/isnt found. On the other hand if i execute the command AT+CWLAP and store its response in the buffer string, i get the entire thing. So i cant understand why is there a difference storing these two response using the same technique.
Lastly i have also used esp.readBytes() as shown:
This code gives me the whole response sometimes but sometimes it just gives a long garbage value. But the times it does give me the complete +IPD response, it switches some of the alphabets ie `the string is found` becomes `the strjng is gound`
If anyone could help me out i'll be very thankful.
Code: Select all
SoftwareSerial esp (8,9);
void setup()
{
esp.begin(9600);
esp.println("AT+CWMODE=3");
delay(100);
esp.println("AT+CIPSTART=\"TCP\",\"192.168.8.100\",5555");
delay(1000);
esp.println("AT+CIPSEND=3");
delay(100);
esp.println("bbb");
delay(100); }
The string "bbb" is recieved on the server and the server responds back, which is shown in the serial monitor as:
Code: Select all
+IPD,19:the string is found
I want to read this response and use it back in the code for further conditional statements. But i am unable to do this. So far i have tried these methods.
1st method by using esp.readString() as shown below:
Code: Select all
String buffer="";
while (esp.available()>0)
buffer+= esp.readString();
Serial.print(buffer);
2nd by using esp.read() as shown below:
Code: Select all
String buffer="";
char c;
while (esp.available()>0) {
c= esp.read();
buffer+=c;}
Serial.print(buffer); // i have also tried using esp.write() directly for prinitng here intead of storing it in a buffer
These two methods returned with incomplete information in the response string buffer ie i only get:
Code: Select all
busy s...
Recv 3 bytes
SEND OK
+IPD,19:the string
I can not get the entire response in the buffer as mentioned in the start i.e the string is/isnt found. On the other hand if i execute the command AT+CWLAP and store its response in the buffer string, i get the entire thing. So i cant understand why is there a difference storing these two response using the same technique.
Lastly i have also used esp.readBytes() as shown:
Code: Select all
char c[500];
esp.readBytes(c,400);
esp.write(c);
This code gives me the whole response sometimes but sometimes it just gives a long garbage value. But the times it does give me the complete +IPD response, it switches some of the alphabets ie `the string is found` becomes `the strjng is gound`
If anyone could help me out i'll be very thankful.