This tutorial describes how to create your own LoRa GPS tracker using Seeedstudio Wio Terminal. Coordinates will be sent from the Sender to the Receiver (Wio Terminal) by LoRa Technology, after processing on the Receiver, the Sender's location on the map can be seen live.
What is Wio Terminal?The Wio Terminal is a SAMD51-based microcontroller with Wireless Connectivity supported by Realtek RTL8720DN thatβs compatible with Arduino and MicroPython. It runs at 120MHz (Boost up to 200MHz), 4MB External Flash and 192KB RAM. It supports both Bluetooth and Wi-Fi providing backbone for IoT projects. The Wio Terminal itself is equipped with a 2.4β LCD Screen, onboard IMU(LIS3DHTR), Microphone, Buzzer, microSD card slot, Light sensor, and Infrared Emitter(IR 940nm). On top of that, it also has two multifunctional Grove ports for Grove Ecosystem and 40 Raspberry pi compatible pin GPIO for more add-ons. More info in SeeedStudio page.
LoRa is a Long-Range radio technology developed by Semtech. Here is a definition from Semtech's LoRa FAQ:
LoRa (Long Range) is a modulation technique that provides significantly longer range than competing technologies. The modulation is based on spread-spectrum techniques and a variation of chirp spread spectrum (CSS) with integrated forward error correction (FEC). LoRa significantly improves the receiver sensitivity and as with other spreadβspectrum modulation techniques, uses the entire channel bandwidth to broadcast a signal, making it robust to channel noise and insensitive to frequency offsets caused from the use of low cost crystals. LoRa can demodulate signals 19.5dB below the noise floor while most frequency shift keying systems (FSK) need a signal power of 8-10dB above the noise floor to demodulate properly. The LoRa modulation is the physical layer (PHY), which can be utilized with different protocols and in different network architecture β Mesh, Star, point to point, etcetera.
You can read this article for more information.
Features of this project- Live tracking on OpenStreetMap (It can be used on other Map services for example Google Map or MapQuest with minor changes)
- By double pressing the button on Sender, you receive an alarm notification (Buzzer Beep) in Receiver. (Wio Terminal)
- The Temperature/Humidity sensor indicates the current Temperature/Humidity of the Sender.
- The buzzer on Sender provides a sound which helps you find the Sender Box.
- The information received from the Sender on Wio Terminal can be stored on the memory card. (This information includes coordinates, date, time, temperature and humidity)
- It is possible to upload information received from Sender on a personal server or other cloud services for example Adafruit IO.
- Calculate the distance from the Sender to Home with the DistanceBetween2P function. (In meters)
- Ability to save program settings on a memory card without the need to re-upload the program by Arduino.
View of the Receiver and Sender at the end of the project:
1. Navigation
It is the most common and primary application of LoRa based location tracking. Most hiking enthusiasts and adventure lovers like to own a LoRa tracker because it allows them to navigate freely. If you are planning to go on a road trip or hike a new trail then the LoRa tracker will help you in completing your journey safely. It will assist you in selecting the best possible routes and you can save a lot of valuable time this way.
2.Instant help during emergencies
Suppose that you are in a road accident and get unconscious. How will you receive help if it is an isolated area and no one calls the rescue services? This is where the LoRa tracker comes in. A smart LoRa tracker will instantly send a notification to the rescue authorities as soon as it detects that you are in a road accident. Since it will have a built-in GPS, hence, rescue authorities will have no trouble in arriving at your current location.
3.Securing your vehicle
Cars are expensive and therefore car thieves are always looking for vulnerable moments to steal them. If you own a car then the best thing you can do for ensuring its security is that you install a LoRa tracker in it. This way you will always know where your car is at the current moment. So, if it ever gets stolen, you can easily track it through the LoRa tracker. Hence, you can easily recover it by sharing the location of the car with the concerned authorities.
4.Location tracking of Pets
Pets have a habit of wandering out and make a run for escaping the house. Pets are adorable creatures who get easily distracted by loud noises and food. That is why they often wander off and hence go missing or get stolen. If you want to protect your pet then you should install a miniature LoRa tracker in a collar and make your pet wear it. Hence, you will always know about where your pet is wandering off to and you can ensure that your pet remains safe.
5.Looking after the elderly
Older people often wander off alone and then they have extreme difficulty finding their way back. Patients of Alzheimerβs and Parkinsonβs are especially prone to losing time and space. Meaning they can easily get lost and forget where they are and why they came there in the first place. You can ensure the safety of the elderly by giving them a LoRa GPS tracker and making them wear it at all times. This will help you in figuring out where they are at any given time and you can immediately come to their rescue if they ever need help.
6.Protecting Sculptures and Artworks
Galleries and Museums around the world host numerous valuable works of art and artifacts of history. Thieves are constantly looking to steal them and some even succeed. The best way to ensure that these sculptures and artworks remain safe is to track their location at all times. So, you can use a LoRa tracker to have access to their location at any given moment. Hence, you can recover these valuable pieces if they ever get stolen.
7.Solo Travelling
Solo traveling is one of the best experiences in oneβs life. It is not only a great adventure but also an amazing opportunity to interact with different cultures. However, solo traveling involves many dangers especially if you are a woman traveling in an unsafe area. If this is the case then you must make sure that someone is always aware of your current location. And the best way to do that is by sharing your live location through a LoRa GPS tracker. This way you will remain safe and your loved ones will not have to worry about your well-being. If some unfortunate event takes place then the LoRa tracker will help the authorities rescue you.
8.Fleet and Shipment Tracking
Logistics is one of the core operations of any business. Therefore, companies take extra measures to make sure that their fleets and shipments arrive safely and on time. Installing LoRa trackers ensures that your shipments are delivered safely. If someone tries to sabotage your logistics operations by disrupting your fleet then you can easily find your missing shipments by using the signal coming from the installed LoRa Tracker.
9.Merchandise Security
Shoplifting and stealing valuable merchandise is one of the most common and frequent crimes in the world. That is why it is important for large departmental store owners to protect their most valuable items. For this purpose, a LoRa tracker will come in handy. All you need to do is to deploy small LoRa trackers by attaching them to the price tags. And whenever someone tries to shoplift that valuable item, you will receive a notification from the LoRa tracker.How it works?
GPS coordinates are received from the GPS module (Grove GPS Air530) and sent to the Receiver by Grove LoRa module. The interval between each packet sending is completely optional, which I considered 15 seconds. (This time can be changed by the user), also Temperature and humidity information collected by Grove DHT 11 module is sent. A LoRa packet with the following contents will be sent:
22.575171,113.943668,25,45,N1
Which contains the following information:
GPS latitude,GPS longitude,Temperature,Humidity,Device Name
On the receiver side (Wio Terminal), the information is received by Grove LoRa Module
and processing begins. GPS coordinates and other information are extracted. The information is sent via Wi-Fi connection and the static image of the map is received. The following link is created by the getDatafromLink function:
"http://idreams.ir/osm/map.php?center="+ latitude + "," + longitude + "&zoom=" + String(ZoomLevel) + "&size=" + String(MAP_WIDTH) + "x" + String(MAP_HEIGHT) + "&maptype=" + MapType + "&markers="+ latitude + "," + longitude + ",bullseye&quality=" + String(QualityJPG), jpgbuffer
The extracted image is placed in the jpgbuffer variable and finally, the position will be visible on the Wio Terminal screen by TJpg Decoder library
. The A, B, C keys are used to Zoom in and Zoom out, also return to the default Zoom the map. The middle key of the 5 Way Switch is also used to send a buzzer beep to the sender. (This is a great opportunity to find a sender)
The Arduino IDE has been used for this project and the following libraries have been installed.
- TinyGPS++ [v1.0.2]
- Grove LoRa 433MHz and 915MHz RF [v1.0.0]
- Grove Temperature And Humidity Sensor [v1.4.3]
- OneButton [v2.0.2]
- TJpg Decoder [v0.2.0]
- SDConfigFile
- Seeed Arduino FS [v2.1.1]
- Seeed Arduino LCD [v1.6.0]
- Seeed Arduino mbedtls [v3.0.1]
- Seeed Arduino rpcUnified [v2.1.3]
- Seeed Arduino rpcWiFi [v1.0.5]
- Seeed Arduino RTC [v2.0.0]
- Seeed Arduino SFUD [v2.0.2]
- and Wio Terminal Libraries (+,+,+,+,+ )
Before starting work, I recommend using the tutorials provided by Seeed on the wiki.
Application settingsTo make it easier to use the program and not need to upload the program by Arduino, the necessary settings are read from an config.txt file on the memory card. Download the config.txt file and save it on the memory card. Insert the memory card into the Wio Terminal. Note that the Wio Terminal supports up to 16GB of memory card. config.txt
file contains the following information:
WifiSSID=your_WiFi_ssid
WifiPASS=your_WiFi_password
SendToServer=false
MyServer=yourserver.com
SDLog=false
Buzzer=true
ZoomLevel=16
QualityJPG=20
BufferSIZE=29000
MapType=hot
HomeLAT=11.123456
HomeLNG=12.654321
DistanceCalc=true
LoRaFrequency=868.0
This information is as follows:
WifiSSID: Enter your WiFi SSID here.
WifiPASS: Enter your WiFi PASSWORD here.
SendToServer: Do you want the information to be sent to your personal server?
MyServer: Personal server address
SDLog: Is the information received from the sender stored on the memory card or not?
Buzzer: Is the Buzzer Beep active or not?
ZoomLevel: Default map zoom.
QualityJPG: Image quality received from OpenStreetMap server
BufferSIZE: Image storage buffer
MapType: Map tile server (Included: hot, osmfr, wikimedia)
HomeLAT: Home Latitude
HomeLNG: Home Longitude
DistanceCalc: Is the distance between the Home and the sender displayed or not?
LoRaFrequency: LoRa frequency [Be sure to note that the Sender and receiver LoRa frequencies must be the same]
The project consists of two parts:
Part 1: SenderIn this section, modules are connected to the main board (Seeeduino XIAO or Arduino Pro Micro) as shown below. It is possible to use any micro-controller. Of course, the smaller the range, the better. I used Grove Shield for Seeeduino XIAO to connect the grove modules to XIAO. For convenience, I put a pre-made XIAO firmware in my Github page (Select the appropriate file according to the frequency of your area).
To protect the modules, I used a ready-made enclosure. A lithium battery and power bank module (If you use Arduino Pro Micro) was used to power supply the Sender.
The Wio Terminal's unique features made it the best choice for this project. Grove LoRa module is connected as shown below. (Hardware Serial is required to use the Grove LoRa module)
Also with the help of Serial Communication Interfaces (SERCOM) you can easily connect the Grove LoRa module to left Grove port. (i2c Grove)
To power the Wio Terminal, I used a lithium battery and a power bank module. You can also use the Wio Terminal Battery Chassis.
The project source code can be downloaded here. Also I put a pre-made Wio Terminal firmware in my Github page (Before use, please edit the LoRa frequency in the config.txt file).
Be sure to note that the Sender and receiver LoRa frequencies must be the same.
Additional parts:Save data to a personal serverIn this section, we will use Google Map Services. If you don't have access to Map API
, skip this section. To save data on a personal server, just save the following code in an wio_store_data.php
file and edit it in the Receiver section. Remember un-comment #define SEND_TO_SERVER
in Receiver code. Upload the php
file to your server and remember the php file address.
<?php
/*
This file is part of Project LoRa GPS Tracker with Wio Terminal
https://www.hackster.io/idreams/
Edited by: Ramin Sangesari
Thanks to Mohamed Fadiga for this code.
*/
function getParameter($par, $default = null)
{
if (isset($_POST[$par]) && strlen($_POST[$par])) return $_POST[$par];
if (isset($_GET[$par]) && strlen($_GET[$par])) return $_GET[$par];
else return $default;
}
$param_names = array("date", "time","lat","lon");
$file = getParameter("date").".txt";
$line="";
for($i=0; $i< count($param_names); $i++)
{
$line = $line.getParameter($param_names[$i]);
if($i<count($param_names)-1)$line = $line.",";
}
$line = $line."\n";
file_put_contents($file, $line, FILE_APPEND | LOCK_EX);
?>
The php page will create a .txt
file on the server, containing the data you sent from Wio Terminal.
Finally, If sending information to a personal server is enabled, with the following code and the file stored in the server, you can easily see the path of the Sender on the Google Map.
<?php
/*
This file is part of Project LoRa GPS Tracker with Wio Terminal
https://www.hackster.io/idreams/
Edited by: Ramin Sangesari
Thanks to Mohamed Fadiga for this code.
*/
function getParameter($par, $default = null)
{
if (isset($_POST[$par]) && strlen($_POST[$par])) return $_POST[$par];
if (isset($_GET[$par]) && strlen($_GET[$par])) return $_GET[$par];
else return $default;
}
?>
<!DOCTYPE html>
<html>
<head>
<script language="JavaScript" type="text/javascript" src="jquery-2.1.4.min.js"></script>
<script src="http://maps.google.com/maps/api/js?key=YOUR_API_KEY&libraries=geometry"></script>
<script type="text/javascript">
var map;
var poly;
var file_name = <?php echo "\"".getParameter("file")."\"" ?>;//get title name
var lastLat=0;
var lastLon=0;
//-------------------
var firstLat = 0;
var firstLon = 0;
var calc;
//-------------------
var polyOptions= //polyline properties
{
strokeColor: '0#000000',
strokeOpacity: 1.0,
strokeWeight: 3
};
var mapProp = //map properties
{
zoom:15,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
//calculates distance between two points in km's
function calcDistance(p1, p2) {
return (google.maps.geometry.spherical.computeDistanceBetween(p1, p2) / 1000).toFixed(2);
}
//
function haversineDistance(latlngA, latlngB) {
const squared = x => x * x;
const toRad = x => (x * Math.PI) / 180;
const R = 6371; // Earthβs mean radius in km
const dLat = toRad(latlngB[0] - latlngA[0]);
const dLon = toRad(latlngB[1] - latlngA[1]);
const dLatSin = squared(Math.sin(dLat / 2));
const dLonSin = squared(Math.sin(dLon / 2));
const a = dLatSin +
(Math.cos(toRad(latlngA[0])) * Math.cos(toRad(latlngB[0])) * dLonSin);
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
let distance = R * c;
//if (isMiles) distance /= 1.609344;
return distance;
}
function initialize()
{
map=new google.maps.Map(document.getElementById("map"),mapProp);
poly=new google.maps.Polyline(
{
map:map,
icons: [{
icon: {
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
strokeColor:'#ff0066',
fillColor:'#ff0066',
fillOpacity:1
},
repeat:'100px', //repeat polyline
path:[]
}]
});
poly.setMap(map);
$.get(file_name, function(txt)
{
var c = 0; // counter for marker
//console.log("file")
var lines = txt.split("\n");
for (var i=0;i<(lines.length-1);i++)
{
var coords=lines[i].split(",");
if(lastLat!=coords[2]||lastLon!=coords[3])
{
var pos = new google.maps.LatLng(coords[2],coords[3]);
poly.getPath().push(pos);
map.setCenter(pos);
lastLat = coords[2];
lastLon = coords[3];
if (c == 0 ) {
firstLat = lastLat;
firstLon = lastLon;
c = 1;
}
var coords2 = lines[i+1].split(",");
if(lastLat!=coords2[2]||lastLon!=coords2[3])
{
var p1 = new google.maps.LatLng(lastLat, lastLon);
var p2 = new google.maps.LatLng(coords2[2], coords2[3]);
var cc = haversineDistance(p1, p2);
}
}
}
var pA = new google.maps.LatLng(firstLat, firstLon);
var pB = new google.maps.LatLng(lastLat, lastLon);
var resultN = calcDistance(pA, pB);
//alert(resultN);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body >
<div>
<center>
<div id="map" style="width: 100vw;height:100vh;"></div>
</center>
</div>
</body>
</html>
Save this file with the .php
extension on your personal server, replace YOUR_API_KEY
in the code. You'll need to get a developer key for the Google Maps JavaScript API from Google developers console.
Type www.yourserver.com/map.php?file=2020-12-03.txt
in your browser, and this should be the result.
1. Due to the fact that you need a credit card to use Google Map service for free and I don't have access to a credit card to create an account, I used the free OpenStreetMap service.
2. In my testing, the range was somewhere in the 300-500m
range without line of sight, so is likely to be much longer with line of sight and/or better antenna.
3. Be aware that the GPS connection time may take up to a few minutes.
4. Before using Wio Terminal, be sure to update the WiFi firmware.
Comments