Hi,
I'm learning websockets (trying to make it works without libraries), but I'm having problem with handshake response.
My browser request looks like this:
Provisional headers are shown
Accept-Encoding: gzip, deflate
Accept-Language: pl-PL,pl;q=0.9,en-US;q=0.8,en;q=0.7
Cache-Control: no-cache
Connection: Upgrade
Host: 192.168.0.25
Origin: http://192.168.0.14
Pragma: no-cache
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
Sec-WebSocket-Key: q2vnxYPpBhCBdbMNVNj87A==
Sec-WebSocket-Version: 13
Upgrade: websocket
Arduino/ESP server config via AT commands:
esp8266Data function params are (comman, delay)
String esp8266Data(String command, const int timeout)
{
String response = "";
esp8266Serial.print(command);
long int time = millis();
while ( (time + timeout) > millis())
{
while (esp8266Serial.available())
{
char c = esp8266Serial.read();
response += c;
}
}
Serial.println(response);
return response;
}
esp8266Serial.begin(9600);
esp8266Data("AT+RST\r\n", 3000);
esp8266Data("AT+UART_DEF=9600,8,1,0,0\r\n", 3000);
esp8266Data("AT+CWMODE=1\r\n", 3000);
esp8266Data("AT+CIPMODE=0\r\n", 3000);
esp8266Data("AT+CWJAP=\"myrouter\",\"pass\"\r\n", 3000);
esp8266Data("AT+CIPSTA=\"192.168.0.25\",\"192.168.0.1\",\"255.255.255.0\"\r\n", 3000);
esp8266Data("AT+CIFSR\r\n", 3000);
esp8266Data("AT+CIPMUX=1\r\n", 3000);
esp8266Data("AT+CIPSERVER=1,80\r\n", 3000);
then my arduino generates response like this:
esp8266Data("AT+CIPSEND=0,242\r\n", 200);
//then I generate handshake response which looks like this:
HTTP/1.1 101 Switching Protocols
Accept-Encoding: gzip, deflate
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
Sec-WebSocket-Accept: GJgW3dfoFE77yV4JXD8Xds3criU=
Sec-WebSocket-Version: 13
and now I don't know if I should use "AT+CIPCLOSE=0\r\n" to send this response or it should be received automaticaly with CIPSEND?
The problem is that on my browser it is still pending status like nothing is being sent... any idea what may be wrong? I'm sure Sec-WebSocket-Accept is ok, beacuse I've tested it with other tools.
EDIT
My problem was because I counted length of headers wrong, remember that at the and of headers u need 2x "\r\n" so it knows it's end of headers.