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.
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).
- 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- Install module
python -m venv .venv
. .venv/bin/activate
pip install -e .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 omitport. - 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.infoafter each call.
- The codec trusts the JSON schema; if the schema is stale, calls will misdecode. Keep
msp_messages.jsonandinav_enums.jsonfresh 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.
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