3

It is quite a while since I coded something and it is the first time I am dealing with Influxdb and NodeRED. I am acquiring four sets of measurements from a sensor connected to a Pi. This is a screenshot taken during the debug, the measurements are coming trough.

enter image description here

I managed to get the data from the sensors into NodeRED:

enter image description here

The problems I am facing are:

  • how to structure the table (measurements) in InfluxDB and get those data into the right column;
  • and how/where to define the sample interval to avoid millions of data into the db?

I will later on try to connect the DB with Grafana and it is all new for me. Any help is appreciated.

FeliceM
  • 4,163
  • 9
  • 48
  • 75

1 Answers1

1

First, add a function node at the end of each sensor node and save the output as variable. The code will vary greatly depending how you are getting your sensor data, but here is how I do it:

msg.payload = Number(msg.payload);
flow.set("presion_agua_psi",msg.payload);
flow.set("sensor_presion_agua","Wemos D1");
return {payload: msg.payload};

In example below, I am using MQTT to send the sensor data Sensor node

Then, separately, use an inject node and set it to repeat every xx minutes. This is the timeframe you will use to actually save the data into influxDB.

Inject Node

After the inject node, add a function node that creates a dictionary, using the variable name and its value. This will make sure your columns in influx are stored with a name.

Once again, the code will vary, but here is an example:

msg.payload = { 
    Timestamp:date, 
    Device:flow.get("sensor_nivel_agua"), 
    Nivel_Agua_Tinaco:flow.get("Agua_Tinaco"),
}

return msg;

Finally, add your influxDB credentials and debug to make sure the data is getting stored correctly.

Portfedh
  • 178
  • 1
  • 13