Skip to main content

Scripted Signals

A scripted signal is a signal that is computed on the fly as defined by a script, unlike signals described in a signal database.

For example, let's imagine that you want to subscribe to the value representing the percentage of battery remaining in your vehicle, however, your signal database only defines signals for remaining battery capacity and total battery capacity.

With a simple Lua script, it is possible to define a scripted signal that returns the battery percentage. You can find an example of such a script in our samples repository: Vehicle.Powertrain.TractionBattery.StateOfCharge.Displayed.lua.

Defining a scripted signal

To get an idea of how to define scripted signals, investigate example code in our samples repository together with RemotiveCloud Demo or with your own broker.

There are three things that need to be put in place:

Simple mappings

Let's say you wish to subscribe to a signal named Vehicle.Speed, but your signal database names it as ID257DIspeed.DI_vehicleSpeed.

One option is to create a Lua script that will simply pass the same value of ID257DIspeed.DI_vehicleSpeed under a new name.

A more convenient way is to use a feature called "simple mapping". When the only computation you wish to perform is to rename a signal, you can define the mapping between old and new names in the scripted signals database JSON file. Take a look at an example for inspiration.

Changing frequency of signals

A specific kind of computation you can perform with scripted signals is to change the frequency of emitted signals.

Let's say you wish to change the frequency to 10 updates per second. Take a look at an example script for inspiration on how to achieve that.

Video guide on how to iterate to create a custom signal with a Lua script

Scripted signal, video tutorial

Scripted signal, video tutorial