====== First steps with your NIG ======
==== What you will need ====
* A browser
* Your personal URL
* Your personal node-red username and password
* Your personal grafana username and password
==== How it works ====
All NIG-Environments (N=nodered, I=influxdb, g=grafana) are running in [[https://www.docker.com/resources/what-container|Docker-Containers]] on the eolab-server. Only the nodered UI and the grafana UI are accessible from the outside. Internally both services can access the influxdb. Probably you will not know what each service is so you can just read on and we will explain what they are and why you need them.
=== What is node-red ===
[[https://nodered.org/|Node-RED]] is a UI programming tool for writing code with just graphical blocks. With this, you can easily wire together hardware devices with APIs and other online services. Node-RED is all about flows. A flow is really what it says it is. The data flows from an entry point (like MQTT or HTTP) to an endpoint. On the way, you can modify, compare it with other data, or do whatever you want to do with it. The endpoint could also be an outgoing MQTT-Message or HTTP-Request. In our case, you will probably want to save it permanently in the given influx database and later display it in some way (that is what grafana is for).
* [[https://nodered.org/docs/|Documentation (with a getting started and some tutorials)]]
=== What is grafana ===
[[https://grafana.com/|Grafana]] describes itself as the
> The analytics platform for all your metrics
With grafana, you can query the data from the database and show it off in graphs. You can also create alerts. So when you want to get a notifications when let's say a value gets above a certain threshold, grafana can do that for you. You can find more information here:
* [[https://grafana.com/docs/grafana/latest/getting-started/what-is-grafana/|What is Grafana?]]
* [[https://grafana.com/docs/grafana/latest/getting-started/getting-started/|Getting started]]
=== What is influxdb ===
[[https://www.influxdata.com/|Influxdb]] is a time series database that is really good designed for IoT applications. It can handle very high write and read loads. It's very easy to use because the used InfluxQL query language is somewhat close to SQL. But you can learn more about it here:
* [[https://www.influxdata.com/products/influxdb-overview/|InfluxDB]]
* [[https://docs.influxdata.com/influxdb/v1.8/guides/|Some Guides]]
==== Connecting all Services with influxdb (only setup shown) ====
All groups only have one admin user. Both for Node-RED and Grafana. When someone changes the password, please inform the other people in your group about it!
=== Connect node-red with influxdb ===
- Open the node-red URL provided in the email and log in with the provided username and password. You will now see an empty flow.
- We have to install some special nodes (nodes are the blocks you use for programming) for interacting with the influx database. Click on the burger-icon in the top right corner. You will find an option named "Manage palette", click it. In the palette, you can manage all plugins you currently have installed. You will now see all currently installed nodes/plugins.
- Click on "Install" in the top bar and search for "influxdb". You will find one named "node-red-contrib-influxdb". Click on the "Install"-button to install it.
- You can close the palette now. On the left side of your screen, you can find all nodes that are available to you. Scroll down until you find a node called "influxdb out". You can also search for it in the top left corner. When you found it just drag it somewhere into your flow.
- Now double click on the node you just dropped. Because you never used it you will have to connect to a new server. Just click on the little pen on the right side of "Server". Here you will have to type in all needed information. These are the same, nevermind the group you are in.
* Host: influxdb
* Port: 8086
* Database: db
* Username: db
* Password: db
* do **not** enable SSL
* Name: makeup something nice
- Click on save. The database is now saved in node-red and you can use it on every influxdb-node you want to. If you want to, you can delete the node we just created.
The influxdb is only accessible by nodered and grafana. Don't mind the weak password and username.
=== Connect grafana with influxdb ===
- Open the grafana URL provided in the email and log in with the provided username and password. You will have to change your password on the first login.
- We just need to add the influxdb as a data source. Find the gear icon on the left side and while hovering over it select "Data Sources".
- Click "Add Data Source". In the first part under "Time series databases" you will then find "influxDB". Select it.
- You will just have to change a few things. Copy all the values provided here:
* HTTP
* URL: influxdb:8086
* InfluxDB Details
* Database: db
* User: db
* Password: db
* All other values can be left as default
- Click "Save & Test". You will see a message "Data source is working". You successfully added the influxdb.
==== Sample project ====
For the sample project, we will just let nodered put some values into the influxdb and read them afterward inside of grafana. Make sure you have done the steps under "Connecting all Services with influxdb"!
- Node-RED Part:
- Open up your nodered
- Drag an "inject"-node into your flow.
- Edit it with a double-click. As a payload, we just want a number. Type in a number you want. The topic is a value that we will be sent with the value you have chosen. The nodes communicate under each other with message objects as JSON-Objects. The payload is the raw data you want to work with. The topic is just another value inside this JSON-Object. My topic is just named "testing". We also want that the value gets injected like every 5 seconds. Just for testing of course. The name property you also see is the name you can see inside the flow.
- Now we only need a node that sends the value to the influxdb. Drag and drop the "influxdb out"-Node into your flow. Choose your influxdb-server and name the measurement also testing. Under this name, you will later find it inside of the database. Click on Done and connect the two nodes with each other. This is your first flow.
- The last click on deploy in the top right corner and the node-red server is already injecting something into your database.
- Grafana-Part:
- Open up your grafana
- Create a new dashboard by hovering over the "plus"-icon on the left side of the screen and click "Dashboard"
- Click "Add new panel". Panels are generally graphs you want to display in one dashboard. One dashboard consists of many panels.
- What you will see now can be a bit overwhelming at first but we will just do a little dip into it right now. To display data in our graph we have to query it from our influxdb. We will just need one query for this sample project.
- We just need to change one thing right now. Under query, you will find a row named "FROM". We want to show the measurement from our database from the table named testing. So click on "select measurement". There should be a drop-down where you can select from all currently existing measurements. Choose "testing".
- On the right side of the screen, you can change the panel title if you want. Otherwise, click on Apply in the top right corner.
- You now need to save the dashboard you just created. In the top right corner, you will fond a save icon. Give it some appropriate name and click "Save".
- You just finished the sample! You can now see the dashboard on the grafana home screen. You can click the name to display it.