-
Notifications
You must be signed in to change notification settings - Fork 680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
module: Websocket #1442
base: master
Are you sure you want to change the base?
module: Websocket #1442
Conversation
Added a module to support input and output of MAVLink messages via a websocket connection.
Don't we already have websocket support via Pet Hall's work in pymavlink here? ArduPilot/pymavlink#967 |
Well heck, @peterbarker I didn't notice that! Although it still might be worth a merge based on the following: @IamPete1, I'm curious on your thoughts on potentially combining some of our efforts? I'm totally fine to close this PR and potentially use the core functionality in pymavlink, but would need some additional functionality for my needs. These were the high-level requirements for my PR:
From what I can tell:
Anyway, I'm happy to abandon this PR if the other one can provide similar functionality. It's just a question of whether or not it would be easier to adapt this additional functionality into pymavlink or to add it to a module in MAVProxy. Also I guess the question is: does websocket support belong in a pymavlink connection_type or a MAVProxy module? I originally though about adding it as a connection_type, but when I saw that the REST interface was created as a module, I went the module direction. Curious what other people think. Thanks! |
Hi @jheising. My implementation was down at the connection level because I don't want to have to run MAProxy, a simple translation script is enough. I have been using https://github.com/ArduPilot/pymavlink/blob/master/examples/mavtcpsniff.py with the second connection as websocket. What I have done is really a bare minimum any improvements would be great. Some thoughts from my end:
|
@IamPete1 to address some of the concerns:
Agreed, although the JSON format I used was simply the
So while there isn't a published JSON spec per se, the param names (except for mavpackettype) have a well-defined spec which makes it easy to translate into a common JSON format. It also makes it really easy to debug and test with command line tools like
There is no need to waste any bandwidth, you just need to indicate the format you want to communicate in when you connect. Since websockets start with a standard HTTP request we have full support for paths, URL parameters, etc., like any other HTTP request. So for example, if you want to send/receive raw/binary format you just connect to
Not sure how the websocket library you are using works, but the one I'm using treats each inbound connection as it's own instance, so I don't think there should be any issues with incomplete messages. Also the implementation I provided works in complete messages so it will only forward the messages to pymavlink when the message is complete. Anyway, @IamPete1, totally fine if this version is a bit more overkill than what you needed and doesn't make sense to integrate into pymavlink. @peterbarker I still think it would make sense to consider this merge into MAVProxy for the following reasons:
Please let me know what you think, thanks! |
FYI, if you want to see a quick video of it in action: https://www.youtube.com/watch?v=5mEAPg7Ye7I |
Nice!
That is a nice solution, I had not thought of that. It would be great to also support it at the connection level. |
message_name_2_type_cache = {} | ||
|
||
# Some examples of JSON MAVLink messages | ||
# {"mavpackettype": "COMMAND_LONG", "target_system":0, "target_component": 0, "command": 400, "confirmation": 0, "param1": 1, "param2": 0, "param3": 0, "param4": 0, "param5": 0, "param6": 0, "param7": 0} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You really want the header in here too. So you can check where the messages are coming from. There is already a "standard" for MAVLink over JSON from the mavlink2rest lib here: https://github.com/mavlink/mavlink2rest?tab=readme-ov-file#api
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a great callout. I will update the PR to move to that.
Added a module to support input and output of MAVLink messages via a websocket connection.
I'm not sure what the process is for submitting a new module, but I figured I would create this PR to start the process. Questions:
Thanks!