harlequin-tech / WiFlyHQ

WiFly RN-XV Arduino Library
Other
110 stars 68 forks source link

WebSocket Example Not Working #8

Closed jonmarkgo closed 12 years ago

jonmarkgo commented 12 years ago

Already joined network open echo.websocket.org 80 connect: handshake failed close: failed, no CLOS Failed to connect to echo.websocket.org Terminal ready

OPENCLOSOPENCLOSOPENCLOSOPENCLOSOPENCLOSOPENCLOSOPENCLOSOPENCLOSOPENCLOSOPENCLOSOPENCLOSOPENCLOSOPENCLOSOPEN

I know its establishing the connection since I've monitored the TCP and tried it with my own server, but the handshake seems to fail... The only change I made to the example is swapping Serial and wifiSerial (along with all the println stuff)

harlequin-tech commented 12 years ago

Can you post your modified sketch? I'll try out out and see what is going on.

jonmarkgo commented 12 years ago

https://gist.github.com/3213165

harlequin-tech commented 12 years ago

Thanks. It will be few days before I can test this.

Are you using a recent version of firmware on the WiFly? (E.g. 2.32 or newer?).

jonmarkgo commented 12 years ago

Yup , its a brand new wifly rn-xv

harlequin-tech commented 12 years ago

Looking at the output you are getting, its strange to see the "open echo.websocket.org 80" command in the serial output. This is meant to go to the WiFly module, not the serial monitor. Do you have a separate serial to usb convertor for the soft serial interface?

Would you mind describing your hardware setup and how its configured to connect through to the WiFly module? (Which shield you're using, what the jumper / switch settings are, etc).

jonmarkgo commented 12 years ago

Arduino Uno SMD (https://www.sparkfun.com/products/11224) with Arduino Wireless SD Shield (http://arduino.cc/en/Main/ArduinoWirelessShield) and the RN-XV (https://www.sparkfun.com/products/10822), switch on the shield is to micro, not USB. I have the TX and RX from this FTDI->USB cable (https://www.sparkfun.com/products/9717) wired up to pin 2 and 3 on the shield for SoftwareSerial output.

harlequin-tech commented 12 years ago

Okay that looks fine, and I found the debug code that echos the open command to the debug serial interface so the output is ok.

I'm not sure why its having problems - will have to wait to try it out on my board.

One thing to check would be that you can enter command mode when the terminal starts (send $$$ on your debug serial port and you should get the WiFly command prompt). You can then try to connect to the server by sending the "open echo.websocket.org 80" command and seeing if you get an "OPEN" response.

jonmarkgo commented 12 years ago

Yeah I tried that both directly connected to the wifly and via your terminal code and both worked as expected. As far as I can tell its connecting and sending its data but not receiving the response properly

jonmarkgo commented 12 years ago

I just tried testing it with a basic node.js server that listened on a TCP port and piped all input to stdout. Got this serial monitor output: Already joined network open jonsplanet.com 1337 connect: handshake failed close: got CLOS Failed to connect to jonsplanet.com Terminal ready OPEN

And this server output: $ node power.js Server listening on localhost port 1337 Client connection created GET / HTTP/1.1 Upgrade: WebSocket Connection: Upgrade Host: j

onsplanet.com Origin: http://www.websocket.org

Client connection disconnected

I'm not sure why the Host is split on 2 lines - could very well be an issue with my node script. Either way, seems to be correct....

harlequin-tech commented 12 years ago

You could use the dbgBegin() and dbgDump() calls to get a dump of the serial comms between the AVR and the WiFly module. E.g. in the connect() function, add a call to wifly.dbgBegin() before the wifly.open() call and add a call to wifly.dbgDump() before the wifly.close(). That might provide some clues as to what is happening.

jonmarkgo commented 12 years ago

Already joined network close: got CLOS open echo.websocket.org 80 connect: handshake failed debug dump 0: 24 $ 1: 24 $ 2: 24 $ 3: 43 C 4: 4D M 5: 44 D 6: D 7: A 8: 63 c 9: 6C l 10: 6F o 11: 73 s 12: 65 e 13: D 14: 3C < 15: 32 2 16: 2E . 17: 33 3 18: 32 2 19: 3E > 20: 20
21: D 22: A 23: 2A 24: 43 C 25: 4C L 26: 4F O 27: 53 S 28: 2A 29: 6F o 30: 70 p 31: 65 e 32: 6E n 33: 20
34: 65 e 35: 63 c 36: 68 h 37: 6F o 38: 2E . 39: 77 w 40: 65 e 41: 62 b 42: 73 s 43: 6F o 44: 63 c 45: 6B k 46: 65 e 47: 74 t 48: 2E . 49: 6F o 50: 72 r 51: 67 g 52: 20
53: 38 8 54: 30 0 55: D 56: 3C < 57: 32 2 58: 2E . 59: 33 3 60: 32 2 61: 3E > 62: 20
63: D 64: A 65: 2A 66: 4F O 67: 50 P 68: 45 E 69: 4E N 70: 2A 71: 47 G 72: 45 E 73: 54 T 74: 20
75: 2F / 76: 20
77: 48 H 78: 54 T 79: 54 T 80: 50 P 81: 2F / 82: 31 1 83: 2E . 84: 31 1 85: D 86: A 87: 55 U 88: 70 p 89: 67 g 90: 72 r 91: 61 a 92: 64 d 93: 65 e 94: 3A : 95: 20
96: 57 W 97: 65 e 98: 62 b 99: 53 S 100: 6F o 101: 63 c 102: 6B k 103: 65 e 104: 74 t 105: D 106: A 107: 43 C 108: 6F o 109: 6E n 110: 6E n 111: 65 e 112: 63 c 113: 74 t 114: 69 i 115: 6F o 116: 6E n 117: 3A : 118: 20
119: 55 U 120: 70 p 121: 67 g 122: 72 r 123: 61 a 124: 64 d 125: 65 e 126: D 127: A 128: 48 H 129: 6F o 130: 73 s 131: 74 t 132: 3A : 133: 20
134: 65 e 135: 63 c 136: 68 h 137: 6F o 138: 2E . 139: 77 w 140: 65 e 141: 62 b 142: 73 s 143: 6F o 144: 63 c 145: 6B k 146: 65 e 147: 74 t 148: 2E . 149: 6F o 150: 72 r 151: 67 g 152: D 153: A 154: 4F O 155: 72 r 156: 69 i 157: 67 g 158: 69 i 159: 6E n 160: 3A : 161: 20
162: 68 h 163: 74 t 164: 74 t 165: 70 p 166: 3A : 167: 2F / 168: 2F / 169: 77 w 170: 77 w 171: 77 w 172: 2E . 173: 77 w 174: 65 e 175: 62 b 176: 73 s 177: 6F o 178: 63 c 179: 6B k 180: 65 e 181: 74 t 182: 2E . 183: 6F o 184: 72 r 185: 67 g 186: D 187: A 188: D 189: A 190: 2A 191: 43 C 192: 4C L 193: 4F O 194: 53 S 195: 2A close: failed, no CLOS Failed to connect to echo.websocket.org Terminal ready

OPEN

jonmarkgo commented 12 years ago

As far as I can tell, it looks correct... though its quite hard to read

harlequin-tech commented 12 years ago

Ok, so the WiFly thinks the remote end dropped the connection and did not send back the expected "HTTP/1.1 101" response for some reason. Maybe the echo server has changed its setup requirements to create the websocket connection. I'll do some reading on the websocket site.

harlequin-tech commented 12 years ago

I tried it by hand via telnet. Seems to be working with the same request as the WebSocketClient.ino sketch.

telnet echo.websocket.org 80 Trying 174.129.224.73... Connected to websocket.org. Escape character is '^]'. GET / HTTP/1.1 Upgrade: WebSocket Connection: Upgrade Host: echo.websocket.org Origin: http://www.websocket.org

HTTP/1.1 101 Web Socket Protocol Handshake Upgrade: WebSocket Connection: Upgrade WebSocket-Origin: http://www.websocket.org WebSocket-Location: ws://echo.websocket.org/ Server: Kaazing Gateway Date: Tue, 31 Jul 2012 04:52:12 GMT Access-Control-Allow-Origin: http://www.websocket.org Access-Control-Allow-Credentials: true Access-Control-Allow-Headers: content-type Access-Control-Allow-Headers: authorization Access-Control-Allow-Headers: x-websocket-extensions Access-Control-Allow-Headers: x-websocket-version Access-Control-Allow-Headers: x-websocket-protocol

jonmarkgo commented 12 years ago

Interesting, so I did a factory RESET on the RN-XV to see if there was anything funky in the settings... And now I get this when it starts up (had previously just saved my wifi credentials into the RN-XV settings): Failed to exit

Failed to turn off sys print Failed to exit

Failed to set comm remote Failed to exit

Failed to exit

Failed to exit

Failed to exit command mode Failed to start wifly Terminal ready Auto-Assoc roving1 chan=0 mode=NONE FAILED

jonmarkgo commented 12 years ago

Weird, I just unplugged my Arduino and plugged it back in and now I get this:

Joining network Joined wifi network open echo.websocket.org 80 Sending Hello World Received response: Hello, World!

I didn't change anything between these last 2 posts except that I restarted it but it suddenly works...

jonmarkgo commented 12 years ago

One thing to note - I tried it on my own node.js websocket server and it expects Sec-WebSocket-Key and Sec-WebSocket-Version to be included - may want to modify the example to have those fields since they're now part of the spec

jonmarkgo commented 12 years ago

Also, not sure if you're interested but I managed to get WiFlyHQ working with ArduinoPusherClient today: https://github.com/jonmarkgo/ArduinoPusherClient

harlequin-tech commented 12 years ago

Thanks for the link.

I'm closing this issue, let me know if you still think its a software issue.