-
Notifications
You must be signed in to change notification settings - Fork 227
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
connecting via TCP #422
Comments
The TCP connection is mostly untested because PX4 does not generally use TCP. What sort of radio are you using that gives you TCP? Can you get the output of mavsdk_server, e.g. by using:
Or by starting mavsdk_server separately like this:
and then starting the
(replace with your Python version) |
ah alright, ill have a play around with that, thanks. It's the TBS tango 2. their TCP seems to work substantially better than UDP (i get like 95% lost packets with UDP, I've heard it's some problem with the radio), but I'm honestly not sure why its that way, it's just what they recommend using at the moment. |
alright, the first method returns "None" for the second method, I'm not sure how you start the server from their terminal, sorry I'm not the most experienced programmer!
|
For the second method, remove the arguments in And then open a separate console and run mavsdk_server like this:
To find where your
|
no matter if I try to connect first or not, assuming I've typed the right stuff into the console... I'm getting this error. Im on windows by the way
|
Aha you're on Windows. That's good to know. It looks like it fails to bind. Do you have Mission Planner running when you try this? And btw. I assume you're using ArduPilot and not PX4? Note that support for ArduPilot in MAVSDK is only experimental, you can see more details in mavlink/MAVSDK#1568. |
Ah yes, I should have said all my hardware at the start. I didn't think it could have an effect as I thought the incoming stream of mavlink data would be the same. So I'm trying out a fairly different set up. It's a betaflight fc, that is transmitting mavlink over crossfire to my tx, and then tcp from my tx to my laptop/phone I'm trying to make a gps-based antenna tracker that works with betaflight. As I said I have got it working with mission planner, so the mavlink is making it through to my PC/phone, and the rest of my code works in jmavsim too. My end game was to try and implement this onto a microcontroller or a raspi or something later on once I've got my brain around getting it working on the PC. |
Ok cool! Have you tried connecting without Mission Planner open? I think the problem is that Mission Planner is using the port which means MAVSDK cannot bind to it. |
I don't think it's a binding error on the Just to be sure: drone.connect(system_address="tcp://[192.168.4.1][:5760]") This is invalid, right? The way to write that is: drone.connect(system_address="tcp://192.168.4.1:5760") Can you show us the command line you type and the corresponding output of Because you are on Windows, I assume you did not copy-paste exactly that, so it would be interesting for us to see exactly what you wrote. Still guessing, but the error message sounds like grpc gets an error saying "Failed to add port to server" and "Only one usage of each socket address (protocol/network address/port) is normally permitted". But to me this is happening when
Where |
Oh sorry, I totally forgot to reply to that bit. I'll just go and make sure it isn't running in the back ground or anything and try again.. |
ok so, im on windows, to get that previous error I typed as for the I just tried again double checking mission planner is not running and still, the same result. BUT
You guys are pretty clever ay, haha. Any hints on how I could implement this into code? |
Ah, so the mavsdk_server port is already taken. Now the question is what is using 50051. You could try to reboot the computer to make sure whatever is using is, is shut down. |
got some more info for you, which I don't understand but maybe you do. I checked what is using the port 50051 in PowerShell to see what was blocking it, and it was another instance of mavsdk_server. But If I try to use on top of all that, when I do use a different port and get the server up and running, It is failing to connect. Ill keep trying different things for a bit. But I'm in NZ and its about bedtime so I might go quiet for a bit |
Good night over to NZ 👋
So it connects and everything is working? And if not, please paste the output that it's printing so we can debug what is going on. If you use |
Allright, I've not done much poking around to check if I've done something silly here, but this is what I get when the port works:
|
so I've been trying a few things today, one of which is just switching to UDP and the default port on my TX, with no luck. I've been using this example code to rule out my code being the issue: but I using but no matter what I'm still having the same issue as above. I saw mavsdk is for mavlink 2.0. I can't find any info about what version I'm using so ill send off an email to try and work that out! |
Hm, that's interesting:
Have you made sure mavsdk_server gets to connect through the firewall? Sometimes that pops up on Windows... And can you ping that IP? Does it respond? |
A normal ping to 192.168.4.1 works fine, but in powershell if I use the Test-NetConnection thing to try ping the actual port (I tried with 3 or 4 ports) I get this:
Again, this is outside of my understanding here so I don't know if that is valuable info, but seems like it pings but cant do TCP stuff. Another thing I've been playing with is, my TX can either act as an access point that I connect to, or it can join the same network as my laptop. Is mavsdk-server able to work in one of those setups but not the other? I had a look at trying to do that regedit stuff, I don't know if windows 11 has changed regedit, but those instructions don't seem to relate to what my regedit looks like on this computer... EDIT: Same results with all my firewalls disabled |
Ok not sure what I changed as I've changed a lot of stuff. but now I just get this
also. why does it say "set to listen on 0.0.0.0:5555" when I ask it to listen to 192.168.4.1 |
It listens on port 5555 for gRPC so that the Python wrapper can talk to it, that's all correct.
Now for this part, it might be that the TCP implementation is "in the wrong direction". Basically, the TCP connection is the client part with: The other side would then have to implement the server and implement the Do you know what the other side implements? Maybe we have to add the server mode to mavsdk to support your case. |
IF I sent you a Wireshark log of mission planner talking to the tx would you be able to tell from that? if not I can ask the manufacturers of the radio, they are quite quick to reply! |
Either information might work, yes! |
So I got a reply from tbs, (the tx manufacturer) and they say the tx is acting as a tcp server! |
You are not asking to listen on 192.168.4.1. You are asking MAVSDK to open a TCP connection to 192.168.4.1:5760. So 192.168.4.1 is the IP of the drone, and MAVSDK will try to open a connection. Is that what you expect? |
To be honest, at this point this has gone way deeper into network stuff than I understand. I'm trying to keep up with some googling but Im never sure what I expect, I'm learning on-the-go! the rest of this project with more hardware-based problems I'm alright with, just this wifi stuff I'm very new to. |
Ok, so this would then actually be correct. However, it doesn't work 🤔. It's a bit tricky to help you because TCP is not used much (at all?) with MAVSDK, at least when using PX4, and additionally Windows is not used much with it, so there are a few unknowns. Plus, I don't have the device. A few things you could try:
Any of these could give us a hint what is going on. |
Nice one, well thanks again for all the help. I'll give this all a go when I'm back from Christmas holidays. Maybe I'll just skip windows and just go straight to raspi/arduino/stm route instead. I learnt a lot this week! Have a good Christmas! |
You too, thanks! |
hey, I think i've got a fundamental misunderstanding in how to connect to my drone, I'm trying to connect to mavlink through my tango2 tx's wifi.
I can get mission planner to connect using TCP, 192.168.4.1 port: 5760, But within MAVSDK
drone.connect(system_address="tcp://[192.168.4.1][:5760]")
Doesn't seem to connect. I assumed these would be the same as the address you would use for mission planner.
I have code working within jmavsim all fine, just struggling to transfer it over to the real world.
The text was updated successfully, but these errors were encountered: