A Python command-line tool for sending messages to Meshtastic devices via MQTT. This tool simplifies the process of sending messages through the Meshtastic MQTT network by handling JSON message construction and protocol compliance automatically.
- π Simple command-line interface for sending Meshtastic messages
- βοΈ YAML-based configuration file for storing connection settings
- π Command-line argument overrides for flexible usage
- π Secure credential storage in configuration files
- β Automatic message formatting according to Meshtastic protocol
- π Verbose logging mode for debugging
- π― Support for broadcast and direct messages
- Clone the repository:
git clone <repository-url>
cd meshtastic-mqtt-cli- Install the package:
pip install -e .This will install the meshtastic-send command globally.
pip install meshtastic-mqtt-cliThe tool uses a YAML configuration file stored at:
- Linux/macOS:
~/.config/meshtastic-mqtt-cli/config.yaml - Windows:
%APPDATA%\meshtastic-mqtt-cli\config.yaml
On first run, if no configuration file exists, the tool will create a default template:
meshtastic-send --message "test"This will create the configuration file and exit. Edit the file with your MQTT credentials before sending messages.
mqtt:
server: "mqtt.meshtastic.org"
port: 1883
username: "meshdev"
password: "large4cats"
meshtastic:
from_id: "!12345678"
to_id: "^all"
channel: "LongFast"
channel_number: 0
region: "US"Configuration Options:
mqtt.server: MQTT broker address (required)mqtt.port: MQTT broker port (default: 1883)mqtt.username: MQTT username for authentication (required)mqtt.password: MQTT password for authentication (required)meshtastic.from_id: Your Meshtastic node ID, e.g.,!12345678(required)meshtastic.to_id: Recipient node ID or^allfor broadcast (default:^all)meshtastic.channel: Meshtastic channel name for MQTT topic (default:LongFast)meshtastic.channel_number: Channel index in message payload, 0-7 (default: 0)meshtastic.region: Meshtastic region code, e.g.,US,EU(default:US)
Send a message using configuration file settings:
meshtastic-send --message "Hello, Meshtastic!"All command-line arguments override values from the configuration file.
Required Arguments:
--message,-m: Message text to send (required)
MQTT Connection Arguments:
--server: MQTT server address--port: MQTT server port (default: 1883)--username,-u: MQTT username--password,-p: MQTT password
Meshtastic Arguments:
--from-id: Sender node ID (e.g.,!12345678)--to-id: Recipient node ID (e.g.,^allfor broadcast)--channel: Meshtastic channel name for MQTT topic--channel-number: Channel index in message payload (0-7)--region: Meshtastic region code
Other Arguments:
--config: Path to custom configuration file--verbose,-v: Enable verbose (DEBUG level) logging--version: Display version information--help,-h: Display help information
Send a message with config file:
meshtastic-send --message "Hello, Meshtastic!"Override MQTT server:
meshtastic-send -m "Test message" --server mqtt.example.comSend a direct message to a specific node:
meshtastic-send -m "Direct message" --to-id "!87654321"Specify all parameters via command line:
meshtastic-send -m "Complete example" \
--server mqtt.meshtastic.org \
--username meshdev \
--password large4cats \
--from-id "!12345678" \
--to-id "^all" \
--channel "LongFast" \
--region "US"Use a custom configuration file:
meshtastic-send -m "Hello" --config /path/to/config.yamlEnable verbose logging for debugging:
meshtastic-send -m "Debug message" --verboseProblem: Configuration file not found at ~/.config/meshtastic-mqtt-cli/config.yaml
Solution: Run the tool once to create the default configuration file, then edit it with your credentials:
meshtastic-send --message "test"
# Edit the created config file
nano ~/.config/meshtastic-mqtt-cli/config.yamlProblem: Connection failed: [Errno 111] Connection refused
Solution:
- Verify the MQTT server address is correct
- Check that the MQTT broker is running and accessible
- Ensure your firewall allows outbound connections on port 1883
- Try using verbose mode to see detailed connection logs:
--verbose
Problem: Connection failed: Authentication error
Solution:
- Verify your MQTT username and password are correct
- Check that your credentials have permission to publish to Meshtastic topics
- For public Meshtastic MQTT server, use: username=
meshdev, password=large4cats
Problem: Missing required configuration parameters: server, username, password
Solution: Either:
- Add the missing parameters to your configuration file, or
- Provide them via command-line arguments:
meshtastic-send -m "test" --server mqtt.meshtastic.org --username meshdev --password large4catsProblem: Messages not appearing on Meshtastic devices
Solution:
- Ensure your
from_idstarts with!followed by 8 hexadecimal characters (e.g.,!12345678) - For broadcast messages, use
^allas theto_id - For direct messages, use the recipient's node ID (e.g.,
!87654321)
Problem: Permission denied when creating or reading config file
Solution:
- Ensure you have write permissions to the configuration directory
- On Linux/macOS, the config file should have permissions
0600for security - Try creating the directory manually:
mkdir -p ~/.config/meshtastic-mqtt-cli
This tool follows the Meshtastic MQTT integration protocol. For more information about the protocol, message formats, and MQTT topics, see the official documentation:
Messages are published to topics following the pattern:
msh/[region]/2/json/[channel]/[node_id]
The JSON payload structure follows the Meshtastic protocol specification.
- Python 3.7 or higher
paho-mqtt>=1.6.1PyYAML>=6.0
- Configuration files containing credentials should have restricted permissions (0600 on Unix-like systems)
- Avoid passing passwords via command-line arguments in shared environments (they appear in process lists)
- Use the configuration file for storing credentials instead
- The
.gitignorefile excludes configuration files to prevent accidental credential commits
# Run all tests
python -m unittest discover tests -v
# Run specific test file
python -m unittest tests.test_integration -v
# Run validation tests against actual Meshtastic broker
python tests/manual_validation.pyThis project uses Renovate for automated dependency updates. Renovate will automatically create pull requests to update dependencies when new versions are available.
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Please make sure to update tests as appropriate and follow the existing code style.
For issues, questions, or contributions, please open an issue on the project repository.