Skip to main content

MSH-BOT

This is a simple meshtastic bot that will reply to some given commands. It connects to a node over TCP so the node needs to be reachable on your network. The main purpose of this bot is to use it for tests in a private channel :)

Thing logo

Commands

/trace <node_id>    -> will traceroute the given node_id and return the number of hops and path, if no node_id is given it will trace route the sender
/ping               -> will just reply with the number of hops and snr and rssi values
/dist               -> will calculate the distance between the sender and the bot
/off <time>         -> program will disconnect from node for the given time (useful for maintenance on the node)
/help               -> will print an help message listing available commands

Configuration

Settings live in a config.toml file, the bot reads the path specified in MSHBOT_CONFIG if set, otherwise config.toml in the working dir. config.example.toml in the repository root is a template to copy.

[node]
hostname = "192.168.1.1"    # hostname of the node
target_channel = "Example"  # the channel name where the bot will reply (please do not set in main channels like longfast), note that this is case sensitive!
dm_reply_message = "Hello!" # if this is defined the bot will respond to all dms with this message, if this is not set in the config the dm functionality is disabled!
discord_webhook_url = "https://discord.com/api/webhooks/..." # if set will send all the received and sent messages through this webhook


[mesh]
hop_limit = 4               # the bot hop limit (check your local community guide for this value)
trace_route_channel = 0     # the channel where the traceroute will run (default 0), set this as your public channel if it is not 0 so the node ids in the path are not always !ffffff
trace_route_timeout = 60    # hard timeout for trace route (default 1 min)

[offline]
offline_minutes = 30        # default value for the time the node will be offline (in case a <time> value is omitted in the /off command)
disconnect_delay = 10       # delay in seconds till the program disconnects from the node
reconnect_poll = 30         # delay in seconds to retry connection to the node
probe_interval = 60         # seconds between liveness probes, also the worst case delay before a silent drop is detected

hostname and target_channel are required, everything else falls back to the defaults shown above

Install (as systemd service)

These instructions assume systemd and a dedicated service account. Adjust the paths if you prefer somewhere other than /opt.

I run this bot on a Pi Zero 2 W, where a container adds more overhead than it is worth for a single Python process. systemd is enough.

The projec is built with uv. Since the pi doesn't have uv installed I usually just buld the wheel on my host and copy it over to the pi.

Build the wheel

uv build

This produces something like this: dist/msh_bot-0.1.0-py3-none-any.whl

Copy this to the pi

scp dist/msh_bot-0.1.0-py3-none-any.whl <user>@<host>:/tmp/

Create the user and dirs

sudo useradd -r -s /usr/sbin/nologin msh-bot
sudo mkdir -p /opt/msh-bot /etc/msh-bot
sudo chown msh-bot:msh-bot /opt/msh-bot

Install the wheel

sudo -u msh-bot -H /usr/bin/python3 -m venv /opt/msh-bot/venv
sudo -u msh-bot -H /opt/msh-bot/venv/bin/pip install --no-cache-dir /tmp/msh_bot-0.1.0-py3-none-any.whl

On the pi if the venv command hangs don't worry it is not stuck!

Copy config

sudo cp config.example.toml /etc/msh-bot/config.toml
sudo chown root:msh-bot /etc/msh-bot/config.toml
sudo chmod 640 /etc/msh-bot/config.toml

Then edit it with your favourite editor, for example sudo vim /etc/msh-bot/config.toml. The file is readable by the service and by root only.

Create the unit file

at /etc/systemd/system/msh-bot.service

[Unit]
Description=MSH-BOT a simple meshtastic bot
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
User=msh-bot
WorkingDirectory=/opt/msh-bot
Environment=MSHBOT_CONFIG=/etc/msh-bot/config.toml
ExecStart=/opt/msh-bot/venv/bin/msh-bot
Restart=on-failure
RestartSec=10

NoNewPrivileges=yes
PrivateTmp=yes
ProtectSystem=strict
ProtectHome=yes

[Install]
WantedBy=multi-user.target

Start it

sudo systemctl daemon-reload
sudo systemctl enable --now msh-bot.service

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

msh_bot-0.1.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file msh_bot-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: msh_bot-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"NixOS","version":"26.05","id":"yarara","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for msh_bot-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9db53164a977eea5b14bfd4d8e32520b5cf281728aa022d4138c120bc9ecaf1c
MD5 1208ec3d3e0701c88f179698e49a6233
BLAKE2b-256 2c956a4a7663ff578b57f34fdeef13dc9cd844f29abadb51ad11da304984ec20

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.0

2 files

This release

0.1.0 This release

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page