Troubleshooting websocket connection in Node Red

1,112 views
Skip to first unread message

san...@vanloosbroek.com

unread,
Aug 6, 2017, 3:15:42 PM8/6/17
to Node-RED
I want to connect to a remote HTTP server that supports websockets so I can read status updates, the address is ws://2ndfloor-pi:8080/status.ws and when I use the simple websocket client Chrome extension all is fine and I get:

{"status": {"temperature": "24.35"}}
{"status": {"roomtemperature": "24.35"}}
{"status": {"temperature": "24.33"}}
{"status": {"roomtemperature": "24.33"}} 

Now when I try to create a websocket client in NR I always get "disconnected", no matter what I do or how I configure the node. I tried running node-red -v but no messages appear in the console. It's just disconnected, as if it isn't even trying. Any help troubleshooting this is much appreciated. Where should I look first?

Here's the config:

[{"id":"46f7a7d.ae26558","type":"debug","z":"dcbcc49f.0a2fc8","name":"","active":true,"console":"false","complete":"true","x":627,"y":245,"wires":[]},{"id":"1561d83c.aba248","type":"websocket in","z":"dcbcc49f.0a2fc8","name":"","server":"","client":"ad00d4f.6210328","x":226.5,"y":249,"wires":[["46f7a7d.ae26558"]]},{"id":"ad00d4f.6210328","type":"websocket-client","z":"","path":"ws://2ndfloor-pi:8080/status.ws","wholemsg":"false"}]

KR,
Sander

Julian Knight

unread,
Aug 6, 2017, 7:02:56 PM8/6/17
to Node-RED
I think you left the node at its default "type" of "Listen On"? You need it to be "Connect To" I think.

san...@vanloosbroek.com

unread,
Aug 7, 2017, 3:36:16 AM8/7/17
to Node-RED
If I did so in the pasted config my bad but in my tests I used connect-to (otherwise I had to enter a path instead of a ws:// URL)

Op maandag 7 augustus 2017 01:02:56 UTC+2 schreef Julian Knight:

Julian Knight

unread,
Aug 7, 2017, 11:51:02 AM8/7/17
to Node-RED
Is NR running on Windows? And is Windows running over Wi-Fi?

san...@vanloosbroek.com

unread,
Aug 7, 2017, 1:00:10 PM8/7/17
to Node-RED
It's actually between 2 RPi's, both running Jessie with all the updates, kernel 4.9. No special configuration.

Op maandag 7 augustus 2017 17:51:02 UTC+2 schreef Julian Knight:

Julian Knight

unread,
Aug 8, 2017, 2:15:56 AM8/8/17
to Node-RED
OK, thought it might have been an odd Windows Firewall issue.

Not sure then. Possibly some header not being passed? Might be worth checking in with the Slack community as well. Though most Slack people are here, you might find someone.

san...@vanloosbroek.com

unread,
Aug 10, 2017, 7:33:47 AM8/10/17
to Node-RED
Ok I found the problem. The websocket server requires the origin parameter to be not null. The dirty way is to patch https://github.com/websockets/ws/blob/master/lib/WebSocket.js#L501 from null to "localhost:8080" but I'd prefer to parse the origin parameter to the websocket node or to be able to configure it in the node itself. Any succestions?

Op dinsdag 8 augustus 2017 08:15:56 UTC+2 schreef Julian Knight:

Julian Knight

unread,
Aug 10, 2017, 9:10:29 AM8/10/17
to Node-RED
Well, needs raising as an issue on that library first I guess. Then as an issue against the node.

san...@vanloosbroek.com

unread,
Aug 10, 2017, 4:24:36 PM8/10/17
to Node-RED
I'm trying to fix this myself but now I'm making a Node-Red mistake. I created a new node based on the existing websockets node, with the tutorials etc I managed to set everything up. The only code I changed is: 

            var socket = new ws(node.path, {
            origin: node.path
            });

The repository is here: https://github.com/svloosbroek/node-red-contrib-ws-options-origin/ It seems that the origin value is not passed on so the node remains disconnected again. What am I missing?

KR,
Sander

Op donderdag 10 augustus 2017 15:10:29 UTC+2 schreef Julian Knight:

Nick O'Leary

unread,
Aug 10, 2017, 4:28:52 PM8/10/17
to Node-RED Mailing List
Hi, I don't have input on the specific issue as I've not looked in detail, but please please please do not publish a new ws contrib node purely to add this one feature. If its needed, we'd happily accept a pull-request to expose this option properly in the core nodes.

Nick

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/bd690bfc-01bb-4682-b22a-ed0055a6ac2c%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

san...@vanloosbroek.com

unread,
Aug 11, 2017, 3:13:25 PM8/11/17
to Node-RED
I created an issue on Github for this problem, suggestion to pass origin header. I'm not skilled to create a pull request of this so I edited 22-websocket.js locally for now. Thank you for considering.

Op donderdag 10 augustus 2017 22:28:52 UTC+2 schreef Nick O'Leary:
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.

To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
Reply all
Reply to author
Forward
0 new messages