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 project 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 Distribution

msh_bot-1.0.0.tar.gz (21.1 kB view details)

Uploaded Source

Built Distribution

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

msh_bot-1.0.0-py3-none-any.whl (21.0 kB view details)

Uploaded Python 3

File details

Details for the file msh_bot-1.0.0.tar.gz.

File metadata

  • Download URL: msh_bot-1.0.0.tar.gz
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • 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-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c1cf61191d3c8ac6a6b7e44ca39843fc8d341ee9fd389564d9f9079f7bf86c45
MD5 194d9110c8ce80087301a3bd777a5ce0
BLAKE2b-256 0d6ff3b9c97cd5c75927028d112e18c9ce9309950f25cb55b77f1425c1210a8b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: msh_bot-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 21.0 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-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e0613b67902df30df3248439e191106fc74cbfc9f83582260759c03ae8c53402
MD5 e81b7438071074cb852972077e6942cc
BLAKE2b-256 873ce856c05a8a0854f3d056054d7a25772aba0595d47d62e5e7e251b99d8cbd

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 files

0.1.0

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