im searching for a suggestion for read a response out of a websocket, what is generating realtime machine data.
For example, here is the javascript code, that i can open in my browser.
<!DOCTYPE html>
<meta charset="utf-8" />
<title>WebSocket Test</title>
<script language="javascript" type="text/javascript">
<!-- Fill in the correct URL from AgentDataRealTimeWebSocket (see step 3). -->
<!-- The comma is mandatory as it is a list. -->
var wsUri = "wss://...,/data-realtime";
var output;
function init()
{
output = document.getElementById("output");
testWebSocket();
}
function testWebSocket()
{
websocket = new WebSocket(wsUri);
websocket.onopen = function(evt) { onOpen(evt) };
websocket.onclose = function(evt) { onClose(evt) };
websocket.onmessage = function(evt) { onMessage(evt) };
websocket.onerror = function(evt) { onError(evt) };
}
<!-- Enter your JWT token here. -->
function onOpen(evt)
{
writeToScreen("CONNECTED");
doSend("Authorization: Enter JWT here");
}
function onClose(evt)
{
writeToScreen("DISCONNECTED");
}
function onMessage(evt)
{
writeToScreen('<span style="color: blue;">RESPONSE: ' + evt.data+'</span>');
}
function onError(evt)
{
writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data);
}
function doSend(message)
{
writeToScreen("SENT: " + message);
websocket.send(message);
}
function writeToScreen(message)
{
var pre = document.createElement("p");
pre.style.wordWrap = "break-word";
pre.innerHTML = message;
output.appendChild(pre);
}
window.addEventListener("load", init, false);
</script>
<h2>WebSocket Test</h2>
<div id="output"></div>
</script>
The response of this code looks like this, and comes in every 0,5s (PLC Data):
RESPONSE: {"message": {"points": [{"float32": [35.912109375, 2.0], "int16": [5808], "str": [""], "tags": [1, 2, 3, 4], "time": 1665666946000}], "sentTime": 1665666946398}, "agent": {"publicId": "..."}, "device": {"publicId": "..."}}
Does anyone have an approach to this?
Thanks for your help!