diff --git a/README.md b/README.md index 1224c07..258d407 100644 --- a/README.md +++ b/README.md @@ -90,8 +90,4 @@ esptool.py --chip esp32s3 write_flash -z 0 ~/Desktop/GENERIC_S3-20220117-v1.18 ## Hardware sensors * [Energy Monitor](./software/firmware/energy-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/) +* [Shelly Example](./software/firmware/shelly-monitor/README.md) \ No newline at end of file diff --git a/software/flow/.flows.json.backup b/software/flow/.flows.json.backup index 3dd2fcf..e90a3fe 100644 --- a/software/flow/.flows.json.backup +++ b/software/flow/.flows.json.backup @@ -192,6 +192,20 @@ "servername": "", "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", "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", "type": "mqtt in", diff --git a/software/flow/.flows_cred.json.backup b/software/flow/.flows_cred.json.backup index 445a0eb..d0bceb6 100644 --- a/software/flow/.flows_cred.json.backup +++ b/software/flow/.flows_cred.json.backup @@ -1,3 +1,3 @@ { - "$": "2b099099e7732ecc4498978f475755f6UU2zgPJFd8JcqdknMyuTvMxV11RG2zk=" + "$": "8a5830375d7cb047a920bc81b4cc476d+XU3NAfSPPxYBE1efxY1lIAusvuTCZCAU0damInvBBb4fzVvhMaUn60RLfr4AV7lMRCB2hbzc9MdqjzWd2JOC4ihNxhIKjYqZiqGAZ+dhJJ0U+FjxkCd" } \ No newline at end of file diff --git a/software/flow/README.md b/software/flow/README.md index 7d3b48c..128c9d5 100644 --- a/software/flow/README.md +++ b/software/flow/README.md @@ -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/). +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 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). +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 + * [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/) diff --git a/software/flow/docs/images/influx-connection.png b/software/flow/docs/images/influx-connection.png new file mode 100644 index 0000000..60a8ba1 Binary files /dev/null and b/software/flow/docs/images/influx-connection.png differ diff --git a/software/flow/docs/images/influx-data-explorer.png b/software/flow/docs/images/influx-data-explorer.png new file mode 100644 index 0000000..a3dcc5f Binary files /dev/null and b/software/flow/docs/images/influx-data-explorer.png differ diff --git a/software/flow/docs/images/influx-flow.png b/software/flow/docs/images/influx-flow.png new file mode 100644 index 0000000..c2a5e61 Binary files /dev/null and b/software/flow/docs/images/influx-flow.png differ diff --git a/software/flow/docs/images/influx-function.png b/software/flow/docs/images/influx-function.png new file mode 100644 index 0000000..a961a80 Binary files /dev/null and b/software/flow/docs/images/influx-function.png differ diff --git a/software/flow/docs/images/influx-node.png b/software/flow/docs/images/influx-node.png new file mode 100644 index 0000000..caa8f9b Binary files /dev/null and b/software/flow/docs/images/influx-node.png differ diff --git a/software/flow/flows.json b/software/flow/flows.json index 7cad056..dc5ff10 100644 --- a/software/flow/flows.json +++ b/software/flow/flows.json @@ -203,7 +203,7 @@ "usetls": false, "tls": "d50d0c9f.31e858", "influxdbVersion": "2.0", - "url": "http://influx:8086", + "url": "http://influxdb:8086", "rejectUnauthorized": true }, { @@ -289,7 +289,7 @@ "y": 480, "wires": [ [ - "7e53d20583f56487" + "16687c90623bdb9b" ] ] }, @@ -299,16 +299,52 @@ "z": "f6f2187d.f17ca8", "influxdb": "d61a7da6caeb26aa", "name": "Influx watt", - "measurement": "", + "measurement": "msg", "precision": "", "retentionPolicy": "", "database": "database", "precisionV18FluxV20": "ms", "retentionPolicyV18Flux": "", - "org": "ccl", + "org": "Curious Community Labs", "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, + "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": [] }, { diff --git a/software/flow/flows_cred.json b/software/flow/flows_cred.json index d0bceb6..baedee3 100644 --- a/software/flow/flows_cred.json +++ b/software/flow/flows_cred.json @@ -1,3 +1,3 @@ { - "$": "8a5830375d7cb047a920bc81b4cc476d+XU3NAfSPPxYBE1efxY1lIAusvuTCZCAU0damInvBBb4fzVvhMaUn60RLfr4AV7lMRCB2hbzc9MdqjzWd2JOC4ihNxhIKjYqZiqGAZ+dhJJ0U+FjxkCd" + "$": "61928af03edb50cc6aca62a484ad6ea92hejWh+gAvqCLSvWIF/BQNIS6vqKIgzteKjcP4UA1Ee/AWCUcFXPizdT6suUZ4Mf6vw8dbLcJnXduW+0c0f2dwGK5io0Z3ghS7rh4tA2XAgsyhMKA2DuI3z2Bl7O0znAZo390l6MK+btAysPNiWak4eScefUyhcZAmSYiuGo/A1OrlgYMe7gKPQYtwsSSVe07hO8W+uQBeoAC9JL4+CJeOwDOM70iz/kZdzfamdGY3K80iE3+GNwHmmP" } \ No newline at end of file