Use the Change Processor Function
You can use the Change Processor Function to alter incoming messages based on specific parameters and requirements. You can assign new values, update existing information, or restructure data for better organization.
This guide explains the different operational modes in the Change Processor Function using a real-world scenario with tags and devices in Litmus Edge.
The Change Processor Function offers several operational modes, each tailored for specific types of modifications:
- Set Mode: This mode lets you directly replace a specified field's value. When the Change mode is set to "set," the input value overwrites the existing content in the designated message field.
- Change Mode: This mode enables complex string manipulations. It operates differently depending on the data type of the input field:
- For string or JSON fields, it will search for all occurrences of the specified Value within the field and replace them with the Replace Value. Both Value and Replace Value will be treated as strings during this operation.
- For other data types, the processor looks for an exact match between the Value and the field. If a match is found, the field content will be replaced with the Replace Value.
- Delete Mode: This mode is used to remove specified values from the input field entirely. When set to "delete," it eliminates the designated content.
- Move Mode: This mode takes the modified content from one field and relocates it to another field within the same message.
Review the following scenario for the change processor function. Then, you will simulate PLC data and modify incoming messages using different modes of change processor function.
In a manufacturing facility, a sensor sends messages ['heat', 'humidity', 'temperature'] with machine status reports. A technician can use the Change Processor Function to optimize this data in the following way:
- In Set Mode, they update the deviceName field from "Test Device" to "Validation Device" during production runs.
- In Change Mode, they replace all occurrences of "heat" with "Heating Problem" in maintenance reports.
- In Delete Mode, they remove outdated deviceID field that no longer apply.
- In Move Mode, they transfer the updated values from the Value field to a new Updated Values field.
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. Only one tag will be used for simulating the different Switch processor outputs mentioned above.
- Name: Select S - Random value generator
- Value Type: Select string
- Polling Interval: Enter 5
- Tag Name: Enter TT1
You can now create the analytics flows using data from the device and tag you previously created. Choose the appropriate step from 3a, 3b, 3c, or 3d based on the desired mode of the Change Processor Function.
To create an analytics flow with the Change Processor function:
- 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 Change. The following information defines this function:
- Mode: Select set from the drop-down menu.
- Input Field: Enter deviceName.
- Input Value Type: Select string from the drop-down menu.
- Input Value: Enter Test Validation.
Click Save.
- Connect the DataHub Subscribe processor (tag: TT1) to the Change 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 Add processor again and select Change. The following information defines this function:
- Mode: Select change from the drop-down menu.
- Input Field: Enter value.
- Input Value Type: Select string from the drop-down menu.
- Input Value: Enter heat.
- Replace With Value Type: Select string from the drop-down menu.
- Replace With Value: Enter Heating Problem.
Click Save.
- Connect the DataHub Subscribe processor (tag: TT1) to the Change 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 Add processor again and select Change. The following information defines this function:
- Mode: Select delete from the drop-down menu.
- Input Field: Enter deviceID.
- Input Value Type: Select unit from the drop-down menu.
Click Save.
- Connect the DataHub Subscribe processor (tag: TT1) to the Change 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 Add processor again and select Change. The following information defines this function:
- Mode: Select move from the drop-down menu.
- Input Field: Enter value.
- Input Value Type: Select string from the drop-down menu.
- Move To Field: Enter Updated Value.
Click Save.
- Connect the DataHub Subscribe processor (tag: TT1) to the Change 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 Change processor to view the output values.
The Set mode assigns the Test Validation string to the deviceName field.
The Change mode switches the occurrence of heat string in the Value field with the Heating Problem.
The Delete mode removes the deviceID field from the message.
The Move mode transferred the Value field to the new Updated Values field in the message.