GPS - Creating a Fence

Creating the GPS Fence:

The software allows different methods to create a GPS fence:

1. Serial

2. EEPROM

3. Map data  (least accurate)

 

To create a Serial or EEPROM fence, access the GPS Menu by long pressing the -> Start button on the KEYPAD.

 

Scroll the menu to select Create Fence and select using the Start button

Now select SERIAL or EEPROM. 

 

1. Serial: Position the GPS module on the ground and save the coordinates to the Serial MonitorFor this method a laptop PC is required.  The GPS module is positioned on the ground and the position saved.  The position is then printed to the serial monitor.  Once all positions have been saved the text from the serial monitor can be copied into the Arduino IDE to save the fence.  This method has no limitations on the amount of GPS coordinates (only the ESP32 memory).


2. EEPROM: Position the GPS module on the ground and save the coordinates to the ESP32 EEPROM memory.  As the EEPROM required 11 EEPROM slots per GPS coordinate there is a maximum limit of 45 GPS coordinates that can be saved to EEPROM.

 

 

1&2. Serial/EEPROM Fence Method

For both the Serial and EEPROM methods the GPS compass is placed on the ground at the point where a GPS coordinate should be saved.

  • Always work clockwise around the area when inputting the coordinates.
  • The line between the last coordinate taken and the fist coordinate taken is filled in automatically by the software.

 

To ensure a good GPS measurement is taken, ensure that the GPS Fix is adequate and that enough satellites are visible to the device. Press

Start: To save the coordinate (long press) - The screen will confirm that the coordinate has been saved.

Back: Delete the last coordinate saved

End: Finish inputting the coordinates

 

If you are creating a Serial Fence then ensure your laptop PC is connected and the Serial monitor window is open. (no matter if you choose Serial or EEPROM the coordinates will be printed to the serial monitor, only with EEPROM at the end the coordinates will be saved to the ESP32 memory).

Continue to save the positions of the GPS module on the ground until the  perimeter of the fence has been saved.

 

3. EEPROM 

  • To save the coordinates long press the Start button until End is selected.
  • Selecting end will write all the coordinates to the EEPROM memory

 

2. SERIAL

Although the serial method requires more steps it allows you to create very detailed GPS fences with many coordinates.  Once the GPS fence has been created and the coordinates are showing in the serial monitor, copy the coordinates by highlighting the text and copying it.

Now 

 

 

 

 

 

3. Create Fence using Map Data

To define the GEO fence we need to get the GPS Latitude and Longitude coordinates of the terrain from a map browser such as google maps.  These coordinates are then inputted into the Arduino sketch so the software can calculate the GEO fence.   This is done on the GPS_Fence_Data tab.

 

Please follow thse simple rules for entering the coordinates.

1. Always work clockwise when inputting the coordinates.

2. For each new GPS fence coordinate a new array number is required.

3. Be careful when entering the coordinates.  Use a point to separate the numbers and not a comma.

4. Remove any additional lines from the array which are not used.

5,  Set the GPSMAX and Define the Array size according to the amount of array points used.  GPSMAX should the same number as the last array point entered.  The GPS_Array value should be at least +1 to the GPSMAX value.

 

Lines of code to define GPSMAX and Array Size.  In this example we have a GPSMAX value of 85. Therefore the minimum GPS_Array value is 86.  (The GPS_Array value could also be 100 if you have defined more than one fence with a higher GPSMAX value)

 

The amount of GPS points the software can track is limited only by the memory and speed of the ESP32 board.  In the below example the software is tracking a GEO fence with 86 points on it.  Point 39 is now being entered using the map data

In the map browser first switch the view to satellite, which allows more accurate placement of the GPS fence points. Clicking on the map gives us a latitude and longitude GPS coordinate which needs to be copied/inputted to the Arduino Software.  Take enough points that a good fence border is formed,

 

 

Negative points of this method

1. The GPS data in google maps typically shows the GPS point to 6 decimal places.  the RTK compass takes position data to 8 decimal places. 

2. The positioning accuracy is dependent on the map view and how accurately you can click on the point required.

 

The software allows more than one GEO fence to be defined (you can input coordinates for various terrains you would need to GEO Fence. 

Each new GEO fence should be copied into the code and the next "Fence = X" number used.  In the settings the Fence number can be selected with the Fence = X setting.

Although many GEO fences can be defined and the GPSMAX value stored in the fence data, the GPS_Array value needs to be updated manually depending on which fence you are using.