Hi,
Hardware: an esp8266 12S that is attached to an Arduino Uno, (actually an Elecrow espduino). Software Arduino IDE 1.8.10 on a Linux box.
I am trying to read data adding them to a string. Funny thing is that the esp8266 keeps emitting characters, but that after a few dozen or so characters they are not added to the string any more.
If the function below is called with e.g. debug=3, I see characters coming in as expected, but the string response stops growing after 40 bytes.
This behaviour is erratic in that in some sketches the function works fine, but in other sketches not. I tried all kinds of delays, both as 'delay(xxx)' and as a parameter to te function, but no luck.
It does not seem to be memory related. The output from the compiler says: Sketch uses 17110 bytes (53%) of program storage space. Maximum is 32256 bytes.
Global variables use 1348 bytes (65%) of dynamic memory, leaving 700 bytes for local variables. Maximum is 2048 bytes.
I really am beating my head to the wall now.
String sendData(String command, long timeout, int debug)
{
// debug=0 : geen output
// debug=1 : alleen commando
// debug=2 : commando en output
long int timein = millis();
String response;
char ch;
int t=0,x;
if (debug>0) {Serial.print("command ");Serial.println(command);}
esp8266.println(command); // send the command to the esp8266
response = "";
while( (timein+timeout) > millis())
{
while(esp8266.available())
{
// The esp has data so display its output to the serial window
ch = esp8266.read(); // read the next character.
Serial.print(ch);
t++;
if (int(ch)>31) response.concat(ch);else response.concat(" ");
if (debug==3)
{
Serial.print(" ");
Serial.print(t); Serial.print(" - ");
Serial.print(int(ch));Serial.print(" ");Serial.print(response.length());
Serial.print(" ");Serial.println(response);
}
}
}
if (debug>1)
{
Serial.print("response: ");Serial.println(response);
Serial.print("bytes read: ");Serial.println(t);
}
return response;
}