Websocket Support in 2.0

Discussions about RaZberry - Z-Wave board for Raspberry computer
digitaldan
Posts: 11
Joined: 11 Sep 2014 18:53

Websocket Support in 2.0

Post by digitaldan »

I see in the 2.0 release notes that websocket push support is there. Can you explain how one would use this? Thanks!
pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: Websocket Support in 2.0

Post by pofs »

Well, it is pretty simple. On a low level,

Code: Select all

ws.push(obj);
will send a JSON-encoded object to all connected websocket clients. Then client may eval() received string and use it.

The shortcoming is, there should be a way for client to identify if the received object is intended for this particular client.

EDIT: In the future there would be an event type to push:

Code: Select all

ws.push(type, obj);
Client may specify a set of event types to listen for (by sending a comma-separated list of types into a socket), so messages will be delivered only to matching clients (in form of {"type": type, "data": obj}). Not specifying types filter will result in receiving all events.
digitaldan
Posts: 11
Joined: 11 Sep 2014 18:53

Re: Websocket Support in 2.0

Post by digitaldan »

Right now I am polling the ZWaveAPI every few seconds for status and would like to replace this with a push function over a websocket. Unfortunately this is the only API I am familiar with, so I'm not sure where your example would live. Would the ws.push(obj) live inside a automation module? How would clients make a websocket connection, what URL would they need to request? Thanks again!
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: Websocket Support in 2.0

Post by pz1 »

What client software are you using?
Since 29-12-2016 I am no longer a moderator for this forum
hpd
Posts: 36
Joined: 20 Mar 2014 12:03

Re: Websocket Support in 2.0

Post by hpd »

well, i am probably in similar position as digitaldan. My Home automation system is a java application which is based on regular ZWaveAPI/Data/{timestamp} requests.

This works very well for me and the whole application is for about 20 devices very stable and reliable.

But I am also wondering how i would achieve to a udp listener discussed above in a java application.
Z-Way 2.0.0-final on Raspberry Pi
pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: Websocket Support in 2.0

Post by pofs »

hpd wrote:But I am also wondering how i would achieve to a udp listener discussed above in a java application.
Just to clarify, WebSockets are not UDP.
If you actually need UDP, you'd better refer to @pz1 posts about UDP and OpenRemote. I'd rather write a native UDP sender, but calling netcat in a shell script also works fine.
For WebSockets you'll need a client-side support (like modern browser, or a java library).

But they're both just transports. Anyway you'll need to write some JS to catch events you need, and send them over preferred transport.
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: Websocket Support in 2.0

Post by pz1 »

pofs wrote:If you actually need UDP, you'd better refer to @pz1 posts about UDP and OpenRemote. I'd rather write a native UDP sender, but calling netcat in a shell script also works fine.
I am about to start rewriting the instructions here in the Recipes forum, and on the OpenRemote site, to make it work for version v2.0.0-rc23 and higher.
update 17:00: Recipe is up to date now

@pofs: A native UDP sender would indeed be nice. Well if you get bored sometime... :mrgreen:
Since 29-12-2016 I am no longer a moderator for this forum
digitaldan
Posts: 11
Joined: 11 Sep 2014 18:53

Re: Websocket Support in 2.0

Post by digitaldan »

My system is also Java, so I have a few choices for a websocket client. I was grepping through the automation code but can't find any reference to a websocket class. I would be happy to post what I get working in the recipes section. I just need a little stronger nudge in the right direction ;-)
digitaldan
Posts: 11
Joined: 11 Sep 2014 18:53

Re: Websocket Support in 2.0

Post by digitaldan »

BTW, I had not seen the openremote UDP solution, that actually may be better for my needs, so I may pursue that instead. Thanks.
hpd
Posts: 36
Joined: 20 Mar 2014 12:03

Re: Websocket Support in 2.0

Post by hpd »

sorry fro bringing UDP into this thread. I have no special knowledge with Websockets and was not aware of the difference.
Well, there are Websocket clients for Java Apps available. Therefore I think it should be possible to listen to the Zway Websocket Server. But I think you have to know some implementation Details of the Server to do so. Are these details known?
Z-Way 2.0.0-final on Raspberry Pi
Post Reply