HTTP Expression

HTTP Expression can be used to include custom expressions in Event Rules. This can be used with live or buffered data that can later be used in reporting.

Another area of usage is to get real-time position updates from GpsGate to another system.

Example of usage

GpsGate will make an HTTP request to a URL specified by you. The URL contains complete time, position, variables and user information. Your service response if the expression evaluates to true or false, and it can also include notification variables.

For instance, if you have a database of different speed limits for different roads and you want an Event Rules which generates an alarm if a specific speed limit is broken. GpsGate makes an HTTP request for each position update, your service makes a look-up in the database and returns true or false depending on if the speed limit was broken or not.

Installation

1. Go to Site Admin (Legacy)> Plugins > Get More Plugins

2. Install Http Expression

3. Enable Http Expression for your application under Main Menu > Platform Settings > Manage Applications > [click in your app] > Privileges & Plugins

Read how to access the application privileges and features here.

Event Rule setup

1. Inside the application, go to Main Menu > Events > Manage Event Rules and click Custom event rule (or open an existing rule).

2. Under Triggers, set Trigger type to Http Expression.

mceclip0.png

3. Fill in the URL field.

This is the URL to your web service (e.g. http://myserver.com/eventrule.php). Position data is appended to it as query parameters.

4. Leave Format set to GpsGate (GET) to use the request and response format described in this article. The other options are GpsGate (POST XML) and MultiSpeak.

mceclip1.png

Request URL

This is an example of a request URL:

http://myserver.com/eventrule.php?POS_LATITUDE=56.09899&POS_LONGITUDE=18&POS_ALTITUDE=0&POS_TIME=2012-12-11T20:49:18&POS_HEADING=180&POS_VALID=True&USER_USERNAME=1111&SIGNAL_SOS=False&SIGNAL_SPEED=0&SIGNAL_BARCODE=Driver1&Aircondition=True

Variables description

POS_LATITUDE, POS_LONGITUDE is positioned in decimal degrees.
POS_TIME time in UTC/GMT
POS_HEADING heading in degrees. 0 is north.
POS_VALID True if the position was up to date at POS_TIME.
USER_USERNAME user in GpsGate.
SIGNAL_SPEED speed in meters per second.
SIGNAL_BARCODE example of variable from device mapper.

XML Response

Your web service should respond with XML in the following format

<HttpExpression>
    <Result>1</Result>
</HttpExpression>

Result = 1 if the expression is true, and 0 if false.

Testing

Use the Test settings button. It will display the request URL and the response from your web service. If there are any errors those will be written in clear text.

Read how to test using the simulator here.

Advanced features

Methods test/live/buffer/report

The request URL includes a method= variable which can be test, live, buffer or report.

method=test - The request was made using the Test settings button.
method=live - Live Gate Message from tracker going forward in time.
method=buffer - Buffered data from tracker.
method=report - Reporting/Analyze mode.

You choose which data is sent with the Mode checkboxes: Live, Buffered and Reports. By default only Live is selected, and at least one must be selected.

Notifier variables

Switch on Response variables. Variables returned in the response are then available in notification templates as [Http_<name>], where <name> is the variable name your web service returns. This does not affect whether the rule triggers.

Response XML example with one notifier variable:

Code: Select all

<HttpExpression>
    <Result>0</Result>
    <Notification>
        <Variable>
            <Name>Hello</Name>
            <Value>Hello World!</Value>
            <Type>System.String</Type>
        </Variable>
    </Notification>
</HttpExpression>

Error handling

If the web service times out, returns an HTTP error or invalid XML the connection to the tracker will be closed. trackers/protocols that require an ACK will typically resend the same data again until success.

Timeout and parallel requests

Request timeout is the time in seconds before GpsGate considers the request to be a time out (1 to 60, default 15).
Parallel requests (previously Max connections) is the number of parallel requests that are allowed to be made to your web service (1 to 5, default 1).

Asynchronous requests

By default, HTTP Expression will make the request once the message comes in from the asset. If the request fails, for example if the 3rd party server is down or overloaded, then the connection to the asset is closed. If the tracker has a re-send mechanism, it will later try to resend the message. This mode is required for HTTP Expression to work as part of a Live Event Rule.

In case you do not need HTTP Expression to be part of any live events, but rather just use it to forward live tracking data to a 3rd party server, you can instead have HTTP Expression send data asynchronously. To do this, switch on Send in background (previously Asynchronous) and set Discard after (in hours, default 8). If the 3rd party server fails to respond, HTTP Expression will later resend the request, but the connection to the tracker is not affected. Note that a request sent in the background can never trigger the event rule, so use it for one-way data pushes only.

To be notified by email when the queue of background requests is delayed, go to Main Menu > Platform Settings > Account Settings > Error handling and make sure HTTP expression queue delays is switched on. Enter the Email address to send the alert to, set the Delay limit in minutes (default 5), and then click Save. An email is sent when a queue of background requests is delayed for longer than the delay limit. This setting replaces the old Site Admin (Legacy) > System Tools > Http Expression page.

Extra variables in request URL

You can add custom variables to the service URL. e.g. http://myserver.com/eventrule.php?myvalue=6