Software

February 10, 2024

Introduction to Grafana

It is used to graph and monitor the data stored in InfluxDB. 

Basic graphing data

In the dashboard, click on the top bar of a graph and select edit. 

In the lower half of the screen there will be an area to change the rules for the graph. Click on the pencil on the right side and delete the default code.

Replace it with:

SELECT * FROM “DataTypeToGraph”

This will graph the data added to the database by a single InfluxDB node in Node-RED using the tag it was defined with.

Basic tabling data

In a new dashboard, under the sql code, from the dropdown select “Table”. After that select Table view from the tab on the right called Format. This should table each entry in the database instead of graphing it.

Use this SQL code to show only the last value recorded:

SELECT last(value) FROM “Data”

Show average in table

SELECT sum("value") / count("value")
FROM "Data"
WHERE $timeFilter
February 10, 2024

Introduction to Node-RED

Node-RED is a visual programming tool that allows users to create and connect hardware devices, APIs, and online services. It uses a web-based flow editor to drag and drop nodes, which represent different functionality, to create automated workflows. It simplifies the process of building Internet of Things (IoT) applications by providing a user-friendly interface for connecting and controlling devices.

Debug Node

The debug node is a built-in Node-RED node that allows users to view the message passing through the nodes in real-time. It is useful for troubleshooting and understanding the flow of data through a flow. 

Users can view the contents of the message, filter messages by type or topic, and output messages to the console in the sidebar. It is easy to use by simply dragging and dropping it into the flow and connecting it to other nodes.

The green square on the right means it will debug. Pressing it will stop the node from debugging without deleting it.

Debug On:

Debug Off:

Aventics Node

This node is used to access the sensors and values in the system.

The node looks like this:

Aventics Node Modules

  1. 01 Valve driver 4 valves – Controls the pneumatic distributors.
  2. 03 IO-Module dig. (8DI8M8) – Digital sensors module. It is connected to 8 magnetic sensors each situated at the end of every piston on the stand. Each address of the module is a different sensor output. In the software they are numbered from 1 to 8 but on the plastic module they are labeled from 0 to 7.
  3. 04/05 IO-Module ana. (2AI2M12-E) – Analog sensors module. Each module has 2 analog sensor inputs.

Parameters:

  • Topic – Cosmetic name of node for internal use only. It doesn’t affect other functionality.
  • Function – Determine how the data should be pulled from the sensor.
  • From – Select which sensor it pulls data from. Each address is a different sensor in the selected module.
  • Poll interval – The minimum delay between each reading. The sensor sends data each time it changes states. This will only delay the next reading. For x seconds it will not send any data after some data was sent.

Function Node

This node uses Javascript to transform data or use any other js function. 

To access the value in the input use msg.payload and change it for output value. Use return msg to output.

Airflow function

After the aventics node that takes data from the airflow sensor (04 IO-Module, address 01) place a function with this code. It will output the current airflow in L/min. 

Sensors give an analog signal to node red, usually from 0 to 32767. Each sensors needs to be calibrated. Our sensors outputs 0 when there is no airflow and using the built-in settings of the sensors we can see the max airflow going through the sensors was 315,43 L/min and it outputted a values of 2742. So by dividing it we can calculate a transfer equation.

msg.payload *= 0.115;
return msg;

Speed function

After the aventics node that takes data from the linear analog sensor (05 IO-Module, address 2), place a function node with this code. It will output the current speed of the cylinder in cm/s.

// This function node counts the time between two signals that are equal to 1
var lastTime = context.get('lastTimestamp');
var lastPos = context.get('lastDistance');

if(msg.payload 3200) {
	msg.payload = (msg.payload - 3200.0) / (29750.0 - 3200.0) * (51.1 - 7.13) // cm/s
    
	if (!lastTime) {
    	// Store the timestamp of the first 1 signal
    	lastTime = new Date().getTime();
    	lastPos = msg.payload;
    	context.set('lastTimestamp', lastTime);
    	context.set('lastDistance', lastPos);
	} else {
    	if (lastPos == msg.payload)
        	return
   	 
    	// Calculate the time difference between the first 1 signal and the current 1 signal
    	var deltaTime = new Date().getTime() - lastTime;
    	var deltaPos = msg.payload - lastPos;
   	 
    	context.set('lastTimestamp', null);
    	context.set('lastDistance', null);
    	msg.payload = (deltaPos)/(deltaTime);
   	 
    	return msg;
	}
}
return null;

InfluxDB Integration

The simple InfluxDB node takes whatever data it is given and along with a tag it is sent to the database along with a time stamp.

Select the second Server for data to be logged.

Each time a new piece of data is added to the database it will automatically get a timestamp when it was logged. 

Parameters:

  • Measurement – Name of the date stored and used for identification with SQL. 

Join Node

Every connection between the nodes sends a message msg with different parameters. Two of the most important ones in this node are msg.payload and msg.topic. 

msg.topic = “Name of the variable transported”

msg.payload = value of the variable transported

Using the Join Node, we can combine multiple variables into a single object. Like a json, each item in the object has a name (from the topic) and a value (from the payload). 

With this node, we can combine all the data and send it to a single influxDB node as a single table entry instead to keep the data organized. 

Parameters:

  • Mode – Automatic, Manual (usually preferred option)
  • Combine each – Choose which parameter to be the value of each item
  • to create – Output type of the node (usually Object)

Manual Mode parameters:

  • using the value of – name of each item in the Object
  • After a number of message parts – Number of item the node should wait for to output an object