Mavlink2Rest
mavlink2rest
creates a REST server that provides mavlink information from a mavlink source.
The current version supports the ardupilotmega dialect, that includes common, icarous and uavionix.
Install :zap:
- :gear: Cargo Install:
cargo install mavlink2rest
Downloads :package:
- :computer: Windows
- :apple: MacOS
- :penguin: Linux
- :strawberry: Raspberry
- ARMv6 binary, ARMv7 is also available under the project releases.
For others or different releases, check the releases menu.
Endpoints
Pages
- Main webpage:
GET /
- Provides information about mavlink2rest and available messages.
API
- MAVLink JSON:
-
GET /mavlink|/mavlink/*
. The output is a JSON that you get each nested key individually, E.g:- http://0.0.0.0:8088/mavlink/ATTITUDE
- http://0.0.0.0:8088/mavlink/ATTITUDE/roll
- http://0.0.0.0:8088/mavlink/ATTITUDE/message_information/time/last_message
- Any MAVLink message will contain a normal message definition, as described in
GET /helper/message/<MESSAGE_NAME>
, and a message_information structure defined as:"message_information":
- Any MAVLink message will contain a normal message definition, as described in
-
POST /mavlink
. Sends the message to a specific vehicle.- For more information about the MAVLink message definition: https://mavlink.io/en/guide/serialization.html
- header: Is the mavlink header definition with
system_id
,component_id
andsequence
. - message: A valid mavlink message, for more information check
GET /helper/message/<MESSAGE_NAME>
.- Check ARM/DISARM example.
-
GET /helper/message/MAVLINK_MESSAGE_NAME
: Helper endpoint to create JSON compatible MAVLink messages, whereMAVLINK_MESSAGE_NAME
is the mavlink message name. E.g:
-
Examples
Get all messages:
# The output is huge, you can get it here: https://gist.github.com/patrickelectric/26a407c4e7749cdaa58d06b52212cb1e
Get attitude:
Get time of last ATTITUDE message:
"2020-03-28T14:28:51.577853-03:00"
Get a message structure example:
Request vehicle to be armed:
# ARM: param1 is 1.0
Request vehicle to be disarmed:
# ARM: param1 is 0.0
Note: For any invalid
GET
, you'll receive a 404 response with the error message. Note: The endpoints that allowGET
and provides a JSON output, also allow the usage of the query parameterpretty
with a boolean valuetrue
orfalse
, E.g: http://0.0.0.0:8088/helper/message/COMMAND_LONG?pretty=true
Websocket
It's also possible to connect multiple websockets with the following path /ws/mavlink
, the endpoint also accepts the query parameter filter
, the filter value should be a regex that matches MAVLink message names, E.g: /ws/mavlink?filter=.*
for all messages, /ws/mavlink?filter=RC_.*
will match RC_CHANNELS_RAW and RC_CHANNELS, resulting in the following output:
For a demonstration, please check the example under the examples filder: websocket_client.py
Benchmark
The following benchmarks were extracted from a raspberry pi 3 connected to a pixhawk running ArduSub.
-
In idle.
6% CPU usage
-
1 client requesting all mavlink messages at 10Hz
9% CPU usage
-
1 client requesting all mavlink messages at 100Hz
20% CPU usage (~5% each core)
-
1 websocket with no filters
11% CPU usage
-
5 websockets with no filters
24% CPU usage (14% @ 1 core, ~3% @ 3 cores)
-
20 websockets with filter only for ATTITUDE message (receiving at 10Hz)
9% CPU usage
-
20 websockets with filter only for NAMED_VALUE_FLOAT message (receiving at 70Hz)
17% CPU usage (9% @ 1 core, ~2% @ 3 cores)
-
20 websockets with no filters
48% CPU usage (20% @ 1 core, ~9% @ 3 cores)
-
1 client requesting all mavlink messages 1000 times
60% CPU usage (~15% each core) Time taken for tests 3.7 seconds Total requests 1000 Successful requests 1000 Failed requests 0 Requests per second 273.60 [#/sec] Median time per request 3ms Average time per request 4ms
-
10 clients requesting all mavlink messages, 100 requests for each client.
140% CPU usage (~46% each core) Time taken for tests 1.4 seconds Total requests 1000 Successful requests 1000 Failed requests 0 Requests per second 733.14 [#/sec] Median time per request 13ms Average time per request 13ms Sample standard deviation 3ms
-
100 clients requesting all mavlink messages, 1000 requests for each client.
140% CPU usage (~46% each core) Time taken for tests 13.8 seconds Total requests 10000 Successful requests 10000 Failed requests 0 Requests per second 725.83 [#/sec] Median time per request 132ms Average time per request 137ms Sample standard deviation 54ms