How to 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 "If 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". On the other side, 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 can have different fuel tank sizes). How can I adapt the fuel level signals to display the correct values (liters for example) for my 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.

  1. Enable the required properties for your applications
  2. Input the Custom Variables
  3. Set the Custom Variable to your vehicle/s
  4. Input your script in your device mapper
  5. Testing the script
  6. Result

Enable the required properties for your applications

You will require enabling the following properties in your application “Privilegies and Roles”:


Input the Custom Variables

To add a Custom Variables we need to go to the Vehicle Panel -> Manage Custom Fields

We are going to input different Custom Variables in a form of a list and we are going to set our different tank types with their properties

Set the Custom Variable to your vehicle/s

To add the new property to our vehicles we need to edit the User Type to add this new field

The new property is located under “User details”. We should check both check boxes to set this parameter as mandatory for future new units.

Define the value for each vehicle by editing the vehicle.

Input your script in your device mapper

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.

Now we have to select “4.Scripts”, click on “+ Add”, 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).

Some useful tips for your Javascript code:


  • 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’)
  • The following script, is Javascript, and is just an example of the transformation you can do to your input. You need to have some knowledge of Javascript or programming allowing you to create your own script.


    Testing the script

    You have some tools in the script editor to test your scripts. You can modify the Device Mapper variables 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 thanks to the Device Mapper scripting you can now 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

    Related guides

      Discuss this blog post on the forum please

    Download free GpsGate Server

    Install it on your own server. The installation is free for 5 users.

    Download Now