-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Implementing Web Sockets #30
Comments
Is websocket a application layer above tcp socket? like http? |
Yes it is a protocol providing full-duplex communications channels over a single TCP connection. |
It let you connect directly and have 2 way communication with server and ESP (Client) |
I google it and seems that this websocket work with html5, isn't it too "heavy" for mcu? |
I've found several libraries online like They are in pure lua |
its implementation should be fairly simple, you connect to tcp server and send special get request with special headers and wait for the response, you then compare the response id with the one you already generated, once confirmed you then have a successful handshake. Then you have to add a special frame and encode the message with a special way for the socket server to accept the message and response back. I've done it all using node Js by just using tcp connection so it should be fairly easy to implement on Lua |
Try to connect to esp8266 AP from other device ,but the configured password is not recognised. |
on my esp it works normaly. Open AP can be configured with nil pwd: |
Neironx, |
@samehhady have you been able to implement a WebSockets client on the ESP? You mentioned that you've developed something using node.js with a tcp connection, was this using the tcp capabilities of this firmware? If so, can you provide some example of how this can be achieved? I'd be keen to see a Lua implementation included in nodemcu as I believe it is a powerful and light-weight means of managing communications between nodes. |
My early websocket experience
|
@redlava I have did some studies on how to implement it and still waiting for my ESPs to try it out. |
I used rabbitmq with web-stomp and mqtt to connect nodemcu. |
There's also a good and lightweight https://developer.mozilla.org/en-US/docs/Web/API/EventSource |
mqtt and coap available. |
Thanks. mosquitto / rabbitmq has websocket support. I use rabbitmq on a raspberry pi as a central hub, works great. |
@samehhady, it will be nice if you can share your lua or js code to implement Websocket over TCP connection. I'm planning to do so, can leverage on your work. Thanks! |
Websocket is a little heavy, but I think it can be done. I tried porting my luvit websocket library but it used too much ram. The protocol itself is pretty simple. When I get a chance I'll write another pure lua websocket server that uses less ram so that an html5 based app can talk directly to the nodemcu. |
The main problem is md5 and sha1 algorithms, as i see. |
Those can also be implemented in lua, I've done it a few times before in JS. Though I do wonder how much memory that would use. |
@pastukhov There is no MD5 in websocket, but you do need SHA1 and Base64 encoding. Here is a sha1 function I just wrote using the |
I'm getting > dofile('testsha1.lua')
string length overflow |
@pastukhov You probably don't want to run all the unit tests on the nodemcu. One is calculating the sha1 of a string containing 1,000,000 "a"s long. The values that will be used in websocket handshake are under 100 characters long. I ran that one on a raspberry pi using luajit (it's bit library is compatible) |
Hi, all! |
Now that we have sha1 and friends in the core and a lot more free ram than when I initially started this, making a websocket server and/or client is quite feasible. See also my past experiments in this area:
I'm especially excited about websocket server since it means that browsers can directly talk to the mcu without any proxy in between. You can still host the bulk of the web ide (js/css/html) in the cloud and use cache-manifest or service workers to make it work when the laptop is offline. I'm currently working on a new VM for esp chips that should use less ram than lua. It will have websocket built-in. The basic workflow will be browser based so that any device on the same wifi network as the mcu can program it. There will be a repl in the browser as well as a code editor. My compiler from the high-level language down to the bytecode running in the vm will be implemented in JS so the mcu doesn't have the overhead of a compiler. |
Hi @creationix. |
Hi Zeroday,
You think its possible to implement web sockets on ESP?
Think of it as we will be able to control all ESPs using a cloud server & there will be 2 way communication between all ESPs and the server!
Also this can provide a cloud based flashing tool for ESP, we will be able to flash the ESPs from anywhere!
The text was updated successfully, but these errors were encountered: