-
• #2
i've tested the server with versions of npm ws 5, 4, 3, and 2. all give the same error about RSV1 must be clear, after connecting from the client. i have not tested the client on espruino wifi with versions older than 1v97.
-
• #3
Thanks for letting me know. Sorry about this - it seems to be a bug introduced in a recent pull request to Espruino. I'll try and get it fixed as soon as possible
If you try firmware 1v96 (or any commit before 46e4bc69d73631b63f62b11febb4f2c07ec1acf3) then that should work.
You can follow the fix here if you're interested: https://github.com/espruino/Espruino/issues/1405
-
• #5
i have confirmed that 1v96 works with espruino as the websocket client. i am still receiving an error when espruino is the server, using the example code, and i use this code in node.js
Error: Server sent a subprotocol but none was requested
const WebSocket = require('ws'); const ws = new WebSocket('ws://192.168.1.203:8000/', { protocol : "echo-protocol", protocolVersion: 13 }); ws.on('open', function open() { ws.send('something'); }); ws.on('error', function(err) { console.log(err); }) ws.on('message', function incoming(data) { console.log(data); });
-
• #6
And the error comes from Node.js?
Strange thing is it'd seem that you are requesting a subprotocol of
"echo-protocol"
, unless I'm misunderstanding? -
• #7
This may be user error, as the espruino websocket server example works when the client is a web browser. when trying to get the client to be a node.js app, i'm having issues.
this gives the same error from node.js. i can see the blue light flash on the espruino when i run the client, but there is no output in the espruino repl.
is there an example for espruino websocket server, and node.js client?
const WebSocket = require('ws'); const ws = new WebSocket('ws://192.168.1.203:8000/'); ws.on('open', function open() { ws.send('something'); }); ws.on('error', function(err) { console.log(err); }) ws.on('message', function incoming(data) { console.log(data); });
-
• #8
changing the connection to mirror the browser client connection in the embedded web page worked
const ws = new WebSocket('ws://192.168.1.203:8000', 'protocolOne');
i didn't see that 'protocolOne' parameter documented anywhere. it works, so i'll move on for now.
-
• #9
Just to add that @opichals has just fixed this, so any new firmware from http://www.espruino.com/binaries/travis/master/ (or 1v98 and later) will have this fixed.
-
• #10
there were other regressions with 1v97.60, e.g. the getPage() example did not return a page. reverting to 1v97 or 1v96 does work. i'll wait for an official release to move forward from 1v96 for now.
-
• #11
i tried 1v97.62 as well. this code does not return a page to the repl anymore
function getPage() { require("http").get("http://www.pur3.co.uk/hello.txt", function(res) { console.log("Response: ",res); res.on('data', function(d) { console.log("--->"+d); }); }); }
-
• #12
also with 1v97.62 i am not able to complete a websocket connection with espruino as the server and a webpage as the client. it stays in the connecting state. same code is working in 1v96
-
• #14
I tried the getPage() and it did work for me when the URL is correct. Cutting & pasting from the forum's example however mangled the URL for me so I got a 'Not found' error.
@J{a}SON could you try this and post the whole console result?
require("http").get("http://www.pur3.co.uk/hello.txt", function(res) { console.log("Response: ",res); res.on('data', function(d) { console.log("--->"+d); }); }).on('error', function(err) { console.log('ERROR', err); });
-
• #16
which build are you looking at? the larger remaining problem is the espruino not working as a websocket server, as documented in the github issues https://github.com/espruino/Espruino/issues/1405.
i'll test again if you let me know which build to look at.
-
• #17
@J{a}SON I would wait for the https://github.com/espruino/Espruino/pull/1415 to get merged and then grab the master build for further tests.
-
• #18
Just done :)
-
• #19
ok, this is working now with espruino as the ws client, and ws server. getPage() is working as well.
i do have an additional question: when espruino is the ws client, and i send a message from the node.js server, it shows up as a rawData event as well as a message event. is this expected?
wsConnect()
=undefined
RAW: HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: NRGmTTLwn7B71D1ZNRdkobCXs/0=
Sec-WebSocket-Protocol: echo-protocol
Handshake Success
Connected to server
RAW: something
MSG: something -
• #20
Yes. Listen to one event or the other...
-
• #21
Just to add - 'rawData' is basically just a debugging aid for the websocket implementation. 99.9% of the time you'd want to use the message event :)
-
• #22
glad we got this sorted out. now i can move on to programming ble on my pucks :)
-
• #23
I've manager to reproduce one of these issues using a current build on linux.
vue native sockets in chrome browser -> Backend Espruino WS server.
If protocol is specified, then all is well:
const ws = new WebSocket('ws://192.168.1.203:8000', 'protocolOne');
However, if this is defaulted, ws.js on the espruino sends as a header:
Sec-WebSocket-Protocol: undefined
this test seems to be failing:
https://github.com/espruino/EspruinoDocs/blob/master/modules/ws.js#L196-L197if (this.protocol) socketHeader.push("Sec-WebSocket-Protocol: "+this.protocol);
in the constructor we have:
https://github.com/espruino/EspruinoDocs/blob/master/modules/ws.js#L76-L86
this.protocol = options.protocol;
So it seems this is setting
this.protocol=undefined
.What is the cleanest way to fix?
if ( typeof(this.protocol) != 'undefined' )
-
• #24
Ahh - that's frustrating. Thanks for checking up - I believe I may have fixed this for the Espruino as client case, but not Espruino as server.
I think the code you pointed to is for the client, and is actually working.
if (this.protocol)
should be fine.What was needed was to add that same check for the server case. I've just done it here: https://github.com/espruino/EspruinoDocs/commit/74d779dc5d636d9c6fb2df032a8dfda148961bb9
It's not on the website yet, but you can
require("https://raw.githubusercontent.com/espruino/EspruinoDocs/master/modules/ws.js")
and test it out -
• #25
Thanks for updating!
when attempting to follow the websocket client example at http://www.espruino.com/ws, i get errors on the server (running node.js on a windows10 laptop) as:
RangeError: Invalid WebSocket frame: RSV1 must be clear
When I modify the code to use the npm ws client on the laptop, it works fine.
server:
node 8.9.4,
"dependencies": {
}
espruino wifi client:
1v97
output on the repl is