How to connect using Websocket Api

I have a device which is publishing to an attribute now I want to make connection with attribute to get data as soon as it is published. I want to make it realtime using websocket apis but I am unable to find how can I subscribe to attribute for realtime update?

There is some documentation on the GitHub wiki to get you started with listening to attribute updates;

this part I am able to achieve but how to do next. I want to subscribe to building device attribute city then how to send here?


Also, will it be same for publish?

You can only subscribe to attribute events once authenticated.
The URL you’re talking about is to instantiate the connection by authenticating.


  1. Use wss://localhost:8080/websocket/events?Realm=smartcity&Authorization=Bearer%20eye2238f3a-e43c-3f54-a05a-dd2e4bd4631f to connect and authenticate with the WebSocket API
  2. Send a JSON message using the EventSubscription format; (as written in the docs)
    For example, to subscribe to a single attribute;
SUBSCRIBE:{"eventType": "attribute", "filter": { "ref": { "id": "<asset id>", "name": "<attribute name>" }}

(can’t verify this, and I’m not 100% familiar with the WS API, so check docs if not working)

  1. You’ll get a message prefixed with SUBSCRIBED: or an error verifying the subscription.

It sadly involves quite a bit of diving into the JavaDoc, same counts for publishing.
We should write some documentation on this. :sweat_smile: