Introduction
Running meshtastic on a Raspberry Pi is common place in installations where you are both stationary and want to run “high power”. These types of setups are convenient for a number of reasons:
- You can power them over PoE
- They typically have higher power output than battery powered devices
- You can attach multiple radios to a single control plane
- You can run “virtual” radios to provide more than one meshtastic API endpoint per device
This article focuses on the latter two points.
Why?
When running Meshtastic on a Raspberry Pi, you need to run the meshtasticd
service. This service is responsible for managing the radios and providing the
API endpoints for your client application. Each instance of meshtasticd is
only capable of communicating with a single radio and providing a single API
endpoint, which means only one client can connect at a time. But the Pi has
far more horsepower than is necessary to run just a single radio. What if you
want to run multiple radios or you want to have multiple client applications
connecting to a single radio? Enter meshtasticd multi-instance “mode”.
This is less of a “mode” and more of an architectural concept, but for the
sake of brevity I’m going to refer to it as mode throughout this document. The
basic idea is that you will run multiple instances of meshtasticd
side-by-side on the same Raspberry Pi. Using the recently introduced ability
for network connected meshtastic radios to communicate over UDP multicast, we
can do some really neat things. For example:
- Connect two radios to one Pi and use them to “bridge” two different mesh presets together.
- Run virtual radios to provide multiple API endpoints for a single radio.
Prerequisites
Hardware
- Raspberry Pi (3/4/5 or Zero/2/2W)
- SD Card (8GB or larger)
- Meshtastic radio modem (MeshAdv, MeshToad, etc.)
In addition to the list above, you’ll need a way to power the Pi. This can be done with a dedicated power supply or PoE. Just make sure you are using a power supply that can provide at least 5V 2A. This is more than the USB port on your computer can provide so you’ll need to use a dedicated power supply or PoE.
You will also want an antenna for each radio. Never run your radio without an antenna. Especially 1w+ radios. Doing so can cause irreparable damage to your radio.
Software
Since the focus on this article is around running multiple instances of
meshtasticd I’m going to assume you already have a few things in place:
- A working Linux installation
- A working single-instance
meshtasticdsetup w/ at least one radio
The Setup
meshtasticd is typically run as a background service. On modern systems,
this is done using systemd. The file that controls the default meshtasticd
instance is located at /etc/systemd/system/meshtasticd.service. This file is
responsible for starting the meshtasticd service and keeping it running. It
is also responsible for restarting the service if it crashes. Unfortunately,
this file (called a unit file) is only designed to run a single instance of
meshtasticd. In order to run multiple instances, we need to create multiple
unit files. In addition, there are two parameters that must be passed to both
the new meshtasticd processes in order to allow them to simultaneously
coexist on the same system. The following sections will dissect the standard
unit file and explain how to replicate this file with the necessary changes to
run an additional instance
The Unit File
The default unit file for meshtasticd looks like this:
[Unit]
Description=Meshtastic Native Daemon
After=network-online.target
StartLimitInterval=200
StartLimitBurst=5
[Service]
AmbientCapabilities=CAP_NET_BIND_SERVICE
User=meshtasticd
Group=meshtasticd
Type=simple
ExecStart=/usr/bin/meshtasticd
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target
We’re not going to go in to detail about each of the parts of this file in
this article. If you want to learn more, I recommend systemd.unit(5)
for a detailed explanation of the unit file format. We’re going to be focusing
on the [Service] section, specifically the ExecStart line. This line is
responsible for starting the meshtasticd process. In order to run multiple
instances, we need to create multiple unit files with slightly different
ExecStart lines. We need to add the following three parameters to the
ExecStart line:
--port <portnum>- This parameter specifies the port number that the API server will listen on. The default port is 8080. You can use any port number you want as long as it is not already in use.--config <config_file>- This parameter specifies the config file to use. We will create a new config file for each instance.--fsdir <fsdir>- This parameter specifies the directory to use for storing the mesh data. We will create a new directory for each instance.
When we add these parameters, we’re going to end up with a unit file that
looks something like this, with <port_number>, <instance_name>, and
<fsdir> replaced with the appropriate values:
[Unit]
Description=Meshtastic Native Daemon
After=network-online.target
StartLimitInterval=200
StartLimitBurst=5
[Service]
AmbientCapabilities=CAP_NET_BIND_SERVICE
User=meshtasticd
Group=meshtasticd
Type=simple
ExecStart=/usr/bin/meshtasticd --port <port_number> --config /etc/meshtasticd/<instance_name>.conf --fsdir /var/lib/<instance_name>
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target
Copy the File
Copy the original unit file to a new file with a different name. Replace
<instance_name> with the name you want to give this instance.
sudo cp /etc/systemd/system/meshtasticd.service /etc/systemd/system/meshtasticd-<instance_name>.service
Reload the systemd daemon to pick up the new unit file.
sudo systemctl daemon-reload
Edit the new unit file to add the parameters we discussed earlier. Replace
<port_number> and <instance_name> with the appropriate values.
sudo systemctl edit --full meshtasticd-<instance_name>.service
Supporting Files
In addition to the unit file, we need to create a config file and a directory
for each instance. The config file should be created in
/etc/meshtasticd/<instance_name>.conf. The directory should be created in
/var/lib/<instance_name>. You can, more or less, copy the original config file
to the new location and rename it. You should then edit the new config file as
you would like for your second radio.
Testing
Once you have created your unit file and config file, you can start the new instance up with:
sudo systemctl start meshtasticd-<instance_name>.service
Once it is running to your liking, you can enable it to start on boot with:
sudo systemctl enable meshtasticd-<instance_name>.service
Conclusion
That’s it! You should now have multiple instances of meshtasticd running on
your Raspberry Pi. You can connect to each instance using the port number you
specified in the unit file. You can also connect to each instance using the
--port parameter when running the meshtastic command line tool. The best
part is, you’re not limited to just two instances. The process outlined above
can be repeated as many times as you like.
Once you have your multi-instance meshtasticd setup, you may wish to set up
UDP multicast between your radios. There is very little documentation on this
feature at the time of writing but a quick summary of the setup is as follows:
- Configure each radio with
--set network.enable_protocols 1using the meshtastic command line tool. - Ensure that all radios are on the same network (localhost works)