I’ve recently completed an Honours Degree in Software Development and as part of this I spent a few months off and on working on a proof of concept tracking system utilising Bluetooth Low Energy (BLE) in order to track small asset tags. I believe this system could quite easily be scaled up to an industrial scale with further work but don’t personally plan to follow this up in the near future due to working on other projects. As such I figured I’d release a lot of what I have and hopefully it can help somebody else.
If you do something cool with this then please get in touch, otherwise do with it all as you wish.
This post is one of eight scheduled to be released over the next few weeks, all posts in this series may be found by selecting the tag below.
This post functions as a log of the steps required to implement this project in a practical manner, the goal is that somebody else with minimal knowledge may be able to follow it.
Logging MQTT Data to Database
In a production environment it would be suggested to use a Time Series database to store incoming MQTT logs which would allow for historical view of assets, or potentially using a data streaming platform to acquire the latest data if historical views were not required which would reduce storage costs.
However, for the purposes of this proof of concept I will make use of SQLite hosted on a Raspberry PI, this will allow me to easily handle the relatively small quantity of data being processed.
Set Up SQLite
For the install of SQLite, I will make use of the instructions found at linoxide.com –
https://linoxide.com/install-use-sqlite-linux/
Setup
The script found here – GitHub – NRF5188_BLE_to_MQTT .
When ran this script will create the required database and tables, it will then process any incoming MQTT messages and save it to a database which will be used for the visualisation of asset locations.

Calculating Location
The first step in ascertaining the location of a specific tag is to retrieve the coordinates of each gateway which is receiving a BLE advertisement, from there it is possible to calculate the distance to the tag from each gateway, this effectively becomes the radius of a circle centred on each gateway.
We can then take the coordinates and radiuses of each gateway to trilaterate the location of the tag by calculating where each circle intersects.
The graphic below demonstrates the principle of trilateration.

Although the example given is trilaterating the location of a mobile device form signal towers, the same principal may be applied to a BLE system – https://www.101computing.net/cell-phone-trilateration-algorithm/