ITARS
Posts: 6
Joined: Tue Jul 21, 2015 10:42 am
Location: Australia

Setting up Passenger Counter

Tue Jul 21, 2015 10:57 am

Note: for this and newer articles, we recommend you to check our knowledge base here

Hi all

I'm trying to display the Number of Passengers on a vehicle.
With information from the device I know when a passenger gets on and off. Is this something that is easily achieved using scripts, I cannot find or know how to save and recall the number of passengers on the vehicle.

I have a custom field for passenger count, but I cannot see how to change its value. I can read it using user.getCustomFieldValue() within the script editor within the device mapper.

Any help very much appreciated.
ITARS

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

RE: Setting up Passenger Counter

Tue Jul 21, 2015 11:12 am

Set Notifier variables from script. topic.asp?TOPIC_ID=17167

Regards,
Johan

GpsGate Support

ITARS
Posts: 6
Joined: Tue Jul 21, 2015 10:42 am
Location: Australia

RE: Setting up Passenger Counter

Wed Jul 22, 2015 9:29 am

Thanks Johan
I may not have made my query clear enough or I have not understood your response. I had previously found this topic, but it did not help. So I revisited the topic and used the example presented to see what hapens. Small steps as recommended. What was shown appeared to ONLY fit when used with an EVENT notifier, and for the example shown if the speed was 101, then 3 events were displayed.
I amended the EVENT to show a label on the Events tab displaying a counter. I should be able to increment this counter a little later at the moment its a static value (small steps) . What I would like to do is have Either a Custom Field for the device or an Application Variable (what would you recommend) updated to reflect this counter value.
THe problem I have is the EVENT Expressions area does not allow me to SET a customfield only GET via fields.get(strName, defaultvalue), and the Notifications client Script only appears to let me get and input via Core.resolveinput(paraname), and the Presentation area is where I managed to display the counter on the EVENTs tab.
Our device sends one of two messages for each of the Text1 or Text2 messages;
Text1
"Start;DriverID,VehicleID, RouteID"
"End;DriverID,VehicleID, RouteID"
Text2
"Off; Passenger; VehicleNo; RouteNo"
"On; Passenger; VehicleNo; RouteNo"
The passenger counter is ONLY the start of what I am trying to do, but this problem impacts the other things I would like to do also. We would like to eventually update the Vehicles Custom Fields of DriveName, VehicleNo and RouteNo, with the information from the Text1 string. But we cannot seem to find the method that allows us to Read the Current Value, evaluate the Text string, and then Write to a custom field. I was led to believe this can all be done via scripts, but which, Device Mapper Scripts, Event Expressions Scripts, Event Notification Client Script, or a combination and how?
I am not used to the way you refer to your API, within the scripts, I am self tought, so the worked examples ONLY give me part of the answer, I am used to searching for say javascript substr and the results will tell me the Syntax to use, a list of Parameters and their descriptions, a description of how to use the substr function and what it is used for, then a worked example to follow. All this helps me to understand and work out how to use the functions correctly. Do you have any of this detailed somewhere, I found the WEB Services API detail but not the APIs for the Scripts Etc.
So in summary I have asked
for your recommendation on wheter to use Custom Field for the device or an Application Variable,
Which script to use a Device Mapper Scripts, Event Expressions Scripts, Event Notification Client Script, or a combination and how?
Location of the API

Thank you again
ITARS

Machtl
Posts: 88
Joined: Sat Aug 16, 2014 2:58 pm
Location: Austria

RE: Setting up Passenger Counter

Fri Jul 24, 2015 5:28 pm

maybe with an external php or cgi script and http-expressions?

ITARS
Posts: 6
Joined: Tue Jul 21, 2015 10:42 am
Location: Australia

RE: Setting up Passenger Counter

Mon Aug 31, 2015 7:02 am

Hi johan

I think I have finally come up with a solution to my problem, following your guidance in topic.asp?TOPIC_ID=17167 of taking small steps. I have done some extensive testing using the ONESIM, with reasonable results, this is what I came up with.

Solution:
First I have scripts running for my device, which assign PassengerStatus and ShiftStatus to system variables..

I also have an event for the Passenger Counting which has the following script Expression:

var pState = fields.get('PassengerStatus', 'EMPTY')
var sState = fields.get('ShiftStatus', 'EMPTY')
if (sState == '0' ){
if (context.state > 0){
context.setState('');
context.setVariable('PC',0);
context.endEvent('Pcounter');
return false;
}
}
if(pState == "EMPTY"){
if (context.state > 0){
return true;
}
else{
return false;
}
}
if (pState == "On"){
if (context.state > 0){
var pc = context.state;
pc = ++pc;
context.setState(pc);
context.setVariable('PC',pc);
return true;
}
else{
var pc = 1;
context.setState(pc);
context.setVariable('PC',pc);
return true;
}
}
else if (pState == "Off"){
if (context.state == 1){
var pc = context.state;
context.setState('');
context.setVariable('PC',0);
context.endEvent('Pcounter');
return false;
}
else if (context.state > 1){
var pc = context.state;
pc = --pc;
context.setState(pc);
context.setVariable('PC',pc);
return true;
}
else{
log("No Context");
return false;
}
}

the event ALSO uses the notification to set TEXT with a Heading Passengers using the [PC] variable from the script.
I then display the Marker Attribute Passenger.

So now when the device sends the text string for a passenger either on or off, the script triggers the event and the Variable PC used to set the "state" of the event. The "state" is evaluated between between runs and thus keeps track the Number of Passengers on Board. The variable PC is also used to send the current passenger count to the text notifier for use on the MAP for the device.

It looks a bit clumsy but it seems to work, can you think of any improvements to simplify my script or if you notice any obvious problems I may have over looked.

Thank you
again

Return to “GpsGate for Developers”