Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytro-landiak committed Oct 31, 2017
1 parent e634b96 commit 13e9cf6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 47 deletions.
85 changes: 39 additions & 46 deletions docs/user-guide/resources/web-socket.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,62 +3,55 @@
<head>

<script type="text/javascript">
function WebSocketTest() {
if ("WebSocket" in window) {
alert("WebSocket is supported by your Browser!");

var token = "YOUR_JWT_TOKEN";
var entityId = "YOUR_DEVICE_ID";
var webSocket = new WebSocket("ws(s)://host:port/api/ws/plugins/telemetry?token=" + token);

if (entityId === "YOUR_DEVICE_ID" || token === "YOUR_JWT_TOKEN") {
alert("Invalid token or device id!");
webSocket.close();
}

webSocket.onopen = function () {
var object = {
tsSubCmds: [
{
entityType: "DEVICE",
entityId: entityId,
scope: "LATEST_TELEMETRY",
cmdId: 10
}
],
historyCmds: [],
attrSubCmds: []
};
var data = JSON.stringify(object);
webSocket.send(data);
alert("Message is sent: " + data);
};

webSocket.onmessage = function (event) {
var received_msg = event.data;
alert("Message is received: " + received_msg);
};

webSocket.onclose = function (event) {
alert("Connection is closed!");
};

window.onbeforeunload = function (event) {
webSocket.close();
};
function WebSocketAPIExample() {
var token = "YOUR_JWT_TOKEN";
var entityId = "YOUR_DEVICE_ID";
var webSocket = new WebSocket("ws(s)://host:port/api/ws/plugins/telemetry?token=" + token);

if (entityId === "YOUR_DEVICE_ID") {
alert("Invalid device id!");
webSocket.close();
}

else {
alert("WebSocket is NOT supported by your Browser!");
if (token === "YOUR_JWT_TOKEN") {
alert("Invalid JWT token!");
webSocket.close();
}

webSocket.onopen = function () {
var object = {
tsSubCmds: [
{
entityType: "DEVICE",
entityId: entityId,
scope: "LATEST_TELEMETRY",
cmdId: 10
}
],
historyCmds: [],
attrSubCmds: []
};
var data = JSON.stringify(object);
webSocket.send(data);
alert("Message is sent: " + data);
};

webSocket.onmessage = function (event) {
var received_msg = event.data;
alert("Message is received: " + received_msg);
};

webSocket.onclose = function (event) {
alert("Connection is closed!");
};
}
</script>

</head>
<body>

<div id="sse">
<a href="javascript:WebSocketTest()">Run WebSocket</a>
<a href="javascript:WebSocketAPIExample()">Run WebSocket</a>
</div>

</body>
Expand Down
2 changes: 1 addition & 1 deletion docs/user-guide/telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ Change values of the following variables :

- replace **host:port** with **demo-thingsboard.io** and choose secure connection - **wss://**

In case of local instalation :
In case of local installation :

- replace **host:port** with **127.0.0.1:8080** and choose **ws://**

Expand Down

0 comments on commit 13e9cf6

Please sign in to comment.