Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebSocket API Example #76

Merged
merged 2 commits into from
Oct 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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