Using the new Arduino IDE for ESP8266 and found bugs, report them here

Moderator: igrr

User avatar
By cnwesleywang
#33230 hi there, sorry for my pool english.

I don't know what the problem is but if we do not create WiFiClient for every request just like the example doing, then we can not get continues response from the TCP Server.

for example:

Code: Select all#include <ESP8266WiFi.h>

const char* ssid     = "team";
const char* password = "team";

const char* host = "192.168.31.113";

WiFiClient client;
void setup() {
  Serial.begin(115200);
  delay(10);

  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
 
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected"); 
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

}

int value = 0;

void loop() {
  delay(1000);
  ++value;

  if (!client.connected()){
    Serial.print("connecting to ");
    Serial.println(host);
    // Use WiFiClient class to create TCP connections
    const int httpPort = 1234;
    if (!client.connect(host, httpPort)) {
      Serial.println("connection failed");
      return;
    }
  }
 
  // This will send the request to the server
  //client.write("\xFE\xEF\x0E\xE2\x06\xDB\x48\xB4\xB0\x04\x00\xA2\x00\x04\x16\x1C\xB4",17);
  client.write("hello\r\n");
  client.flush();
  delay(500);
 
  // Read all the lines of the reply from server and print them to Serial
  while(client.available()){
    //String line = client.readStringUntil('\r');
    Serial.print(client.read(),HEX);
    Serial.print(" ");
  }
 
  Serial.println();
  Serial.println("closing connection");
 
}



if we use other program like python, everything responses well,so server side should be ok, but if we change to ESP 12-E board as TCP client, and use the code above, the response come randomly. it seem the 80% response has been lost, mean while the server side gives all the response successfully return.

what can be the problem?

thanks.
User avatar
By igrr
#33273 client.flush() discards all data present in RX buffer. This is why you are loosing parts of the reply.

This is different from HardwareSerial class where flush causes all TX data to be transmitted.

This is documented in Arduino WiFi library docs here: https://www.arduino.cc/en/Reference/WiFiClientFlush
User avatar
By cnwesleywang
#33315 hi igrr:

thank you for the so soon reply, and as you said, remove client.flush() resolved the problem.

without client.flush, when sending hex binary data, the server side receive nothing, so I add client.flush() and server side could receive data correctly.

after remove client.flush() I add client.setNoDelay(), now sending and receiving both works fine.

thanks again,great job!
User avatar
By ravi
#44518 i have an issue esp8266 generic wifi module
if i use client.write(&a[0],10); to sent 10 byte array elements, it will send only one time to the server but not continuously , what should i do so that i can send continuously

please help me for this issue ,Thanks -