Page 1 of 4

Websocket Support in 2.0

Posted: 02 Dec 2014 23:00
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!

Re: Websocket Support in 2.0

Posted: 03 Dec 2014 00:00
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.

Re: Websocket Support in 2.0

Posted: 03 Dec 2014 03:39
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!

Re: Websocket Support in 2.0

Posted: 03 Dec 2014 10:39
by pz1
What client software are you using?

Re: Websocket Support in 2.0

Posted: 03 Dec 2014 13:29
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.

Re: Websocket Support in 2.0

Posted: 03 Dec 2014 13:54
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.

Re: Websocket Support in 2.0

Posted: 03 Dec 2014 14:25
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:

Re: Websocket Support in 2.0

Posted: 03 Dec 2014 18:18
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 ;-)

Re: Websocket Support in 2.0

Posted: 03 Dec 2014 18:28
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.

Re: Websocket Support in 2.0

Posted: 03 Dec 2014 21:00
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?