How-To Guides
Analytics Guides

Use the Switch Processor Function

7min

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.

Before You Begin

  • Get familiar with different rules of Switch processor. The rules for comparison are done through GoLang strings.compare functions.

User Scenario

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.

Step 1: Add a Device

Follow the steps to Connect a Device and configure the following parameters:

  • Device Type: Simulator
  • Driver Name: Generator
  • Enable Alias Topics: Select the checkbox.

Step 2: Add Tags

After connecting the device, add the following tag. See Add Tags to learn more.

Tag 1: TT1

  • Name: Select S - Random value generator
  • Value Type: Select string
  • Polling Interval: Enter 1
  • Tag Name: Enter TT1

Step 3: Create Analytics Flows

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:

  1. In Litmus Edge, navigate to Analytics.
  2. On the analytics canvas, click Add processor. The Create a processor dialog box displays.

    The Add processor option
    The Add processor option
    
  3. Select DataHub Subscribe.
  4. In the Topic field, click the Search icon, select the device you previously created, and then select the alias topic for the TT1 tag.

    Create a Processor dialog box
    Create a Processor dialog box
    
  5. Click Save.
  6. 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.

      Edit a processor dialog box
      Edit a processor dialog box
      
  7. Connect the DataHub Subscribe processor (tag: TT1) to the Switch processor with a wire and use the events connection.
  8. On the analytics canvas, click Save. The configured analytics flows should look like the following:
Completed flows canvas
Completed flows canvas


Step 4: View Output of Processor

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.

Switch Processor Output
Switch Processor Output