Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mspapi2

Lightweight Python client and server for INAV’s MultiWii Serial Protocol (MSP). It wraps a generated codec with a small, typed helper API so you can query or command a flight controller over serial or TCP without hand-crafting binary payloads.

What’s here

  • MSPApi (mspapi2/msp_api.py): high-level helper that mirrors MSP messages with typed fields and basic unit conversion.
  • MSPCodec (mspapi2/mspcodec.py): packs/unpacks MSP payloads from a JSON schema.
  • Examples: example_api.py (read a bunch of MSP data and push RC/waypoint writes).

Setup

  1. Use the INAV schema files that match the firmware you want to talk to. If the JSON files are from the wrong INAV release, message decoding will be wrong. Refresh them with:
./syncjson.sh --branch 9.0.1

To pull from your local INAV checkout instead of GitHub:

./syncjson.sh --local
  1. Install module
python -m venv .venv
. .venv/bin/activate
pip install -e .

Quick use

from mspapi2 import MSPApi

with MSPApi(port="/dev/ttyACM0", baudrate=115200) as api:
    version = api.get_api_version()
    status = api.get_inav_status()
    api.set_rc_channels([1500, 1500, 1500, 1500])

    # Request metadata available after each call
    print(f"Latency: {api.info['latency_ms']:.1f}ms")
  • For TCP transports, pass tcp_endpoint="host:port" and omit port.
  • For UDP transports (e.g. via MSP multiplexer), pass udp_endpoint="host:port"; MSP v2 will be used.
  • To force MSP v2 framing on serial/TCP, set force_msp_v2=True.
  • Request metadata (latency, transport, attempt, timestamp) available via api.info after each call.

Notes and caveats

  • The codec trusts the JSON schema; if the schema is stale, calls will misdecode. Keep msp_messages.json and inav_enums.json fresh from INAV.
  • Mode boxes and INAV defines are static snapshots; automatic updates are WIP
  • Exceptions are allowed to surface; crashes are preferable to silently masking protocol drift.

Examples

MSP gamepad/tx12 as MSP_RC joystick: python examples/msp_joystick.py --tcp 127.0.0.1:5762 --rate 50 --joystick-index 0 python examples/msp_joystick.py --port /dev/ttyACM0 --baudrate 115200 --rate 50 --joystick-index 0

About

API for MultiWii Serial Protocol

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages