Real-time location tracking of individuals or things that are important to you

When I was taking my young kids to the park or playground I wished I had a solution that would tell me where they are in case they go out of sight. This led me to a project where I made a system to tell me in which direction (AKA bearing) and how far a tracker is located relative to my current position. Inspired by a tracker that you would see in a James Bond movie car chase scene.

The bad guys are that way! Drive!

Such a system is not only useful with children. It tracks a tracker so by proxy you can track any object that is attached to it, e.g. car, bike and more. This project uses mostly off-the-self devices, though you can be somewhat DIY if you prefer. The only custom part of this project is the GUI (graphical user interface).

tl;dr a LGT92 LoRaWAN tracker sends real-time GPS position data to “The Things Network” (TTN) through one or more LoRaWAN gateways. The data is stored in the storage integration of TTN. A React based, single-page application, TTN-tracker-locator, runs in a mobile browser of the user, fetches the data and displays it in real-time.

Normally, I show the result in the end, but in this case it will help explain the outcome. A picture is worth a thousand words, right?

The anchor icon is your position. The green circle is the tracker. The blue line is tracker’s recent path.

Definition of requirements

As with any task/challenge, we start by understanding and collecting the requirements for the desired system.

  • A tracker that can be attached to anything or anybody.
  • Tracker should find/get it’s own position as accurately as possible, preferably within +-10 meter.
  • Tracker should work outdoors. Indoors is a bonus.
  • Tracker should be the lightest and smallest possible, preferably as small as a key-chain or a watch.
  • Tracker should be battery-powered and should run at least 10 hours on battery, preferably with a rechargeable battery.
  • Tracker should update its position (if moved) at least every minute.
  • Whatever tracker’s range is, it should have coverage in certain predefined locations (each hundreds of meters wide/long). Preferably it will have coverage everywhere with little or no setup.
  • The cost should be as low as possible, preferably with no recurring fees.
  • Something that will not stop working after 6 months, preferably using open protocols. For example, not something that depends on some obscure Chinese cloud server.

Evaluate potential technologies

I only considered GPS (GNSS) based devices for finding the position. GNSS is very mainstream and easily available. I am not aware of other options that can provide the desired accuracy easily without special base-stations or something esoteric. Let me know if I missed anything. This basically ruled out the nice-to-have capability of in-doors tracking.

For wireless communication I considered only radio frequency-based methods. Out of that, I ruled out Wi-Fi due to limited range and not ideal power requirements. In the end, I narrowed it further down to cellular networks and LoRa/LoRaWAN.

Cellular

If you are looking to track a person and that person has a smartphone with internet connectivity, then that smartphone can easily function as a tracker. There is no additional cost to this setup as you have already paid for the device, except that you might need to charge the phone more often. I was looking for a dedicated tracking device, so I didn’t explore this path.

If you are looking for a dedicated device, because you want to track an object, a pet or a child, then there are several options. There are previous-gen devices, current-gen and future-gen. Each class with it’s own disadvantages.

Previous generation devices are relatively low-cost (often watches) that work on the older 2G cellular network. You put a SIM card in and it sends the position through some obscure cloud service or via SMS messages. The frequency of reporting is low.

Cost is about US $50 or less not including cost of cellular plan, which could be another US $50 per year or so, depending on what service is available in your area. The major issue with these is that the 2G network is being phased out, so it is hard to find coverage for these devices and it will be even harder in the future.

Current generation devices are those working on the 3G/4G networks. Due to the complexity of these networks, the devices are more power hungry and more expensive. Cost of the device will be in the US $100-200 range.

Future generation devices are those working on the special LTE standards for IoT devices such as Cat M1, M2, NB1, NB2 standards. The result is a lower-cost device with good power efficiency. In some cases, the SIM is an eSIM (digital) and the device is tied to a particular cellular provider from the get-go. Unfortunately these new networks are just being deployed. The devices themselves are still new, so I have seen just a few types being available.

One example of a modern device is the Samsung SmartThings Tracker. It is incredibly small and light at 42.1 x 42.1 x 11.9mm / 23.8g. Downsides are that it is only available in certain geographical areas. The SIM is an eSIM. You get your cellular subscription with the device for US $50 per year and the device is US $99 including one year of free service.

Samsung SmartThings Tracker

Though I have confidence in Samsung’s ability to maintain the cloud service, especially given the yearly fee, it is still a closed system. I am curious if there is a way to integrate or get the position history so you could analyze, store, process or visualize it in some other system. Other issues with this device are that the highest update frequency is 10 minutes and that accuracy might not be very good. Overall, this is a good option for non real-time tracking.

LoRa

LoRa is a low-power, long-range, low data rate communication protocol. It is very efficient for battery powered devices that need to send just a few bytes of data every few minutes. It is a special transceiver. A normal smartphone, for example, doesn’t know to send or receive LoRa signals. Plain LoRa, as opposed to LoRaWAN, is kind of like a walkie-talkie. It is not connected to the internet and both sides need to be LoRa devices.

This route will require a DIY approach, but you would be able to achieve more flexible results and designs. First, you will need a LoRa device that you can program. There are popular “TTGO T-Beam” modules that include an ESP32 micro-controller, a GPS, LoRa transceiver and battery management in one unit.

One such unit will be a tracker that sends LoRa messages to another receiver unit. The receiver can somehow visualize the result locally or it can forward the data to a computer or a phone over Wi-Fi or Bluetooth. The advantage here is that this setup can work anywhere, even where there is no coverage of any kind. It can be a P2P setup or even a mesh setup.

There are several disadvantages. First, the two devices need to be in range and you can’t just monitor a tracker over the internet with this setup. Second, there are no off-the-shelf trackers or services for plain LoRa so it will take some time and effort to find the right firmware and software to implement this strategy. Third, the generic modules are far from compact and light so they don’t satisfy the requirements I presented initially.

When working with LoRa you have to consider the different frequencies that are available. Use frequencies and devices that match your local regulatory requirements. For example, Europe typically uses EU863-870 while the USA will use US902-928. There are lists that show the various frequencies for different countries. Some countries have no approved frequencies.

LoRaWAN

If using plain LoRa is analogous to using walkie-talkies, then using LoRaWAN is like using a cellular network. End devices still transmit using the LoRa protocol, but there is a scheme that allows other devices in the area, called gateways, to receive the packets and then forward them to an application server through the internet. A LoRaWAN gateway is a bit like a cell tower or a Wi-Fi access point. The gateway can be installed by you or it can be somebody else’s gateway. This scheme, called LoRaWAN, forms a “cellular network” that is community-built. It is designed only for light IoT communication, so it will not carry voice or data, and it is not a replacement for a typical cellular network.

As with any cellular network, there are different service providers. A popular LoRaWAN network provider is “The Things Network” (TTN). This is an open-source project. There is no cost to use it, but there are limitations on the amount of data you can send. In theory, you can also set up your own LoRaWAN provider/network, but it will likely make no sense unless you are deploying a vast network of sensors. If you are into that kind of a project, then the team behind TTN will be glad to help you with that.

I don’t want to go into the setup of configuring TTN, as there is plenty of information available online. I will just mention that using LoRaWAN and TTN will give us the advantage of ready-made, off-the-shelf hardware, software and services that we can use to quickly implement our solutions.

As I was writing this article, Amazon launched its Amazon Sidewalk network. It is a community network that utilizes on the wide distribution of Amazon Ring and Amazon Echo devices. It operates using Bluetooth Low Energy and, you guessed it, LoRaWAN. At first it will only be available in the USA. If Amazon succeeds, this could be a revolution for IoT communication. I just hope the barrier of having your own application/device on the network won’t be too high.

Trackers

LoRaWAN trackers are available from Chinese manufacturers. Typical cost is around US $50 including shipping. Note that there is no recurring cost and that we do not depend on cloud services of the manufacturer for future operation of the device.

I ordered and tried the LGT92. You can set various parameters to control the operation. For example, you can configure how often to send a position to the network.

Gateway

Now here is where it gets interesting. If there is an existing TTN LoRaWAN gateway in your area, then you don’t need any additional hardware. If there is none, you need to purchase and install one. Think of it as of an access point for LoRaWAN. A proper gateway will start from about US $70. Note that there are “single channel” gateways available. They are a bit cheaper but they are deprecated and not recommended for use unless you really know what you are doing. It is worth mentioning that one gateway will be enough for many individual trackers in a particular area, so relative cost is reduced the more end devices you have.

Network and software

LoRaWAN will allow us to use TTN, and using TTN will allow us to use various integrations and add-on of TTN. This opens up a pool of ready-made solutions for us. The power of standards!

Winner

After evaluating the options, I decided to go with LoRaWAN based system. This approach doesn’t have the recurring cost of cellular, nor the complexity of plain LoRa. This approach also met all the requirements I specified above. Sadly, the trackers are not as small as the one Samsung makes. Maybe that will change with time.

Implementation

Once you have your gateway and tracker(s), register your gateway in TTN. Then create an “application” in TTN and register your tracker as a device in the application. The way to do that will depend on the specific device you have, so just follow the instructions that came with the device.

Next, connect everything and check if you are getting messages in the “Data” tab of the device. If not, troubleshoot.

Once you get data, you might be getting bytes (payload) and you will need to configure the system to convert it to parsed JSON data (fields). This is done in the “Payload Formats” tab of the application. Your tracker’s manufacturer should supply you with a decoder function, which is just a snippet of JS code that you paste in the TTN console. Configure the decoder and make sure you are now getting proper fields such as “latitude”, “longitude”, etc. The exact fields will depend on the tracker.

At this stage, the data is received in TTN and stored for a short period, just so we could test and troubleshoot it. Next add a “Data Storage” integration so that data is stored for a longer period of time (7 days) and so that we can query it. Note that you can add other integrations, as well as make your own.

User Interface

Now that we have the data, we want to visualize it. I tried several integrations that can show geographic position on a map but none of them worked the way I envisioned. This led me to develop a UI of my own to show the position of the tracker relatively to the user’s current position.

The UI is an open source, React based, single-page application. It is client-side only and uses the infrastructure I described above as its back-end. The project is anticlimactically called TTN-tracker-locator. The source code is stored in github and there is a deployment you can use on github.io.

It is meant to be used on a mobile device, so the UI can access and use your current location and direction. It can then show you where the tracker is located relatively to your own current location. That all it does 😉 . It does it nicely.

Summary

It is relatively easy to get a low cost LoRaWAN tracking solution. Cost vs benefit will vary greatly depending on whether you already have LoRaWAN coverage in your area of interest.

There are off-the-shelf trackers available that are easy to integrate with, thought the LGT92 tracker I tried seemed to have a so-so GPS accuracy. It manifests as noise in the position data, and looks as if the target is moving around more than it actually is. This is an issue when you are relatively close to the target and a non-issue when you are away.

Cellular solutions are currently smaller in size, but not as real-time as LoRa-based ones. Hopefully we will see more products that address these issues on all technology fronts.

You are welcome to follow this article and use the UI. Send feedback or questions if you have any!

Leave a Reply

  

  

  

This site uses Akismet to reduce spam. Learn how your comment data is processed.