node-red-contrib-thingsboard-gateway 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -0
- package/nodes/thingsboard-gateway.html +44 -0
- package/nodes/thingsboard-gateway.js +37 -0
- package/package.json +21 -0
package/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# node-red-contrib-thingsboard-gateway
|
|
2
|
+
|
|
3
|
+
Send telemetry data from Node-RED to ThingsBoard Gateway using MQTT.
|
|
4
|
+
|
|
5
|
+
## Input
|
|
6
|
+
`msg.payload` should be a valid ThingsBoard gateway telemetry JSON.
|
|
7
|
+
|
|
8
|
+
## Example
|
|
9
|
+
|
|
10
|
+
```json
|
|
11
|
+
{
|
|
12
|
+
"deviceName": "sensor-01",
|
|
13
|
+
"telemetry": {
|
|
14
|
+
"temperature": 27.5
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType("thingsboard-gateway", {
|
|
3
|
+
category: "network",
|
|
4
|
+
color: "#2C3E50",
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: "" },
|
|
7
|
+
broker: { value: "mqtt://localhost:1883", required: true },
|
|
8
|
+
topic: { value: "v1/gateway/telemetry" },
|
|
9
|
+
username: { value: "" },
|
|
10
|
+
password: { value: "" }
|
|
11
|
+
},
|
|
12
|
+
inputs: 1,
|
|
13
|
+
outputs: 0,
|
|
14
|
+
icon: "bridge.svg",
|
|
15
|
+
label: function () {
|
|
16
|
+
return this.name || "ThingsBoard Gateway";
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<div class="form-row">
|
|
22
|
+
<label>Name</label>
|
|
23
|
+
<input type="text" id="node-input-name">
|
|
24
|
+
</div>
|
|
25
|
+
|
|
26
|
+
<div class="form-row">
|
|
27
|
+
<label>Broker</label>
|
|
28
|
+
<input type="text" id="node-input-broker">
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
<div class="form-row">
|
|
32
|
+
<label>Topic</label>
|
|
33
|
+
<input type="text" id="node-input-topic">
|
|
34
|
+
</div>
|
|
35
|
+
|
|
36
|
+
<div class="form-row">
|
|
37
|
+
<label>Username</label>
|
|
38
|
+
<input type="text" id="node-input-username">
|
|
39
|
+
</div>
|
|
40
|
+
|
|
41
|
+
<div class="form-row">
|
|
42
|
+
<label>Password</label>
|
|
43
|
+
<input type="password" id="node-input-password">
|
|
44
|
+
</div>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module.exports = function (RED) {
|
|
2
|
+
function ThingsBoardGatewayNode(config) {
|
|
3
|
+
RED.nodes.createNode(this, config);
|
|
4
|
+
|
|
5
|
+
const node = this;
|
|
6
|
+
const mqtt = require("mqtt");
|
|
7
|
+
|
|
8
|
+
const client = mqtt.connect(config.broker, {
|
|
9
|
+
username: config.username,
|
|
10
|
+
password: config.password
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
client.on("connect", () => {
|
|
14
|
+
node.status({ fill: "green", shape: "dot", text: "connected" });
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
client.on("error", (err) => {
|
|
18
|
+
node.status({ fill: "red", shape: "ring", text: "error" });
|
|
19
|
+
node.error(err);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
node.on("input", (msg) => {
|
|
23
|
+
if (!msg.payload) return;
|
|
24
|
+
|
|
25
|
+
const topic = config.topic || "v1/gateway/telemetry";
|
|
26
|
+
const payload = JSON.stringify(msg.payload);
|
|
27
|
+
|
|
28
|
+
client.publish(topic, payload);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
node.on("close", () => {
|
|
32
|
+
client.end();
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
RED.nodes.registerType("thingsboard-gateway", ThingsBoardGatewayNode);
|
|
37
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "node-red-contrib-thingsboard-gateway",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Node-RED node for sending data to ThingsBoard via Gateway Device using MQTT protocol.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"node-red",
|
|
7
|
+
"node-red-contrib",
|
|
8
|
+
"thingsboard",
|
|
9
|
+
"mqtt",
|
|
10
|
+
"iot"
|
|
11
|
+
],
|
|
12
|
+
"license": "Apache-2.0",
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=16"
|
|
15
|
+
},
|
|
16
|
+
"node-red": {
|
|
17
|
+
"nodes": {
|
|
18
|
+
"thingsboard-gateway": "nodes/thingsboard-gateway.js"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|