Use the Switch Processor Function
In this guide, we will use the Switch Processor Function to manage the flow of data. You will understand the various rules applicable to the switch processor, how input messages are evaluated, and the significance of output filtering.
- Get familiar with different rules of Switch processor. The rules for comparison are done through GoLang strings.compare functions.
Review the following scenario for the switch processor function. Then, using an input processor, you will simulate PLC data, apply certain rules from the Switch processor, and then output only when rule checks are met.
In a manufacturing plant, you can use the Switch Processor to evaluate incoming messages from sensors that detect product specifications, such as tags and weight. When a sensor reports a product that exceeds a predetermined threshold or set conditions, the Switch Processor checks this input against the available rules.
If the condition is met, floor operators can be notified to inspect the assembly line for potential issues or alternatively an alert can be triggered. In this way, the Switch Processor helps ensure that only products meeting quality standards proceed down the production line, minimizing waste and enhancing overall operational efficiency.
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 tag. See Add Tags to learn more.
- Name: Select S - Random value generator
- Value Type: Select string
- Polling Interval: Enter 1
- Tag Name: Enter TT1
You can now create the analytics flows using data from the device and tag you previously created.
To create an analytics flow with the Switch Processor function:
- In Litmus Edge, 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 TT1 tag.
- Click Save.
- Click Add processor again and select the Switch processor. The following information defines this function:
- Rule: The Rule specifies the condition to be checked. For this example, we select contains rule from the drop-down menu.
- Field Name: The Field Name indicates the specific field in the input message for comparison. For this example, we input value as field.
- Check Value: The Check Value is the value against which the Field Name is evaluated. For this example, we want 'h' value to check for.
- Check Value Type: The Check Value Type defines the expected data type of the Check Value. For this example, we input a value of 4.
- Output (Optional): The Output determines where the result will be published or if it goes to all connected processors if left empty.
Click Save.
- Connect the DataHub Subscribe processor (tag: TT1) to the Switch processor with a wire and use the events connection.
- On the analytics canvas, click Save. The configured analytics flows should look like the following:
Click the View icon in the Switch processor to view the output values.
You can see the values that contain the letter 'h' in the specified field are displayed in the output.