User avatar
johan
GpsGate
Posts: 15259
Joined: Wed Aug 04, 2004 10:40 pm
Location: Sweden
Contact: Website

SCRIPT: 5 km gap without position updates

Mon Sep 14, 2015 2:31 pm

SCRIPT: 5 km gap without position updates

This guide shows how you can write a script that triggers if a vehicle/device travels more than 5 km without any updates in between. It would typically be used to get an indication that something is wrong with the device or the placement of the GPS antenna.

Test Setup

Tips when developing Script Expressions.
https://support.gpsgate.com/hc/en-us/articles/360026121574

Create Event Rule

Create an Event Rule with a Script Expression like the one below:

Code: Select all

// Trigger event after 5000 meters without a new position.
var limit = 5000;
var trigger = false;

// Condition 

if(trackPoint.valid)
{
  var lastPos = context.state;
  
  if(lastPos != null && lastPos != "")
  {
	  if (trackPoint.position.distance(lastPos.longitude, lastPos.latitude) > limit)
	  {
	    trigger = true;
	  }
  }
  
  context.setState(trackPoint.position);
}
	   
return trigger;
Related topics

More info on Script Expressions here:
http://gpsgate.com/blogComment/script_expressions

Allow users to select Event Rules using Custom Fields with scripting
http://gpsgate.com/blogComment/allow_users_to_select_event_rules_using_custom_fields_with_scripting

Displaying arguments on Event Rule reports
http://gpsgate.com/blogComment/displaying_arguments_on_event_rule_reports

Regards,
Johan

GpsGate Support

piter197
Posts: 832
Joined: Sun Jan 09, 2011 3:32 am

RE: SCRIPT: 5 km gap without position updates

Mon Sep 14, 2015 3:55 pm

Is it the same if we use this?

Code: Select all

var limit = 5000;
var odometer = fields.get('Odometer',0);
var lastOdo = context.state;


if (!lastOdo) context.setState(odometer);
else {
     var diff = odometer - lastOdo;
     context.setState(odometer);

     if (diff > limit) return true;
}
return false;
Best Regards,
piter197

User avatar
johan
GpsGate
Posts: 15259
Joined: Wed Aug 04, 2004 10:40 pm
Location: Sweden
Contact: Website

RE: SCRIPT: 5 km gap without position updates

Mon Sep 14, 2015 4:24 pm

The above script used GPS distance. You can of course use the Server Odometer if you have that enabled.

Note! The variable name of the Server Odometer is _Odometer

// Correct:
var odometer = fields.get('_Odometer',0);



Regards,
Johan

GpsGate Support

echolist
Posts: 25
Joined: Tue Sep 01, 2015 8:20 am
Location: Indonesia
Contact: Website

RE: SCRIPT: 5 km gap without position updates

Tue Sep 15, 2015 6:24 am

thank you,
like my problem,
these event can occur when wrong position antena and also maybe the device hung and need restart, can we send some command to device when these event occured ?

regards,
echolist

User avatar
johan
GpsGate
Posts: 15259
Joined: Wed Aug 04, 2004 10:40 pm
Location: Sweden
Contact: Website

RE: SCRIPT: 5 km gap without position updates

Tue Sep 15, 2015 6:30 am

Send Template Command when Event Rule is triggered
topic.asp?TOPIC_ID=14834

Regards,
Johan

GpsGate Support

Return to “GpsGate for Developers”