Is Websocket API available for custom browser clients?

301 views
Skip to first unread message

Prashant Goswami

unread,
Mar 20, 2014, 10:29:34 AM3/20/14
to ope...@googlegroups.com
Hello,

 I have written a custom html client using openHAB rest API. But for receiving events is websocket API available?

Thanks in advance.

Kai Kreuzer

unread,
Mar 21, 2014, 2:44:53 AM3/21/14
to ope...@googlegroups.com
Hi Prashant,

What we have available as websocket/streaming is documented here: https://github.com/openhab/openhab/wiki/REST-API#streaming-connections
Note that you can not arbitrarily receive any events there, but only the ones that are together on a page of a sitemap.

Best regards,
Kai

--
You received this message because you are subscribed to the Google Groups "openhab" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openhab+u...@googlegroups.com.
To post to this group, send email to ope...@googlegroups.com.
Visit this group at http://groups.google.com/group/openhab.
For more options, visit https://groups.google.com/d/optout.

ver...@gmail.com

unread,
Mar 29, 2014, 10:26:10 PM3/29/14
to ope...@googlegroups.com
Hi Kai,

   Just to clarify, it's not possible to subscribe to the main REST items list (global), or to subscribe to a single REST item state? I'm trying to modify the GreenT app to at least test binding to something but my Js is terrible.

  I snagged what I think are the first steps with GreenT from the forum and while it says the websocket connection was successful to a single item, I can't get the response body to show up. :(

  I'm using the subscribe function from GreenT and trying to display the response in the console (to start) but all I get is [object Object]. Given your earlier response I can put al objects one one sitemap (if that was what you meant) or change the server as needed, but I would really like to query the server via websockets (long-polling etc) and as the item updates, change the HTML display.

  My changes to the GreenT snippet,

function Request(item) {

    this.socket = $.atmosphere;
    this.subSocket;
    this.transport = 'websocket';
    this.request = { url: 'ws://192.168.1.13:8080/rest/items/' + item,
                    maxRequest : 256,
                    timeout: 59000,
                    attachHeadersAsQueryString : true,
                    executeCallbackBeforeReconnect : false,
                    contentType : "text/plain",
                    logLevel : 'debug',
                    transport : 'websocket' ,
                    fallbackTransport: 'long-polling',
                    headers: {'Accept': 'application/json',
                            'X-Atmosphere-tracking-id': '1234'}};

    this.request.onOpen = function(response) {
        $('body').append('<p>Atmosphere connected using ' + response.transport + '</p>');
        console.log('Server: ' + response);
       
    };


 Any tips would be greatly appreciated.

-J

Kai Kreuzer

unread,
Apr 1, 2014, 4:05:34 PM4/1/14
to ope...@googlegroups.com
Hi,

   Just to clarify, it's not possible to subscribe to the main REST items list (global), or to subscribe to a single REST item state?

You are right. This is actually something I want to provide with openHAB 2.0 (based on Eclipse SmartHome) - an according issue can be found right here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=423552

Regarding the GreenT code, I cannot really help you much - this was fully done by Mihail.

Best regards,
Kai

Reply all
Reply to author
Forward
0 new messages