Device Mapper Scripting example: modify an input with a script
In this example, we will show you how to modify a mapped variable (input) and generate a new value as an output.
You can imagine the situation where you want to alter the original Temperature value of your device and make calculation: for example, divide it by 10.
Steps to change an output of a variable using scripting
1. First map to the Variable of your choice in the device mapper (in this example, we will use Temperature).
2. Now this Temperature should be used as an output in the Scripting section (the script will be applied to this variable).
The following image shows the result of choosing this output for the script. Follow the steps described until you get the same configuration as in the image.
3. Press on Open Script Editor button
4.. Now you need to paste the code in the editor and test the script. Follow the steps in the image.
The following example code is quite simple, but it does the job of dividing the original temperature input by 10.
var temperature = fields.get ('Temperature', 0);
log('original temperature value: '+ temperature);
temperature = temperature / 10;
return temperature;
Note: you need to add the variable to the list of fields if you want to test your code. You can also use the device simulator to generate sampling data for the script.
4. Save the device mapper script.
5. Save the device mapper configurations