Combine Custom Variables and Device Mapper Scripting
In this guide, we want to demonstrate a real-life use of custom variables and device mapper scripting. Device mapper scripting can solve problems of the sort "I have one or more input signals from my GPS device and I want to decide what to do in the output using different formulas." Custom Fields allow us to assign non-standard properties to our vehicles/units like registration number, fuel tank size, vehicle color, etc.
A practical case using both solutions would be, for example, if we have different fuel tanks in different vehicles (vehicles of the same type can have different fuel tank sizes). You can adapt the fuel level signals to display the correct values (liters for example) for your fleet. The difference between non-linear mapping is that in this case we will use a vehicle property and a GPS input to generate the correct output.
- Enable the required properties for your applications
- Input the Custom Variables
- Set the Custom Variable to your vehicle's value
- Input your script in your device mapper
- Testing the script
Enable the required properties for your applications
1. Read how to access Privileges and Features of an application and enable the following two roles:
Input the Custom Variables
1. To add a Custom Variables, we need to go to the Vehicle > Manage Custom Fields
2. Add a new variable of the type List called Fuel_Tanks and add the three different types and its values:
Set the Custom Variable to your vehicles
1. To add the new property to our vehicles, we need to edit the User Type to add the custom field:
The new property is located under Details of the user properties.
2. Check both checkboxes to set this parameter as mandatory for future new units.
3. Define the value for each vehicle by editing the vehicle.
Input your script in your device mapper
1. Go to Admin > Device Mapper and select the correct device for your vehicles. The input signal we want to modify with our script needs to be mapped here.
In the example, the input signal will be the Fuel level which is giving the number of Volts that reflect the capacity of the tank for the given vehicle.
2. Select 4.Scripts, click on + Add,
3. Select the Output signal (in this case the same as the input because we need to transform the volts to liters depending on the type of tank).
- To get a variable from the Device Mapper use fields.get(‘device_mapper_variableName’, default_value)
- To get a variable from the Custom Fields use user.getCustomFieldValue(‘custom_field_label’)
- To log entries to allow you to debug your codes use log(‘variable_name’)
Testing the script
You have some tools in the script editor to test your scripts. You can modify the Device Mapper variable values and use the logs in the code to verify if the result is correct
You can finally see the changes in your Tracking Points for a given vehicle when the signal Fuel level is received. And with the Device Mapper scripting, you can have these values converted, for example, to liters (using the Tank type defined in the vehicle properties)
You can always make your tests within the Script Editor or if you want to submit signals to the platform to see the response you can also use SimOne.