01/05/2024
How-to | ctrlX CORE | InfluxDB

IIoT: Use ctrlX CORE as a monitoring platform using InfluxDB and Grafana

The Goal

One of the most  requested IIoT feature of a machine is the capability to manage, store and visualize data. There are many ways to achieve this result, one of the best ways to achieve this goal is to combine three apps:

  • NodeRed: for connectivity

  • InfluxDB: data storage 

  • Grafana: Simple and standard HMIs

Edit

It's now possible to use the official influxDB app with external memory support 📲. Scroll down to the end 🚀

Let's see together how we can setup a basic example. 

ctrlX core InfluxDB and Grafana

Which data?
The data are coming usually from Ethecat, Opcua or third part devices here there is a brief list which will be updated:

Two ways

There are two possible configurations: 

  1. InfluxDB 2.x + Grafana + NodeRed 

  2. INfluxDB 1.8.3 + Grafana + NodeRed

There are not many differences, InfluxDB 2.0 it's an official ctrlX AUTOMATION app equipped with all the safety and platform features needed to setup reliable IIoT system. The only advantage in using InfluxDB 1.8.3 is the possibility to use the Grafana Auto-Complention features which can save some time. Chose the one you prefer considering that only the number 1 is the full supported by Rexroth.

Step 0 - Valid for both solutions

The first step in both cases is to setup NodeRed correctly how: 

  1. install NodeRed

  2. connect ctrlX CORE to internet and check that the system clock is correctly set

  3. download the InfluxDB palette as shown in the picture

ctrlX node-red-contrib grafana

 If everything goes stright we should find these three new nodes on the left:

InfluxDB nodes

Setup 1 - Productivity

What we need to install is: 

  • InfluxDB 2.x

  • Grafana

In the end the sideboard should look like this: 

ctrlx InfluxDB node-red grafana

Step 0 - Use an external memory (Optional) 

When the influxDB (and thus memory) workload is high it is necessary to use an external memory to save influxDB data. Here there are the steps we need to follow: 

  1. Navigate no setting ➡️ storage and locate youre device

  2. Format the device as an Ext4 device otherwise it won't work correctly in the long term.

  3. Mount it, it will be automatically mounted at boot

mount sd card ctrlx

 Now we need to go to the "Manage app data" menu, save the archive and edit the influxdb config file. W need to change the bold path and engine path to use our device. Once the file is saved we just need to upload the configuration on the device and update it. 

archive modification memory external

Here there is my file configuration example. usually mmcblk1p1 is for external microSD cards and sda1 stand for removable usb device. 

Influxdb ctrlX external memory

NOW REBOOT!!!

Step 1 - Setup influx

Go to the influx page clicking the icon on the left:

Welcome to InfluxDB

 Setup the Initial use and the first Bucket, in this guide we just use boschrexroth as anything:

Setup initial user

 Go to Data API Token:

API Tokens

Just copy and keep secret the autogenerated token:

API Tokens

we're done here! Let's move forward!

Step 2 - Setup Node-Red

Load the example in NodeRed and open up the InfluxDB node!

Be sure to parametrize the node as follow: 

In the server configuration is important to insert the token created before and insert the right URL:

But.. What does this example do? It's simple, basically creates a set o three random values that are then joined together to create a set of values loaded inside InfluxDB. 

If we come back to InfluxDB and we select Explore, boschrexroth, Drive1 (the default measurement), all the fields and finally apply we can see the data flowing inside the database!! great no?

Data Explorer

Step 3 - Connect Grafana

We're almost done, we just need to connect Grafana. Nothing more simple! Lets do it!

Just open up Grafana, login with admin as user and admin as password then move to settings and then Data sources:

Data sources

Select obviously InfluxDB then in the configuration Flux as query language.

ctrlX setup ctrlx grafana flux

ctrlx setup grafana InfluxDB

 The rest of the configuration is just like the NodeRed node! The click save and test!

ctrlX setup grafana InfluxDB token

 Ok almost done, create the first dashboard and then click the "add panel button": 

ctrlx grafana new dashboard

ctrlx grafana new dashboard

Ok now the panel asks for a query don't go mad.. Work smart not Hard!!

InfluxDB ctrlx grafana

Go back inside InfluxDB and open up the script editor, copy the query inside the panel and save!

ctrlx InfluxDB2 query

grafana ctrlx first dashboard

First Panel completed!!

Setup 2 - Alternative (not official)

What we need to install is: 

  • InfluxDB 1.8.3

  • Grafana

In the end the sideboard looks like this:

simple ctrlx apps grafana nodered

By default InfluxDB 1.8.3 has no frontend so, there is no icon on the sidebar.

Step 1 - Setup influx and NodeRed

How? load up the NodeRed example and deploy it!

ctrlx InfluxDB 1.8.3

What is happening? 1 si creating the database trough REST API 2 is setting up  a proper retention policy and 3 is creating random data!

Step 2 - Setup Grafana

Just open up Grafana, login with admin as user and admin as password then move to settings and then Data sources:

Data sources

Important! keep InfluxQL as Query language! and setup the url like this!

ctrlX setup grafana InfluxDB

This setup has not security active, use the firewall app to protect InfluxDB! Insert drivedata as database (the example creates this automatically).

ctrlx setup grafana InfluxDB

Ok almost done, create the first dashboard and then click the "add panel button": 

ctrlx grafana new dashboard

ctrlx grafana new dashboard

Now we just need to select what we would like to see, it's far more easy in this case!

ctrlx grafana dashboard

Extra Step - Create PDF Report

For this step we will need to download pdfbuilder node as shown below:

ctrlX platmac-node-red-pdfbuilder

Import the nodes from the attachment:

pdfbuilder node

  1. We need to configure influxdb in node and insert the query, here we can specify the start and the end time of the data that needs to be extracted from our database:

influxdb in node

  1. Next step is a Javascript function to extract the data from our query and push it to the table:

javascript function

  1. How do we create the PDF now? Just drag the pdfbuilder node and change the output type to Buffer:

    pdfbuilder node

  1. Now we want to store the report in Ctrlx Core, so let's specify the path using write file node:

write file node

Ready to go! Just deploy and activate the inject node!

Let's check where is the file now, navigate to the app data:

app data

Open the Node-RED configuration:

node-red configuration

Inside we have a newly created folder called Reports with our pdf Report stored inside, download it:

pdf report

You can open the file and check the result:

pdf report

Feel free to modify the JS code to format it based on your needs!

10
exampleInfluxgrafana.zip
3.16KB
exampleinfluxreport.zip
1.75KB
Types
How-to
Products
Drives
IOT

Latest published/updated articles