Connect with FRED
Now that we have a database and database users set up, we’ll use the Node-RED InfluxDB nodes to connect to the service using FRED. First, we will create a flow that publishes messages to a topic on the service.
We will first config an InfluxDB out node to write data to InfluxDB. Drag an InfluxDB out node to the editor canvas, and double click on the node to edit the configuration tab.
We will add new InfluxDb server configuration by clicking the edit button.
Next, we enter the STS-InfluxDB URL in the host field and the database username and database user password that we created previously in the username and password field of the InfluxDB node config tab. The default port number is 8086.
The SSL is enabled on STS-InfluxDB. We will have to provide an TLS configuration. Check the checkbox “Eanble secure (SSL/TLS) connection” and create a new TLS configuration like the following. You do not need to provide any client certificate information.
Click the update button when you are finished.
Next, enter a measurement name for collecting some sensor data. Let’s call the measurement “test”.
We can test writing some random sensor data to the measurement “test”. Let’s drag an inject node and a random node (You will need to install the random node if you don’t have it in your node list. Please refer to Node Package Installation. Let’s set the random node to this:
Now connect the inject node, the randome node and the InfluxDB out node. Your flow should look as follows:
Now, clicking on the inject node should allow you to write a random float number to your InfluxDB instance under measurement “test”.
We will drag an InfluxDB in node to query data from our InfluxDB instance. We first drag an InfluxDB in node to the editor. Double click on the node to edit the configuration tab.
Click to add new server, we will be using the user with read privilege. Then, in the query field, we will enter
select * from test. This will return all the value from the measurement that we had used in the previous example.
Connect an inject node before the InfluxDB in node, and a debug node after the InfluxDB node:
When you inject the flow, you should see the debug node showing the returned query result:
Note: Despite its name in the InfluxDB configuration, do not put your STS service credential in the Username and Password field. Put the database user credential in these two fields.
Next, we had successfully connect your FRED instance with your InfluxDB database. We will see how we can use the web query tool to query data next.