-->
Page 1 of 2

Websocket for arduino

PostPosted: Wed Nov 19, 2014 7:09 am
by popcorn
Hello,

I try to made a Websocket for Arduino. This because it's a good way to communicate with a app Android / Ios / ..... Every html5 browser.

I'm able to send (short) messages from http://www.websocket.org/echo.html to my arduino. But when I send it the other way arround to the websocket I got the error:
WebSocket connection to 'ws://192.168.1.101:8000/?encoding=text' failed: One or more reserved bits are on: reserved1 = 0, reserved2 = 1, reserved3 = 1

When well working I'm going to try to implement it in the ESP firmware itself...

https://github.com/zoutepopcorn/esp8266-Websocket

Maybe someone can take a fresh look at it?

Thanks

Re: Websocket for arduino

PostPosted: Thu Jan 15, 2015 10:42 am
by alca3z
Any news about websocket for ESP8266?

Re: Websocket for arduino

PostPosted: Tue Jan 20, 2015 11:46 am
by carlb007
Hey popcorn.

i took a look through your code and after many hours (days actually) trrying to get this working i finally succeeded and now have the following setup:

HTML 5 app transfering 224 bytes of data with the first 2 bytes of the data forminng an INT checksum for the other 222 bytes. Theres then an extra 6 bytes of header info as set by the browser when framing the data that you dont see but will need buffer space for on the arduino side.
Arduino parses data. checks the checksum status, and returns the cheksum back the browser. when the browser (JS) receives the checksum and it matches what it expected it sends the next pack. if not it resends the previous packet.

At present i have this running at ~6500 bytes per second at 115,200 baud with the checksumming and other stuff going on (im not using any delays at all anywhere in the code on arduino).

A few findings:

Your TX issue (from arduino to web) basically resolves around your serial.print. Switch to something like this:

Serial.print("AT+CIPSEND=0,");
Serial.println(dataLength+2);
Serial.write(opCode);
Serial.write(dataLength);
Serial.write((byte)*data);
Serial.write((byte)(*data>>8));

When transfering data back you still need to frame it correctly as per the spec sheet. The browser will handle the unmasking of the data etc.
I transfer using the binary opcode so on the JS side i have to dump the data into uint8 bit arrays and do some jigging about to get my full INT checksum from the first 2 bytes back out - but the bottom line is it is possible and does work.

A few other side notes ive noticed:
There can be alot of jibberish coming from the EPS wifi device. at 115,200 / 16mhz its particularly bad. Swapping to 20mhz remedies this issue quite dramatically - its worth checking out; http://wormfood.net/avrbaudcalc.php?postbitrate=115200&postclock=80&bit_rate_table=1 to ease alot of your pain.
Ive got an 18.432 crystal ordered to try out 230k baud.

After 2 1/2 constant data transfer i seem to be getting EPS hangs. still not figured out whats going on but it always happens on an attempt to send data rather than receive it, and always results in the device phystically resetting itself - i have it debugging to capture the error and print the Serial.read and can see that its replicating a AT+RST command.

If you need any more advice or hints let me know - i dont really want to post my code in its entirety just yet as its still got a few issues but as soon as its 100% stable ill post both my JS and arduino code.

ta
Carl.

Re: Websocket for arduino

PostPosted: Wed Apr 15, 2015 6:11 am
by hieucdtspk
Hi all,

Sorry if it's not relevant.
But I've just created a porting of websocket for arduino to esp8266 with SDK itself, you need setup toolchain, sdk, programming tool (a USB-UART adapter), burn it and enjoy!
Rightnow, the lib. work in websocket server side (only) with multiple connection support!

Regards,
HieuNT.