Sensor data via InfluxDB with Node-RED¶
Overview
This guide will show you how to access sensor data via InfluxDB by using Node-RED within Docker.
Prerequisites
- Node-RED container up and running. Documentation
Influx Configuration¶
Open the settings on the right side, click on manage palette and then select the "install" tab. Search for node-red-contrib-influxdb
and install the first one listed.
Drag and drop the influxdb node from the storage section of toolbox on the left into your flow. Double-click on the influx node in the info panel on the right.
This will open the configuration for the influxdb node. In this case we are sending the query SHOW FIELD KEYS
to display the names of the values in the database. We still need to add an influx database though. To do that click on the pencil icon next to the text Add new influxdb...
.
The InfluxDB is available at the IP-address 172.16.0.2
and port 8086
. The database is named balluffCMTKDatabase
, the username is cmtk
and password is balluff
(If it was not changed via the influx configurator api).
Note
The account above is a read-only account which only works for containers deployed and running on a CMTK device. This interface is not available for external devices.
Now you have to enable the secure TLS connection since the CMTK's inflxdb is configured to only allow secure/encrypted connections.
Make sure to disable server certificate verification.
Add the TLS configuration by click on Add
. Than update the influxdb connection settings with Update
.
This will return you to the influxdb node where you just need to save the changes by clicking on Done
. Now your influxdb node is configured and can be used within your flows.
Debug Output¶
In order to test that your flow is working as intended it might be a good idea to use a debug node. Simply drag in a debug-node from the common section of the toolbox and connect the input to the output of your influxdb node. You also need to insert an inject node to inject the query. So drag in an inject-node from the common section of the toolbox and connect its output to the input of your influxdb node. Do not forget to deploy your changes with the Deploy
button at the top right.
Verify the debug output by toggling the inject node and then clicking on the bug icon in the upper right toolbox. The raw messages will appear in a console windows in case everything is working as expected.
Example¶
The example we have just created may be imported by clicking on the menu in the top right and selecting import with the following JSON. In order to run the example the influx node still has be be installed once and username and password have to be adjusted in the influx node.
[
{
"id": "eb7ead1ff71495e3",
"type": "tab",
"label": "Influxdb",
"disabled": false,
"info": ""
},
{
"id": "28896d193b3821b0",
"type": "influxdb in",
"z": "eb7ead1ff71495e3",
"influxdb": "d1b170b2dc7760f5",
"name": "",
"query": "SHOW FIELD KEYS",
"rawOutput": false,
"precision": "",
"retentionPolicy": "",
"org": "organisation",
"x": 490,
"y": 420,
"wires": [
[
"999ade3158a79000"
]
]
},
{
"id": "a3c06579011dd15e",
"type": "inject",
"z": "eb7ead1ff71495e3",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 260,
"y": 420,
"wires": [
[
"28896d193b3821b0"
]
]
},
{
"id": "999ade3158a79000",
"type": "debug",
"z": "eb7ead1ff71495e3",
"name": "debug 1",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 770,
"y": 420,
"wires": []
},
{
"id": "d1b170b2dc7760f5",
"type": "influxdb",
"hostname": "172.16.0.2",
"port": "8086",
"protocol": "http",
"database": "balluffCMTKDatabase",
"name": "Influx-CMTK",
"usetls": true,
"tls": "92f7f093f4df2d6f",
"influxdbVersion": "1.x",
"url": "http://localhost:8086",
"timeout": "10",
"rejectUnauthorized": true
},
{
"id": "92f7f093f4df2d6f",
"type": "tls-config",
"name": "",
"cert": "",
"key": "",
"ca": "",
"certname": "",
"keyname": "",
"caname": "",
"servername": "",
"verifyservercert": false,
"alpnprotocol": ""
}
]
Another example to retrieve values from port1 for the last 5 minutes:
[
{
"id": "f6f2187d.f17ca8",
"type": "tab",
"label": "Influxdb",
"disabled": false,
"info": ""
},
{
"id": "9ba80cf6b1fd0dd9",
"type": "influxdb in",
"z": "f6f2187d.f17ca8",
"influxdb": "d1b170b2dc7760f5",
"name": "",
"query": "SELECT * FROM \"port1\" WHERE time > now() - 5m",
"rawOutput": false,
"precision": "",
"retentionPolicy": "",
"org": "organisation",
"x": 510,
"y": 220,
"wires": [
[
"3b6cde616f71f2e1"
]
]
},
{
"id": "3b6cde616f71f2e1",
"type": "debug",
"z": "f6f2187d.f17ca8",
"name": "debug 1",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 680,
"y": 140,
"wires": []
},
{
"id": "f7940b1ece5a02b0",
"type": "inject",
"z": "f6f2187d.f17ca8",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 280,
"y": 220,
"wires": [
[
"9ba80cf6b1fd0dd9"
]
]
},
{
"id": "d1b170b2dc7760f5",
"type": "influxdb",
"hostname": "172.16.0.2",
"port": "8086",
"protocol": "http",
"database": "balluffCMTKDatabase",
"name": "Influx-CMTK",
"usetls": true,
"tls": "92f7f093f4df2d6f",
"influxdbVersion": "1.x",
"url": "http://localhost:8086",
"timeout": "10",
"rejectUnauthorized": true
},
{
"id": "92f7f093f4df2d6f",
"type": "tls-config",
"name": "",
"cert": "",
"key": "",
"ca": "",
"certname": "",
"keyname": "",
"caname": "",
"servername": "",
"verifyservercert": false,
"alpnprotocol": ""
}
]
For more information, please consult the official InfluxDB Documentation.