Tracking boats with Meshtastic
I got in touch with Luandro Viera. We've been hacking around for while, with LibreMesh and LibreRouter, SecureScuttlebutt, Meshtastic, local services and more.
This time, he shared with me a challenge that was given to him from an indigenous community in the Brazilian Amazon Forests, tracking the location of their boats as they patrol the rivers:
He asked me if I could build a prototype around this idea, so I gave it a go!
Luckily I already had all the required elements, two Meshtastic devices: Heltec Lora32 v3, so I started right away!
The behaviour of this system would be as follows:
- Each of the Meshtastic nodes (the devices with the M logo) communicate their realtime location over LoRa to each other, and retransmit messages for those too far to connect directly.
- The node to the right would be connected to internet and send the messages that arrive to it over to an MQTT Broker.
- There would be a client connected to the MQTT Broker that would receive the MQTT messages and store them on a MySQL Database.
- A Web Server would use the data on the MySQL database to show a map.
Let's start with the MQTT Broker. Initially I've used Yunohost to set up a quick and dirty instance to try out the idea. I already had a yunohost instance on the cloud, so it was as easy as running yunohost app install mosquitto
to have an MQTT Broker running. I will take note of the IP address, and the username and password configured during the install, as it will be the one I'll use to test out the install.
I've used a local MQTT Client, MQTTExplorer, to make sure the setup was working, and to troubleshoot in case anything odd would happen throughout the setup.
Easily installed through snap install mqtt-explorer
.
Messages might not be easy to read, as they are encoded in Protocol Buffers, an efficient format for representing data in binary form... but at least you can see that messages are arriving.
I imagined that I could enable JSON MQTT publishing (a capability available in Meshtastic), but it seems that the meshtastic-map doesn't support it, so I've sent the request... I hope they are interested in this feature!
At the same time, I am flashing the last stable version of the firmware to all my heltec.
For the Web Server we will for this excellent project by liamcottle called meshtastic-map, that consumes the MQTT info and sets up a nice web interface to browse current and historic information in a map... amazing! It only required for me to download the source code, install/update Docker Engine to a new-ish version (v25+), customize the docker-compose.yml for my own MQTT Broker and that was it... a map of my network!
Now that the server side is ready, let's do the Meshtastic side.
For the nodes on the boat, I've used the Heltec Lora32 v3 that I had at hand, and Luandro replicated the setup using the Liligo T-Beam and T-Echo that he had at hand, yielding the same results.
We will eventually automate the node config with YAML file configurations, but for now I will describe how they need to be set up:
One of the nodes was set up as a Gateway. To do so, we had to:
- connect the node over WiFi, so it can reach the MQTT Broker
- enabled the MQTT module pointing to the MQTT Server.
- enable uplink on the main channel. Doing so will cause for each message that this node receives to be forwarded over MQTT to the Broker.
As the boat nodes have built-in GPS, GPS location needs to be enabled for it to be used.
Excellent! Now, we wanted to add the MQTT Server to the docker-compose.yml so we could set up everything easily on their infrastructure.
To do so, we forked the repository to add this functionality in our own branch:
The last thing we've done (Luandro did actually), was to add a password protection to the web frontend so only them could access it. This was implemented using an nginx-proxy.
This project could be extended by:
- Documenting how to reproduce it
- User documentation
- Using canned-messages for key messages
Here are some additional resources about the work of Luandro in the Amazon rainforests:
Member discussion