Meshtastic Python API

raw JSON →
2.7.8 verified Fri May 01 auth: no python

Python API and client shell for communicating with Meshtastic mesh radios. Current version 2.7.8, supporting Python 3.9-3.14. Regular releases follow the Meshtastic firmware updates.

pip install meshtastic
error ModuleNotFoundError: No module named 'meshtastic.serial_interface'
cause Incorrect import path or outdated package version.
fix
Ensure you have meshtastic >=2.0.0 and use: from meshtastic import SerialInterface
error ValueError: The channel '0' is not a valid channel index.
cause When sending a message, the channel index must be an integer between 0 and 7 (or use default).
fix
Pass an integer channelIndex if needed, e.g., iface.sendText('hello', channelIndex=0) or omit.
error PermissionError: [Errno 13] Permission denied: '/dev/ttyUSB0'
cause User does not have permission to access the serial port.
fix
Run with sudo, or add user to dialout group: sudo usermod -a -G dialout $USER (then log out/in).
breaking In meshtastic >= 2.0, the SerialInterface constructor no longer accepts a baudrate parameter; baudrate is auto-detected.
fix Remove any explicit baudrate argument when creating SerialInterface, e.g., SerialInterface('/dev/ttyUSB0') instead of SerialInterface('/dev/ttyUSB0', 115200).
breaking The 'sendData' method was removed in favor of 'sendText' and 'sendRaw'.
fix Replace calls to iface.sendData(data) with iface.sendText(data) for text or iface.sendRaw(data) for raw bytes.
gotcha When connecting via TCP (WiFi), use meshtastic.tcp.TCPInterface, not meshtastic.serial_interface.
fix from meshtastic.tcp import TCPInterface; iface = TCPInterface('192.168.1.100')
deprecated The top-level 'meshtastic' module functions like 'sendText' are deprecated; use instance methods.
fix Use iface.sendText() instead of meshtastic.sendText(iface, 'hello')

Connects to a Meshtastic device via serial and sends a broadcast message.

import meshtastic
import meshtastic.serial_interface
import time

# Replace with your serial port, e.g., '/dev/ttyUSB0' or 'COM3'
iface = meshtastic.serial_interface.SerialInterface('/dev/ttyUSB0')
try:
    print("Connected! Sending a message...")
    iface.sendText("Hello mesh!", destinationId=meshtastic.BROADCAST_NUM)
    time.sleep(2)
finally:
    iface.close()