Post topics, source code that relate to the Arduino Platform

User avatar
By Barak BN
#33403 Hey all,

I'm having problems with the flow of responding to a request. The ESP is connected to an arduino, and the setup is as follow: AP (mode 1) and multiple connections.

When I'm getting a request from a browser, I receive the channel id. But when I send back the header and the content, the browser receives it after about 7 seconds, and prints both the content and the header, which means I have some problem with my flow and closing the connection.

My code:
Code: Select allvoid homepage(int ch_id) {
  Serial.print(" Channel ID:  ");
  Serial.println(ch_id);

  String Header;
  Header =  "";
  Header += "Content-Type: text/html\r\n";
  Header += "Connection: close\r\n"; 
  Header += "Content-Length: ";
  //Header += "Refresh: 5\r\n";

  String Content;
  Content = "<html> <body> Hello!</body></html>";

  Header += (int)(Content.length());
  Header += "\r\n\r\n";
 
  espSerial.print("AT+CIPSEND=");
  espSerial.print(ch_id);
  espSerial.print(",");
  espSerial.println(Header.length()+Content.length());

  while (espSerial.available() > 0 )  {
    char c = espSerial.read();
  }

 if (espSerial.find(">")) {
    Serial.println(">"); 
    espSerial.print(Header);
   
    espSerial.println(Content);
    Serial.println("...");

    espSerial.println("AT+CIPCLOSE=""\ch_id\"");
    clearSerialBuffer();
    clearBuffer();
  } 


}


I'm working with some old piece of code I found about a year ago. If you have something more up to date please inform me :)

Thank you!