Skip to content

Commit

Permalink
Merge pull request #76 from dmytro-landiak/master
Browse files Browse the repository at this point in the history
WebSocket API Example
  • Loading branch information
ashvayka authored Oct 31, 2017
2 parents 11c69a3 + 13e9cf6 commit 7d3f71c
Show file tree
Hide file tree
Showing 3 changed files with 78 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
58 changes: 58 additions & 0 deletions docs/user-guide/resources/web-socket.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!DOCTYPE HTML>
<html>
<head>

<script type="text/javascript">
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();
}

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:WebSocketAPIExample()">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 installation :

- 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 7d3f71c

Please sign in to comment.