ESP8266 serial find char limit

I'm trying to read HTTP POST request that is sent from Android device using ESP's AP mode. The problem is when I send more than 200 chars it starts losing remaining data - which in case the password part. Code is below:

if (esp8266.available()) // check if the esp is sending a message
  {
    if (esp8266.find("+IPD,"))
    {
      delay(1000);
      int connectionId = esp8266.read() - 48;
      Serial.println(connectionId);
      String sip_keyword = "sid=";
      String ssid_keyword = "id=";
      String pw_keyword = "pw=";
      Serial.print(F("freeMemory()="));
      Serial.println(freeMemory());
      char* sip_buffer = (char*) malloc(sizeof(char) * sip_keyword.length() + 1);
      char* ssid_buffer = (char*) malloc(sizeof(char) * ssid_keyword.length() + 1);
      char* pw_buffer = (char*) malloc(sizeof(char) * pw_keyword.length() + 1);
      sip_keyword.toCharArray(sip_buffer, sip_keyword.length() + 1);
      ssid_keyword.toCharArray(ssid_buffer, ssid_keyword.length() + 1);
      pw_keyword.toCharArray(pw_buffer, pw_keyword.length() + 1);
      SERVER_IP = findDataFromESP8266(sip_buffer);
      WIFI_SSID = findDataFromESP8266(ssid_buffer);
      WIFI_PASSWORD = findDataFromESP8266(pw_buffer);
}}

String findDataFromESP8266(char* keyword) {
  String data = "";
  int tempASCII = 0;
  char tempChar = 0;
  boolean check = (tempASCII != 38 && tempASCII != -1 && tempASCII != 32);
  //advance to find wanted keyword.
  if (esp8266.find(keyword) > -1) {
    tempASCII = esp8266.read();
    if (check) {
      while (check) {
        tempChar = tempASCII;
        data += tempChar;
        tempASCII = esp8266.read(); //iterate
        check = (tempASCII != 38 && tempASCII != -1 && tempASCII != 32);
      }
    } else {
      Serial.println(F("SSID empty"));
    }
    Serial.print(F("Data found with keyword "));
    Serial.print(keyword);
    Serial.print(F(": "));
    Serial.println(data);
    delay(200);
  }
  
  return data;
}

is your esp on a hardware of software Serial ? (do you have multiple Hardware serial on your Arduino?)

Assuming you are:

software serial incoming buffer is limited to 64 bytes, hardcoded in the library. if you push bytes too quickly then you will loose content. also at 115200 or even slower, since you do a lot of Serial.print which might block your can overflow your software serial line.

what do you do if if (esp8266.find("+IPD,")) times out?

the next line delay(1000); is probably for you to feel safe about receiving the data but because you have only 64 bytes in the incoming buffer in 1 second you will likely overflow your buffer.

curious about the following lines in findDataFromESP8266

int tempASCII = 0;
...
boolean check = (tempASCII != 38 && tempASCII != -1 && tempASCII != 32);

As you just initialized tempASCII to null, so you could just as well initialize check to true...

You should not implement delays, you should deal with timeout and reading incoming bytes one by one to do your own analysis. always safer bet

Assumption is true. I have an ESP with AT firmware connected to 8,9 digital pins as representation of TX and RX. I’m using SoftwareSerial library printing codes to esp using esp8266 variable.

Can you please explain a work around for this 64 byte buffer thing? I want to read that HTTP GET request fully.

About your curiosity :), its looking for ASCII representation of & char, which is used in HTTP for seperating parameters. The other one is space char. Its initially true but im updating it for each loop if you take a closer look. Thanks in advance!

caneradiyaman6: Can you please explain a work around for this 64 byte buffer thing? I want to read that HTTP GET request fully.

Easy, read the data out faster than it comes in. So ditch the one second delay for sure. See Robin2's Serial Input Basics threads for some good examples of strategies you could use.

caneradiyaman6: About your curiosity :), its looking for ASCII representation of & char, which is used in HTTP for seperating parameters. The other one is space char. Its initially true but im updating it for each loop if you take a closer look. Thanks in advance!

While you may have a variable by that same name in loop, the one that gets created in the first line of this function is the one that if statement will use and it is being created and set to zero every time you call that function. It will never be anything other than zero when that if statement tests it.

The variable check that you create inside this function also does not exist in loop even though you may have another variable by the same name there. Google C++ scope for a better explanation of why this is flawed.

What I mean by my curiosity is that in the code

  int tempASCII = 0;
  char tempChar = 0;
  boolean check = (tempASCII != 38 && tempASCII != -1 && tempASCII != 32);
  //advance to find wanted keyword.
  if (esp8266.find(keyword) > -1) {
    tempASCII = esp8266.read();
    if (check) {
      while (check) {
        tempChar = tempASCII;
        data += tempChar;
        tempASCII = esp8266.read(); //iterate
        check = (tempASCII != 38 && tempASCII != -1 && tempASCII != 32);
      }
    } else {
      Serial.println(F("SSID empty"));
    }

As tempASCII is initialized with 0, check is initialized at every call with true. Then you do a search for your keyword (which might timeout) and you set tempASCII to the next incoming char and test check - but check is always true at that point as this is how you initialized it. So 'SSID empty' message will never occur.

Then you enter the while and add that untested char to the data buffer, read the next one and change only there the value of check (indeed checking against &, space and no input) and loop.

========= While I'm making comments, the whole thing here

      String sip_keyword = "sid=";
      String ssid_keyword = "id=";
      String pw_keyword = "pw=";
      Serial.print(F("freeMemory()="));
      Serial.println(freeMemory());
      char* sip_buffer = (char*) malloc(sizeof(char) * sip_keyword.length() + 1);
      char* ssid_buffer = (char*) malloc(sizeof(char) * ssid_keyword.length() + 1);
      char* pw_buffer = (char*) malloc(sizeof(char) * pw_keyword.length() + 1);
      sip_keyword.toCharArray(sip_buffer, sip_keyword.length() + 1);
      ssid_keyword.toCharArray(ssid_buffer, ssid_keyword.length() + 1);
      pw_keyword.toCharArray(pw_buffer, pw_keyword.length() + 1)

Is weird... Why don't you just do

 char sip_buffer[] = "sid=";
 char ssid_buffer[] = "id=";
 char pw_buffer[] = "pw=";

Seems more efficient, isn't it?