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:

SoftwareSerial esp (8,9);

   void setup()
   delay(100); }

The string "bbb" is recieved on the server and the server responds back, which is shown in the serial monitor as:

+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:

String buffer="";
while (esp.available()>0) 
    buffer+= esp.readString();   

2nd by using esp.read() as shown below:

String buffer="";
char c;
while (esp.available()>0) {
    c= esp.read();
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:

busy s...

Recv 3 bytes


+IPD,19:the string

I can not get the entire response in the buffer as mentioned in the start. 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 between the two. Lastly i have also used esp.readBytes() as shown:

char c[500];

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.

  • A while(Serial.available()>0) does not guarantee, that all bytes have been received. Sometimes there is a small delay between bytes, which you cannot control. The Arduino will exit the while loop, but short after that, more bytes are received, without the program ḱnowing. Somehow your Arduino has to know, when the message is complete (through a delimiter character or maybe a timeout). – chrisl Apr 15 '18 at 15:21
  • @chrisl i have also tried this using a for loop like so: esp.println("bbb"); delay(100); char c[100]; for(int i=0;i<80;i++){ c[i]= esp.read(); delay(10); Serial.write(c[i]); } Which gives me the following output: busy s... Recv 3 bytes SEND OK +IPD,19:the string⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮ I assumed after this that the buffer must be empty thats why the reverse question marks appeared. I still have no clue on what to do next – simsam Apr 15 '18 at 15:40
  • The reverse question marks depict a character, that has no meaning in ASCII, e.g. a value greater than 127. The read() function returns -1, when the buffer is empty, which translates to an unsigned value of 255. So you are right, that the buffer is empty there. That is strange. How many bytes do you receive correctly with this method? – chrisl Apr 15 '18 at 15:53
  • @chrisl When i run the command AT+CWLAP i can get upto 400B in the buffer variable. But in the commands that receive a response from the server i.e. i use AT+CIPSEND and my sever sends a response which includes +IPD i can only get max 64B. I have shown this in the original question. I dont understand why this is happening because i have used the same reading technique for both commands – simsam Apr 15 '18 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.