Variable notifier: count SOS events
This article describes how to use variable notifiers to count the number of SOS events and assign it to a variable that you can display later on the screen as a column.
- NOTE: You need to map the SOS signal in your device mapper in order to use this example.
Setup
1. Create an event rule.
2. In step 4. Expression, select Script Expression.
3. Edit your script expression by pasting this Javascript Code:
var state = context.state || {sos:false, counter:0};
var sos = fields.get('SOS', false);
if (sos && !state.sos)
state.counter++;
state.sos = sos;
context.setState(state);
context.setVariable('sos_sum', state.counter);
return sos;
4. In step 5. Notifications, use the Variable notifier option.
5. In Source, set [sos_sum] and in Target, select a variable of your choice (for example, Custom Analog3).
- Note that the variable [sos_sum] is the same variable we're setting in the script in the line context.setVariable('sos_sum', state.counter); This means that we will pass this value to the variable notifier to be saved in the vehicle information every time an SOS is detected.
- In this script sample, we count only when SOS = True the first time. If the tracker sends another SOS = True after the first one, the 2nd instance is not counted. The status of SOS needs to go back to False before the counter acts again.
6. Save your event rule.
Result
Every time an SOS event is detected, it's going to be saved in the variable Custom Analog 3 you can add in the vehicle's panel or in the track points as information.