node.js, server-side API and websockets...

Discussions about RaZberry - Z-Wave board for Raspberry computer
Daedalus
Posts: 2
Joined: 04 Feb 2015 11:13

node.js, server-side API and websockets...

Post by Daedalus »

Hi,

since yesterday I am playing with this nice piece of work - and it really is working, I can control all my devices. But I expected a little more, hopefully its just because I don't know better:

- I wanted to make my own node.js server, because of different reasons, for building my own infrastructure and connecting to my public server etc. AND because AJAX and this way of polling really is absolutely no good solution to me for a home automation interface, I definitely want to use websockets!!
But in this forum and in the document I have found no example for how to access the documented zway JavaScript Object from my node.js program so that I can for example bind callback functions and respond directly to my websocket clients.
Is that possible in any way? At the moment I am struggling with creating a userModule, but to me it doesn't seem to be the right way for my purposes...

- I read about websocket support but I found no explanation about it, how does it work?

Thanks in advance!
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: node.js, server-side API and websockets...

Post by pz1 »

Daedalus wrote:- I wanted to make my own node.js server, because of different reasons, for building my own infrastructure and connecting to my public server
Seems you only need acces to the Z-Wave stack?
Since 29-12-2016 I am no longer a moderator for this forum
Mirar
Posts: 113
Joined: 19 Oct 2014 16:54
Location: Stockholm

Re: node.js, server-side API and websockets...

Post by Mirar »

You could use the JSON interface, like I do, and put up your own server on the same/different hardware.

That said, I'd like to see a way of turning z-way-server into minimal mode without any HA support. It was possible in 1.4 (empty automation directory) but with 2.0 it seems trickier?
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: node.js, server-side API and websockets...

Post by pz1 »

Mirar wrote:That said, I'd like to see a way of turning z-way-server into minimal mode without any HA support. It was possible in 1.4 (empty automation directory) but with 2.0 it seems trickier?
There is a thread where Pofs suggested this, but he did not give the recipe at that time if I remember correctly. I guess you would need an alternative main.js that starts the Zwave stack and a few other things. Having the Expert UI in such a minimal setup would be a necessity I think.
Since 29-12-2016 I am no longer a moderator for this forum
Daedalus
Posts: 2
Joined: 04 Feb 2015 11:13

Re: node.js, server-side API and websockets...

Post by Daedalus »

Mirar wrote:You could use the JSON interface, like I do, and put up your own server on the same/different hardware.
OK, but how do you do it? Via HTTP request and localhost? Thats the only way I figured out till now but as far as I know it's not possible with that method to bind callback functions?

pz1 wrote:Seems you only need acces to the Z-Wave stack?
I'm not sure, first thing I want to get running is to send and listen to events WITHOUT polling from my node.js program...
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: node.js, server-side API and websockets...

Post by pz1 »

On this forum I have written a procedure to send a UDP message on every event. Maybe that can inspire you
Mirar
Posts: 113
Joined: 19 Oct 2014 16:54
Location: Stockholm

Re: node.js, server-side API and websockets...

Post by Mirar »

pz1 wrote:There is a thread where Pofs suggested this, but he did not give the recipe at that time if I remember correctly. I guess you would need an alternative main.js that starts the Zwave stack and a few other things. Having the Expert UI in such a minimal setup would be a necessity I think.
That would be great, I think. I only use Expert UI and JSON.

I don't know if you need a different main.js. It would be enough with a setting in the Expert UI or a file somewhere (/etc/defaults/z-way-server, for instance) that stops main.js from loading and starting things not needed.
Mirar
Posts: 113
Joined: 19 Oct 2014 16:54
Location: Stockholm

Re: node.js, server-side API and websockets...

Post by Mirar »

Daedalus wrote:
Mirar wrote:You could use the JSON interface, like I do, and put up your own server on the same/different hardware.
OK, but how do you do it? Via HTTP request and localhost? That's the only way I figured out till now but as far as I know it's not possible with that method to bind callback functions?
Unfortunately, you need to poll. You'll get all the new information since the last timestamp.

http://172.16.0.72:8083/ZWaveAPI/Data/1423075953

to get all new data since 19:52:33 CET today from Razberry on 172.16.0.72.

I poll twice a second. You'll get repeats, but it's totally manageable. (I do the same thing again from my Javascript in-browser UI to my own server.)

You will have to parse that JSON format yourself. But it's really quite feasible. (Although I might be biased, I'm an embedded programmer for a living. The hairy protocols and precisely timed bitbanging against buggy hardware you have to do sometimes...)
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: node.js, server-side API and websockets...

Post by pz1 »

Mirar wrote:Unfortunately, you need to poll.
Not necessarily as I argued in my answer above
Since 29-12-2016 I am no longer a moderator for this forum
Mirar
Posts: 113
Joined: 19 Oct 2014 16:54
Location: Stockholm

Re: node.js, server-side API and websockets...

Post by Mirar »

pz1 wrote:
Mirar wrote:Unfortunately, you need to poll.
Not necessarily as I argued in my answer above
Oh, interesting hack.

I'd like to see something like Kodi's stream of JSON data on TCP though. That would be very useful, and more reliable.
Post Reply