Skip to content

Commit

Permalink
web-socket example added
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytro-landiak committed Oct 30, 2017
1 parent 11c69a3 commit e634b96
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/iot-gateway/mqtt.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description: MQTT protocol support for ThingsBoard IoT Gateway
* TOC
{:toc}

This guide will help you to get familiar with OPC-UA extension configuration for ThingsBoard IoT Gateway.
This guide will help you to get familiar with MQTT extension configuration for ThingsBoard IoT Gateway.
Use [general configuration](/docs/iot-gateway/configuration/) to enable this extension.
We will describe extension configuration file below.

Expand Down
65 changes: 65 additions & 0 deletions docs/user-guide/resources/web-socket.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<!DOCTYPE HTML>
<html>
<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();
};
}

else {
alert("WebSocket is NOT supported by your Browser!");
}
}
</script>

</head>
<body>

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

</body>
</html>
20 changes: 19 additions & 1 deletion docs/user-guide/telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,25 @@ where
- **startTs** - start time of fetch interval for historical data query, in milliseconds.
- **endTs** - end time of fetch interval for historical data query, in milliseconds.

A complete example is coming soon!
##### Example

Change values of the following variables :

- **token** - to the JWT token which you can get using the [following link](https://thingsboard.io/docs/reference/rest-api/#rest-api-auth).

- **entityId** - to your device id.

In case of live-demo server :

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

In case of local instalation :

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

{% capture tabspec %}web-socket
A,web-socket.html,html,resources/web-socket.html,/docs/user-guide/resources/web-socket.html{% endcapture %}
{% include tabs.html %}

## Data visualization

Expand Down

0 comments on commit e634b96

Please sign in to comment.