Connection Close Problem
Posted: Sat Nov 07, 2015 9:21 pm
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:
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!
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 all
void 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!