{"id":24030,"library":"meshtastic","title":"Meshtastic Python API","description":"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.","status":"active","version":"2.7.8","language":"python","source_language":"en","source_url":"https://github.com/meshtastic/meshtastic-python","tags":["meshtastic","mesh","radio","lora","iot"],"install":[{"cmd":"pip install meshtastic","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"In older versions the import path was different, but since v2.x the top-level import is recommended.","wrong":"from meshtastic.serial_interface import SerialInterface","symbol":"SerialInterface","correct":"from meshtastic import SerialInterface"},{"note":"The TCP interface module is named 'tcp', not 'tcp_interface'.","wrong":"from meshtastic import tcp_interface","symbol":"tcp","correct":"import meshtastic.tcp"}],"quickstart":{"code":"import meshtastic\nimport meshtastic.serial_interface\nimport time\n\n# Replace with your serial port, e.g., '/dev/ttyUSB0' or 'COM3'\niface = meshtastic.serial_interface.SerialInterface('/dev/ttyUSB0')\ntry:\n    print(\"Connected! Sending a message...\")\n    iface.sendText(\"Hello mesh!\", destinationId=meshtastic.BROADCAST_NUM)\n    time.sleep(2)\nfinally:\n    iface.close()","lang":"python","description":"Connects to a Meshtastic device via serial and sends a broadcast message."},"warnings":[{"fix":"Remove any explicit baudrate argument when creating SerialInterface, e.g., SerialInterface('/dev/ttyUSB0') instead of SerialInterface('/dev/ttyUSB0', 115200).","message":"In meshtastic >= 2.0, the SerialInterface constructor no longer accepts a baudrate parameter; baudrate is auto-detected.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Replace calls to iface.sendData(data) with iface.sendText(data) for text or iface.sendRaw(data) for raw bytes.","message":"The 'sendData' method was removed in favor of 'sendText' and 'sendRaw'.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"from meshtastic.tcp import TCPInterface; iface = TCPInterface('192.168.1.100')","message":"When connecting via TCP (WiFi), use meshtastic.tcp.TCPInterface, not meshtastic.serial_interface.","severity":"gotcha","affected_versions":"all"},{"fix":"Use iface.sendText() instead of meshtastic.sendText(iface, 'hello')","message":"The top-level 'meshtastic' module functions like 'sendText' are deprecated; use instance methods.","severity":"deprecated","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Ensure you have meshtastic >=2.0.0 and use: from meshtastic import SerialInterface","cause":"Incorrect import path or outdated package version.","error":"ModuleNotFoundError: No module named 'meshtastic.serial_interface'"},{"fix":"Pass an integer channelIndex if needed, e.g., iface.sendText('hello', channelIndex=0) or omit.","cause":"When sending a message, the channel index must be an integer between 0 and 7 (or use default).","error":"ValueError: The channel '0' is not a valid channel index."},{"fix":"Run with sudo, or add user to dialout group: sudo usermod -a -G dialout $USER (then log out/in).","cause":"User does not have permission to access the serial port.","error":"PermissionError: [Errno 13] Permission denied: '/dev/ttyUSB0'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}