influx data exploration

This commit is contained in:
simonox 2023-02-23 16:50:38 +01:00
parent 66c34f04e5
commit 43440b13e3
11 changed files with 159 additions and 12 deletions

View file

@ -91,7 +91,3 @@ esptool.py --chip esp32s3 write_flash -z 0 ~/Desktop/GENERIC_S3-20220117-v1.18
* [Energy Monitor](./software/firmware/energy-monitor/README.md) * [Energy Monitor](./software/firmware/energy-monitor/README.md)
* [Shelly Example](./software/firmware/shelly-monitor/README.md) * [Shelly Example](./software/firmware/shelly-monitor/README.md)
## Tutorials
* A great tutorial can be found at [microcontrollerlab.com](https://microcontrollerslab.com/esp32-mqtt-publish-multiple-sensor-readings-node-red/)

View file

@ -192,6 +192,20 @@
"servername": "", "servername": "",
"verifyservercert": false "verifyservercert": false
}, },
{
"id": "d61a7da6caeb26aa",
"type": "influxdb",
"hostname": "influxdb",
"port": "8086",
"protocol": "http",
"database": "database",
"name": "influx",
"usetls": false,
"tls": "d50d0c9f.31e858",
"influxdbVersion": "2.0",
"url": "http://influxdb:8086",
"rejectUnauthorized": true
},
{ {
"id": "3cc11d24.ff01a2", "id": "3cc11d24.ff01a2",
"type": "comment", "type": "comment",
@ -258,6 +272,64 @@
] ]
] ]
}, },
{
"id": "00a750cdfb54579e",
"type": "mqtt in",
"z": "f6f2187d.f17ca8",
"name": "",
"topic": "/iot-platform/energy-monitor/test-device/watt",
"qos": "1",
"datatype": "auto-detect",
"broker": "7ce136dbb8c897d1",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 270,
"y": 480,
"wires": [
[
"16687c90623bdb9b"
]
]
},
{
"id": "7e53d20583f56487",
"type": "influxdb out",
"z": "f6f2187d.f17ca8",
"influxdb": "d61a7da6caeb26aa",
"name": "Influx watt",
"measurement": "msg",
"precision": "",
"retentionPolicy": "",
"database": "database",
"precisionV18FluxV20": "ms",
"retentionPolicyV18Flux": "",
"org": "Curious Community Labs",
"bucket": "test",
"x": 730,
"y": 480,
"wires": []
},
{
"id": "16687c90623bdb9b",
"type": "function",
"z": "f6f2187d.f17ca8",
"name": "toNumber",
"func": "\nmsg.payload = Number(msg.payload)\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 540,
"y": 480,
"wires": [
[
"7e53d20583f56487"
]
]
},
{ {
"id": "e0977f2582bfaaa6", "id": "e0977f2582bfaaa6",
"type": "mqtt in", "type": "mqtt in",

View file

@ -1,3 +1,3 @@
{ {
"$": "2b099099e7732ecc4498978f475755f6UU2zgPJFd8JcqdknMyuTvMxV11RG2zk=" "$": "8a5830375d7cb047a920bc81b4cc476d+XU3NAfSPPxYBE1efxY1lIAusvuTCZCAU0damInvBBb4fzVvhMaUn60RLfr4AV7lMRCB2hbzc9MdqjzWd2JOC4ihNxhIKjYqZiqGAZ+dhJJ0U+FjxkCd"
} }

View file

@ -6,6 +6,21 @@
If you boot up our tech stack using `docker-compose` you already have a Node-RED instance running on [your local machine](http://localhost:1880/). If you boot up our tech stack using `docker-compose` you already have a Node-RED instance running on [your local machine](http://localhost:1880/).
Node-RED is an open-source, low-code, visual programming tool based on the concept of flow-based development. The idea behind it is to make it very easy to connect APIs, hardware devices, and anything else accessible over some type of network connection.
## Core Concepts
Nodes are the important part of Node-Red. They are the building blocks when working with Node-Red. Nodes are triggered by either receiving a message object from a previous node or an external event like an MQTT event. The node processes the message or event and then passes it on to the next node.
A node can:
* Inject: Starts a flow by injecting a message or a payload.
* Change: Here you can do basic transformation or modification on the message object.
* Debug: Can be used to help developing flows by sending messages to the side bar.
* Switch: Here you can add logic (like sending the message to different nodes).
* Function: Add custom JavaScript for uses cases where simple nodes do not do the trick.
Flows are an organized sequence of nodes. Let's do the "first steps" by creating a simple flow.
## First steps ## First steps
For debuging I already added Node-RED's own dashboard (sure, we are going to use Grafana, later). For debuging I already added Node-RED's own dashboard (sure, we are going to use Grafana, later).
@ -42,7 +57,35 @@ Have a look at the flow also in [this repository](./00-dashboard-example/dashboa
Already added to this project is [node-red-contrib-influxdb](https://flows.nodered.org/node/node-red-contrib-influxdb). You can use it's nodes to write and query data from an InfluxDB time series database. These nodes support both InfluxDB 1.x and InfluxDb 2.0 databases. At the time of this writing we are using [version 2.6 of InfluxDB on port 8086](http://admin:adminadmin@localhost:8086). Already added to this project is [node-red-contrib-influxdb](https://flows.nodered.org/node/node-red-contrib-influxdb). You can use it's nodes to write and query data from an InfluxDB time series database. These nodes support both InfluxDB 1.x and InfluxDb 2.0 databases. At the time of this writing we are using [version 2.6 of InfluxDB on port 8086](http://admin:adminadmin@localhost:8086).
In Node-RED we will be passing the power consumption number through MQTT.
![Overview](./docs/images/influx-flow.png)
By default this will be passed as a string, so we need to create a function to convert it into an integer before storing it with InfluxDB.
Add a function node to the page and put the following code into the node:
```JavaScript
msg.payload = Number(msg.payload)
return msg;
```
![Function](./docs/images/influx-function.png)
You can forward this message to InfluxDB.
![Influx Node](./docs/images/influx-node.png)
The `URL`of our InfluxDB is `http://influxdb:8086`. In InfluxDB you have to create a `token` to connect: Load Data -> API Tokens.
![Influx Connection](./docs/images/influx-connection.png)
Then the measurements should be visible in [Influx Data Explorer](http://localhost:8086/orgs/721027680173bf2f/data-explorer?bucket=test).
![Influx Data Explorer](./docs/images/influx-data-explorer.png)
# Links # Links
* [IoT Made Easy with Node-RED and InfluxDB](https://www.influxdata.com/blog/iot-easy-node-red-influxdb/) * [IoT Made Easy with Node-RED and InfluxDB](https://www.influxdata.com/blog/iot-easy-node-red-influxdb/)
* A great tutorial can be found at [microcontrollerlab.com](https://microcontrollerslab.com/esp32-mqtt-publish-multiple-sensor-readings-node-red/) * A great tutorial can be found at [microcontrollerlab.com](https://microcontrollerslab.com/esp32-mqtt-publish-multiple-sensor-readings-node-red/)

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 143 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

View file

@ -203,7 +203,7 @@
"usetls": false, "usetls": false,
"tls": "d50d0c9f.31e858", "tls": "d50d0c9f.31e858",
"influxdbVersion": "2.0", "influxdbVersion": "2.0",
"url": "http://influx:8086", "url": "http://influxdb:8086",
"rejectUnauthorized": true "rejectUnauthorized": true
}, },
{ {
@ -289,7 +289,7 @@
"y": 480, "y": 480,
"wires": [ "wires": [
[ [
"7e53d20583f56487" "16687c90623bdb9b"
] ]
] ]
}, },
@ -299,16 +299,52 @@
"z": "f6f2187d.f17ca8", "z": "f6f2187d.f17ca8",
"influxdb": "d61a7da6caeb26aa", "influxdb": "d61a7da6caeb26aa",
"name": "Influx watt", "name": "Influx watt",
"measurement": "", "measurement": "msg",
"precision": "", "precision": "",
"retentionPolicy": "", "retentionPolicy": "",
"database": "database", "database": "database",
"precisionV18FluxV20": "ms", "precisionV18FluxV20": "ms",
"retentionPolicyV18Flux": "", "retentionPolicyV18Flux": "",
"org": "ccl", "org": "Curious Community Labs",
"bucket": "test", "bucket": "test",
"x": 610, "x": 810,
"y": 500,
"wires": []
},
{
"id": "16687c90623bdb9b",
"type": "function",
"z": "f6f2187d.f17ca8",
"name": "toNumber",
"func": "\nmsg.payload = Number(msg.payload)\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 540,
"y": 480, "y": 480,
"wires": [
[
"7e53d20583f56487",
"499e0f3651d818db"
]
]
},
{
"id": "499e0f3651d818db",
"type": "debug",
"z": "f6f2187d.f17ca8",
"name": "debug 1",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 800,
"y": 420,
"wires": [] "wires": []
}, },
{ {

View file

@ -1,3 +1,3 @@
{ {
"$": "8a5830375d7cb047a920bc81b4cc476d+XU3NAfSPPxYBE1efxY1lIAusvuTCZCAU0damInvBBb4fzVvhMaUn60RLfr4AV7lMRCB2hbzc9MdqjzWd2JOC4ihNxhIKjYqZiqGAZ+dhJJ0U+FjxkCd" "$": "61928af03edb50cc6aca62a484ad6ea92hejWh+gAvqCLSvWIF/BQNIS6vqKIgzteKjcP4UA1Ee/AWCUcFXPizdT6suUZ4Mf6vw8dbLcJnXduW+0c0f2dwGK5io0Z3ghS7rh4tA2XAgsyhMKA2DuI3z2Bl7O0znAZo390l6MK+btAysPNiWak4eScefUyhcZAmSYiuGo/A1OrlgYMe7gKPQYtwsSSVe07hO8W+uQBeoAC9JL4+CJeOwDOM70iz/kZdzfamdGY3K80iE3+GNwHmmP"
} }