Page 1 of 1

No love between node.js and otmonitor websockets

PostPosted: Wed Aug 09, 2017 10:40 pm
by sandervl
I'm building a solution where I am using Node-Red, a flow-based programming tool for wiring together hardware devices to talk to a number of sensors and to otmonitor. Node-Red offers a way to connect to websockets but for some reason it does not connect to otmonitor. Node-Red is based on node.js and uses the https://github.com/websockets/ws library and some tests in the console reveal that otmonitor responds with a 404 error. I ran more tests with http://www.websocket.org/echo.html and with the Simple Websocket Client Chrome extension and those all work fine. The Chrome Dev tools show a successful handshake. I can't seem to figure out why every library EXCEPT the self-proclaimed most stable and well-tested library is the only one that only doesn't work with otmonitor. In any case it halts further development of my project and I've spent over a week trying different setups. Anyone here have an similar experiences and/or solutions? I tried unraveling what kind of websocket library is in the source of otmonitor but it seems to be an add-on to the wibble http server that I can't debug.

See https://ibb.co/ezPNwa for the successful handshake in Chrome

Re: No love between node.js and otmonitor websockets

PostPosted: Thu Aug 10, 2017 12:25 pm
by labium
this is an interface for opentherm to Homey written in node https://github.com/nlrb/com.tclcode.otgw works great

Re: No love between node.js and otmonitor websockets

PostPosted: Thu Aug 10, 2017 9:36 pm
by sandervl
I found out what the problem is, otmonitor requires the origin header to be set. Weirdly enough it doesn't matter what you set it to as long as it's not empty. This .js code works fine:

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

And the result in the command line is as follows:

$ node ws.test.js

{"status": {"dhwmode": "1"}}
{"status": {"hotwater": "1"}}
{"status": {"flame": "1"}}
{"status": {"flame": "1"}}
{"status": {"boilertemp": "54.00"}}
{"status": {"boilerwatertemperature": "54.00"}}

So all is good, now I'm trying to get this feature added to Node-Red. Building my own node as we speak and see if I can get this option exposed in the core nodes to save everyone the trouble.

Re: No love between node.js and otmonitor websockets

PostPosted: Sat Sep 23, 2017 11:12 am
by hvxl
The check for the origin header was part of the websocket code I copied from the Tclers Wiki. But you are right, RFC6455 does not require the header to be present. I will remove the check.