Skip to content
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

Trying to use ftp, get protocol error #612

Open
itayg-spearuav opened this issue Jul 9, 2023 · 5 comments
Open

Trying to use ftp, get protocol error #612

itayg-spearuav opened this issue Jul 9, 2023 · 5 comments
Labels

Comments

@itayg-spearuav
Copy link

Hi,
I am trying to use mavsdk's Ftp functionality to list the contents of a directory, among other things such as upload files, create dirs etc. However, I am getting the following error when trying to run my code:

File "/home/itayg/Documents/code/mav_ftp_test/mavftp_send.py", line 29, in list_dir
    dirs = await self.mav.ftp.list_directory(path)
  File "/home/itayg/Documents/code/mav_ftp_test/venv/lib/python3.10/site-packages/mavsdk/ftp.py", line 465, in list_directory
    raise FtpError(result, "list_directory()", remote_dir)
mavsdk.ftp.FtpError: PROTOCOL_ERROR: 'Protocol Error'; origin: list_directory(); params: ('/',)

My code:

from mavsdk import System
import asyncio


class MavFtpHandler:
    mav = None
    address = "serial:///dev/ttyACM0"

    async def init_connection(self):
        self.mav = System(mavsdk_server_address="0.0.0.0")
        print("Connecting to px4...")
        # Connect
        await self.mav.connect(system_address=self.address)
        # This waits till a mavlink based drone is connected
        async for state in self.mav.core.connection_state():
            if state.is_connected:
                print(".. Connected to px4!")
                break
        print()

    async def upload(self, path, remote):
        progress = self.mav.ftp.upload(path, remote)
        async for p in progress:
            print(".")
    async def list_dir(self, path):
        dirs = await self.mav.ftp.list_directory(path)
        print(dirs)
    async def run(self):
        await self.init_connection()
        await self.list_dir("/")


def main():
    mavftp = MavFtpHandler()
    asyncio.run(mavftp.run())


if __name__ == "__main__":
    main()

I am using a px4 connected via USB. I tried running mavsdk_server manually, here's the output:

[02:23:51|Info ] MAVSDK version: v1.4.16 (mavsdk_impl.cpp:20)
[02:23:51|Info ] Waiting to discover system on serial:///dev/ttyACM0... (connection_initiator.h:20)
[02:23:51|Debug] New: System ID: 1 Comp ID: 1 (mavsdk_impl.cpp:496)
[02:23:51|Debug] Component Autopilot (1) added. (system_impl.cpp:377)
[02:23:51|Warn ] Vehicle type changed (new type: 2, old type: 0) (system_impl.cpp:225)
[02:23:51|Debug] Discovered 1 component(s) (system_impl.cpp:578)
[02:23:51|Info ] System discovered (connection_initiator.h:63)
[02:23:51|Info ] Server started (grpc_server.cpp:53)
[02:23:51|Info ] Server set to listen on 0.0.0.0:50051 (grpc_server.cpp:54)

I am running linux. Is there any way to fix this?

@julianoes
Copy link
Collaborator

What is the other side? Is it PX4, and which version?

FYI: I'm pretty much re-writing FTP for MAVSDK v2 but it's not finished yet.

@durka
Copy link

durka commented May 15, 2024

I am getting the same error trying to use mavftp with Ardupilot 4.4.4.

@julianoes
Copy link
Collaborator

Yes, I see this too. On my list for this week.

@julianoes julianoes added the bug label May 20, 2024
@durka
Copy link

durka commented May 20, 2024

FWIW, I believe it's because the path length is wrong. MAVSDK is adding 1 for the null terminator but AP seems not to want that.

@julianoes
Copy link
Collaborator

@durka let me know if you found anything more. So far I found this fix mavlink/MAVSDK#2309 for #690 but I'm not sure if it's related.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants