Subscribe to Live Tag Updates via Web Sockets

Follow the steps below to subscribe to tags and receive realtime tag updates (last value) via Web Sockets. The example will be using Postman.

  1. Connect
  2. Send Format Message
  3. Send Subscribe Message
  4. Send Unsubscribe Message

 

The following article will demonstrate how to subscribe to a tag to receive real time tag changes via a web socket connection. Postman will be used to demonstrate / simulate the connection. 

Connect

In Postman, make a new web socket connection and enter the following address for the Url to connect to.

Url ws://<yourServerAddressHere>:4511/api/subscribe

The hub that serves the connection is managed by the Real Time Historian component. Ensure you use the some port as your Historian is configured to utilise. The default port number is 4511. Also, remember to change the <yourServerAddressHere> to your respective node address(IP/FQDN) where your Historian is running

Press connect to start the web socket connection.

Send "Format" Message

This message must be sent before any others. It informs the Historian Live Streaming Hub of the message protocol and version that will be used.

Copy the entire payload below, even the empty whitespace character past the }.

{
"protocol":"json",
"version":1
}

⚠️ Important: The Json message is followed by a special character, shown above with the white space placeholder. It will copy and paste correctly.

The ASCI code for this character is 30.

Make sure to include this charter at the end of your message.

Paste the message content into the Message box and press the "Send" command

 

⚠️ Important: Make sure to include this charter at the end of your message.

The Json message is followed by a special character, shown above with the white space placeholder. It will copy and paste correctly.

The ASCI code for this character is 30.

Send "Subscribe" Message

Send a "Subscribe" message to register for live updates of a tag. The message arguments are Dataset name and Tagname:

{
"arguments": ["<Dataset>", "<Tagname>"],
"target": "Subscribe",
"type": 1
}

Please remember to replace <Dataset> with the data set your tag resides in and the <Tagname> with the name of the tag you want to subscribe to.

Notice the messages appear for every new tag change value.

Send "Unsubscribe" Message

If live updates is no longer required, send an "Unsubscribe" message to deregister from live updates. The message arguments are Dataset name and Tagname:

{
"arguments": ["<Dataset>", "<Tagname>"],
"target": "Unsubscribe",
"type": 1
}

Please remember to replace <Dataset> with the data set your tag resides in and the <Tagname> with the name of the tag you want to subscribe to.