Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP8266 not connecting to socket #23

Open
shahimclt opened this issue Aug 12, 2016 · 7 comments
Open

ESP8266 not connecting to socket #23

shahimclt opened this issue Aug 12, 2016 · 7 comments

Comments

@shahimclt
Copy link

I'm not sure if my issue is the same as #22 , so I'm creating a new one.

This is my log when I try to connect to NodeJS server from ESP8266:

HTTP/1.1 200 OK
97:0{"sid":"TvbbAMyWh9dUUakzAAAB","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000}
Connected. SID=TvbbAMyWh9dUUakzAAAB
Connecting via Websocket`

This just sits there and doesn't recieve a 101 response.

Here is my server side log when connecting from ESP :

engine intercepting request for path "/socket.io/" +2m
engine handling "GET" http request "/socket.io/1/?transport=polling&b64=true" +0ms  
engine handshaking client "ewG8sx4FXkVoZ3bgAAAC" +2ms  
engine:socket sending packet "open" ({"sid":"ewG8sx4FXkVoZ3bgAAAC","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000}) +0ms
engine:polling setting request +0ms
engine:socket flushing buffer to transport +0ms
engine:polling writing "97:0{"sid":"ewG8sx4FXkVoZ3bgAAAC","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000}" +0ms
engine:socket executing batch send callback +1ms
socket.io:server incoming connection with id ewG8sx4FXkVoZ3bgAAAC +0ms
socket.io:client connecting to namespace / +0ms
socket.io:namespace adding socket to nsp / +0ms
socket.io:socket socket connected - writing packet +0ms
socket.io:socket joining room /#ewG8sx4FXkVoZ3bgAAAC +1ms
socket.io:client writing packet {"type":0,"nsp":"/"} +0ms
socket.io-parser encoding packet {"type":0,"nsp":"/"} +0ms
socket.io-parser encoded {"type":0,"nsp":"/"} as 0 +0ms
engine:socket sending packet "message" (0) +0ms
[12/08/2016 13:23:19.960] [LOG]   connected
[12/08/2016 13:23:19.960] [LOG]   /#ewG8sx4FXkVoZ3bgAAAC
socket.io:socket joined room /#ewG8sx4FXkVoZ3bgAAAC +0ms
engine:polling closing +1m
engine:polling transport not writable - buffering orderly close +0ms
socket.io:client client close with reason ping timeout +1ms
socket.io:socket closing socket - reason ping timeout +0ms
[12/08/2016 13:24:44.959] [LOG]   DISCONNECTING!!!

But I am able to connect without issues from a browser client :

engine intercepting request for path "/socket.io/" +17s
engine handling "GET" http request "/socket.io/?EIO=3&transport=polling&t=1471007843270-0" +0ms
engine handshaking client "OMCzE_KVRlXRCZiFAAAA" +2ms
engine:socket sending packet "open" ({"sid":"OMCzE_KVRlXRCZiFAAAA","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000}) +1ms
engine:polling setting request +0ms
engine:socket flushing buffer to transport +1ms
engine:polling writing "      �0{"sid":"OMCzE_KVRlXRCZiFAAAA","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000}" +1ms
 engine:socket executing batch send callback +2ms
socket.io:server incoming connection with id OMCzE_KVRlXRCZiFAAAA +0ms
socket.io:client connecting to namespace / +0ms
socket.io:namespace adding socket to nsp / +0ms
socket.io:socket socket connected - writing packet +1ms
socket.io:socket joining room /#OMCzE_KVRlXRCZiFAAAA +0ms
socket.io:client writing packet {"type":0,"nsp":"/"} +1ms
socket.io-parser encoding packet {"type":0,"nsp":"/"} +0ms
socket.io-parser encoded {"type":0,"nsp":"/"} as 0 +0ms
engine:socket sending packet "message" (0) +0ms
[12/08/2016 13:17:27.876] [LOG]   connected
[12/08/2016 13:17:27.876] [LOG]   /#OMCzE_KVRlXRCZiFAAAA
socket.io:socket joined room /#OMCzE_KVRlXRCZiFAAAA +1ms
engine intercepting request for path "/socket.io/" +332ms
engine handling "GET" http request "/socket.io/?EIO=3&transport=polling&t=1471007843931-1&sid=OMCzE_KVRlXRCZiFAAAA" +0ms
engine setting new request for existing client +0ms
engine:polling setting request +0ms
engine:socket flushing buffer to transport +0ms
engine:polling writing "�40" +0ms
engine:socket executing batch send callback +1ms
engine upgrading existing transport +327ms
engine:socket might upgrade socket transport from "polling" to "websocket" +0ms
engine:ws received "2probe" +319ms
engine:ws writing "3probe" +0ms
engine:ws received "5" +843ms
engine:socket got upgrade packet - upgrading +0ms
engine:polling closing +1ms
engine:polling transport discarded - closing right away +0ms

engine:ws received "2" +23s
engine:socket packet +0ms
engine:socket got ping +0ms
engine:socket sending packet "pong" (undefined) +0ms
engine:socket flushing buffer to transport +0ms
engine:ws writing "3" +0ms

Any ideas as to what might be the issue??

@shahimclt
Copy link
Author

P.S I dont have this issue in local server. Only when using AWS Server.

@shahimclt
Copy link
Author

On digging into the code, it seems like the client.print() calls are taking too long to execute. The server "ping timeout"s in 60 seconds but the ESP takes nearly 2 minutes to complete the TCP upgrade request :

Serial.println(F("Connecting via Websocket"));
client.print(F("GET /socket.io/1/websocket/?transport=websocket&b64=true&sid="));
client.print(sid);
client.print(F(" HTTP/1.1\r\n"));
client.print(F("Host: "));
client.print(hostname);
client.print("\r\n");
client.print(F("Origin: ArduinoSocketIOClient\r\n"));
client.print(F("Sec-WebSocket-Key: "));
client.print(sid);
client.print("\r\n");
client.print(F("Sec-WebSocket-Version: 13\r\n"));
client.print(F("Upgrade: websocket\r\n"));  // must be camelcase ?!
client.println(F("Connection: Upgrade\r\n"));

@washo4evr
Copy link
Owner

I never tried with AWS, I need to check it out
Im glad it is working in local, the issue should be easier to fix

@shahimclt
Copy link
Author

Don't know what is going on, but when I removed all the F( ) inside client.print( ), the code executes much faster. maybe it is related to ESP8266 WifiClient?

@washo4evr
Copy link
Owner

what version of arduino IDE do you use?
and what package for ESP8266?

@washo4evr
Copy link
Owner

you may also try to remove all the Serial (no debugging, but could help with the speed)

@HudsonProdigy
Copy link

I am also having this am issue. Was this ever resolved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants