Custom Meshtastic Config URLs

If you're needing a way to pass around a Meshtastic configuration that modifies channels as well as modem presets, there are few ways of doing this.

  1. Factory reset your node and follow a guide (can be tricky)
  2. Download a config.yml file and make the changes yourself then import (also tricky)
  3. Use a pre-configured URL (easy)

The issue with number 3 is that there aren't a ton of ways to get super-granular. The best example I've found is the Meshtastic QR Code Generator from karida-org on GitHub. It's great, but it won't let you add secondary channels.

My Approach

I took what I found in the Meshtastic Python CLI and did some gentle reverse-engineering. I created a new ChannelSet() Python class that's typically loaded from the Node's settings. I then modified that class with the specific attributes I wanted including max_hops, region, and so on.

Take that data, add in your custom primary and secondary channels, serialize it to string, convert it to base64 and then slap it in the default Meshtastic config URL.

Boom, you're off to the races. You can paste this URL into the QR Code Generator of your choice and share with your Mesh friends to quickly get everyone on the same modem preset and channel setup.

Example

import base64

# pip install meshtastic
from meshtastic.protobuf import apponly_pb2, channel_pb2, config_pb2

ch = apponly_pb2.ChannelSet()
ch.lora_config.use_preset = True
ch.lora_config.modem_preset = config_pb2.Config.LoRaConfig.MEDIUM_FAST
ch.lora_config.region = config_pb2.Config.LoRaConfig.RegionCode.US
ch.lora_config.tx_power = 0
ch.lora_config.hop_limit = 5
ch.lora_config.sx126x_rx_boosted_gain = True
ch.lora_config.tx_enabled = True
ch.lora_config.ignore_mqtt = True
ch.lora_config.config_ok_to_mqtt = True

# primary channel
primary_ch = channel_pb2.Channel()
primary_ch.role = channel_pb2.Channel.Role.PRIMARY
primary_ch.index = 0
primary_ch.settings.psk = b"\001" # comes out as AQ==

# bridge channel for LongFast traffic
secondary_ch = channel_pb2.Channel()
secondary_ch.role = channel_pb2.Channel.Role.SECONDARY
secondary_ch.index = 1
secondary_ch.settings.psk = b"\001"
secondary_ch.settings.name = "LongFast"

ch.settings.append(primary_ch.settings)
ch.settings.append(secondary_ch.settings)

ch_str = ch.SerializeToString()

s = base64.urlsafe_b64encode(ch_str).decode("ascii")
s = s.replace("=", "").replace("+", "-").replace("/", "_")
print(f"https://meshtastic.org/e/#{s}")