Use the Expression Processor Function
You can use a single input or multiple inputs to create a mathematical expression with your desired topic.
Single inputs use events or values-type connection and multiple inputs use only values-type connection.
Review the following scenario for the expression processor function. Then, you will simulate PLC data and calculate mathematical expression outputs using the expression processor function.
In a cold storage facility, maintaining the right humidity levels is crucial for preserving the quality of perishable goods. An alert system needs to be in place to signal if the humidity goes beyond the acceptable range.
Expression for Humidity Alert: (Humidity_value < 30 || Humidity_value > 50) ? "Alert: Humidity Out of Range" : "Humidity Normal"
In a solar power plant, it's essential to constantly monitor the efficiency of solar panels to ensure optimal energy production. Efficiency can be calculated based on the ratio of the output power to the input solar radiation, along with the surface area of the solar panel.
Expression for Efficiency Calculation: (P_value / (S_value * Area_value)) * 100
Follow the steps to Connect a Device and configure the following parameters:
- Device Type: Simulator
- Driver Name: Generator
- Enable Alias Topics: Select the checkbox.
After connecting the device, add the following tags. See Add Tags to learn more. Each tag will represent one of the user scenarios noted above.
- Name: Select S - Random value generator.
- Value Type: Select int64.
- Polling Interval: Enter 5.
- Tag Name: Enter Humidity.
- Min Value: Enter 25.
- Max Value: Enter 55.
- Name: Select S - Random value generator.
- Value Type: Select float64.
- Polling Interval: Enter 5.
- Tag Name: Enter Power.
- Min Value: Enter 75.
- Max Value: Enter 100.
- Name: Select S - Random value generator.
- Value Type: Select float64.
- Polling Interval: Enter 5.
- Tag Name: Enter Solar_Radiation.
- Min Value: Enter 50.
- Max Value: Enter 75.
- Name: Select S - Random value generator.
- Value Type: Select int64.
- Polling Interval: Enter 5.
- Tag Name: Enter Area.
- Min Value: Enter 250.
- Max Value: Enter 500.
You can now create the analytics flows using data from the device and tag you previously created. Follow the appropriate step out of 3a or 3b based on the two user scenarios for the Expression processor function you want to use.
- Navigate to Analytics.
On the analytics canvas, click Add processor. The Create a processor dialog box displays.
- Select DataHub Subscribe.
In the Topic field, click the Search icon, select the device you previously created, and then select the alias topic for the Humidity tag.
- Click Save.
- Click Add processor again and select Expression processor. The following information defines this function:
- Expression: Enter the mathematical expression from the user scenario 1. You must define the connection of the input tag as a variable name (Humidity) and then use that in the mathematical expression (such as Humidity_value).
- Output Field Name: Enter value as the field to appear in the output.
Click Save.
- Connect the DataHub Subscribe processor (tag: Humidity) to the Expression processor with a wire and enter the definition of Humidity for the value-type connection.
- On the analytics canvas, click Save.
The configured analytics flows should look like the following:
- Navigate to Analytics.
On the analytics canvas, click Add processor. The Create a processor dialog box displays.
- Select DataHub Subscribe.
In the Topic field, click the Search icon, select the device you previously created, and then select the alias topic for the Power tag.
- Repeat steps 2-4 in Step 3b to add another DataHub Subscribe node. Select the alias topic for the Solar_radiation and Area tags, respectively.
- Click Save.
- Click Add processor again and select Expression processor. The following information defines this function:
- Expression: Enter the mathematical expression from the user scenario 2. You must define the connection of the input tag as a variable name (P, S, Area) and then use that in the mathematical expression (such as P_value, S_value, and Area_value).
- Output Field Name: Enter value as the field to appear in the output.
Click Save.
- Connect the DataHub Subscribe processor (tag: Power) to the Expression processor with a wire and enter the definition of P for the value-type connection.
- Connect the DataHub Subscribe processor (tag: Solar_Radiation) to the Expression processor with a wire and enter the definition of S for the value-type connection.
- Connect the DataHub Subscribe processor (tag: Area) to the Expression processor with a wire and enter the definition of Area for the value-type connection.
- On the analytics canvas, click Save.
The configured analytics flows should look like the following:
Click the View icon in the Expression processor to view the output values.
The expression function calculates the humidity from the defined tag values and gives the output for the mathematical expression.
The expression function calculates the efficiency from the defined tag values and gives the output for the mathematical expression.