gn02054810
Posts: 6
Joined: Thu Jun 14, 2018 1:04 pm

Event rule script odometer issue

Fri Dec 28, 2018 4:47 am

Hi everyone,

I have try to get the previous odometer but it not get any value of odometer .

any problem?

Code: Select all

var limit = 15;
var trigger = false;
//var previous = context.state;
var currentFuel = fields.get('FuelLevelPercent',0);
var odometer = fields.get('_Odometer',0);
var satCount = fields.get('SatelliteCount',0);
var speed = fields.get('Speed',0);
var currentFuelLevel = fields.get('Fuel level',0);

var odo;

var st = context.state || {
lastFuel: currentFuel,
lastOdo: odometer,
lastLiter: currentFuelLevel,
lastRefillOdo:''
};

log(currentFuel);
log(odometer);
log(currentFuelLevel);

if(!st) context.setState(st);		 //&& speed <1.39

else {
     var diff = currentFuel - st.lastFuel;
  	
    context.setState(st);

  if (diff > limit && currentFuel>0 && st.lastFuel>0) {

	var refillOdo = odometer - st.lastRefillOdo;
	context.setVariable('refillOdo',refillOdo);
	context.setVariable('lastRefillFuel',st.lastFuel);
	context.setVariable('startRefillFuel',st.currentFuel);
	context.setVariable('startRefillFuelLiter',st.lastLiter);
	context.setVariable('lastRefillOdo',st.lastRefillOdo);
	

	st.lastRefillOdo = odometer;
	st.lastFuel = currentFuel;
	st.lastOdo = odometer;
	st.lastLiter = currentFuelLevel;
	context.setState(st);
	return true;
	

Pls help ..

Thanks

Return to “GpsGate Server - How to setup and use”