Geofenсe control script

Consider the following case. Let’s say we have a car and a geofence in which it is allowed to move. When leaving the geofence, it is necessary to notify the platform user with an information message to the operator. When returning to the geofence, a similar message should come, but with information about returning to it.

Geozone creation

Working with geofence is available on the corresponding panel of the main menu. It is necessary to select the geofence, specify its name and color, press the “Save” button to create it.

To create a script for controlling an object, you need to add the appropriate logic. To do this, go to the Logic section and create a new automaton.

Working with geofenсe is possible only with those objects that were created on models with Wialon IPS template.

An example of an automation script for working with geofences

We will develop a script that will warn the operator when an object enters or leaves the created control zone. To do this, in the automation script editor, delete unnecessary elements:

  1. The final state won’t be used in our example since we want to constantly monitor the geo-position of the object. You can move it to the lower right corner of the working area since we can’t delete it.
  2. Let’s also delete the transition that leads to it.

The first state that the system enters into at start will be named in a characteristic way and we will add an action at the entrance – notifying the operator about the script launch.

To create two more notifications – if the object is in the specified zone or outside it – you need to create two new states. Move them to the bottom of the script and name them accordingly. You can then create the required operator alerts as input actions for each of the generated blocks.

At this stage, it is important to set the correct connections between states depending on possible events:

1. if the object is in the zone when the script starts;
2. if the object is outside the zone when the script is run;
3. if the object changes from the “in-zone” state to the “out-of-zone” state;
4. if the object changes from the “out of zone” state to the “in zone” state.

 To create the first link, you need to move the mouse pointer over the “Script start” state block closer to its outer border and hold down the left mouse button on the resulting blue circle to extend it to the “Geofence” state block. In the created transition there will be an opportunity to “Add vent”. In our case, these are events related to geofences: entering and exiting geofences.

In order to associate a script with a specific geofence, it is necessary to start tracking it when starting the script. To do this, add the corresponding action “Start watch geofence” at the entrance to start the script.

Select the action that appears in the block and set the required zone from the drop-down list, then click the save icon to apply the changes.

Save the created script using the save icon on the top panel of the editor menu.
The final script might look like this:

Now you need to select the objects for which the created script will work. To do this, go to the “Objects” tab and select the object for which you want to run the created script.

After that, it will be possible to control the operation of the automaton using the appropriate menu.

Control of the script for our object can be done from the main menu bar “Objects”. After starting the motion emulation, you can observe the operation of the script not only on the map and the messages that appear – in the “Services” tab, you can select a geofence for which the object control logic is set, and track the status of the object’s presence inside the geofence online.