Failed to connect to tcp:127.0.0.1:5760 : [Errno 111] Connection refused

Hi,

I’m trying to run SITL with AirSim (haven’t gotten to the AirSim part yet) and I’m running into this error while follow directions from here: https://ardupilot.org/dev/docs/setting-up-sitl-on-linux.html

As far as I know I’ve followed everything to a t up to this point. Here is the error I get.

Build commands will be stored in build/sitl/compile_commands.json
‘build’ finished successfully (3m53.363s)
SIM_VEHICLE: Using defaults from (/home/user**/ardupilot/Tools/autotest/default_params/copter.parm)
SIM_VEHICLE: Run ArduCopter
SIM_VEHICLE: “/home/user**/ardupilot/Tools/autotest/run_in_terminal_window.sh” “ArduCopter” “/home/user**/ardupilot/build/sitl/bin/arducopter” “-S” “-w” “–model” “+” “–speedup” “1” “–defaults” “/home/user**/ardupilot/Tools/autotest/default_params/copter.parm” “-I0”
SIM_VEHICLE: Run MavProxy
SIM_VEHICLE: “mavproxy.py” “–out” “127.0.0.1:14550” “–out” “127.0.0.1:14551” “–master” “tcp:127.0.0.1:5760” “–sitl” “127.0.0.1:5501”
RiTW: Starting ArduCopter : /home/user**/ardupilot/build/sitl/bin/arducopter -S -w --model + --speedup 1 --defaults /home/user**/ardupilot/Tools/autotest/default_params/copter.parm -I0
xterm: Xt error: Can’t open display: 0.0
Connect tcp:127.0.0.1:5760 source_system=255
[Errno 111] Connection refused sleeping
[Errno 111] Connection refused sleeping
[Errno 111] Connection refused sleeping
[Errno 111] Connection refused sleeping
Failed to connect to tcp:127.0.0.1:5760 : [Errno 111] Connection refused
SIM_VEHICLE: Killing tasks

What do I do abou this? FYI, I’ve been following the instructions I’ve found, but I don’t have a great knowledge of how it all works. I’m just trying to run the simulation SW so I can test control algorithms for a drone and this process for getting SITL is very confusing to me.

user** is just me replacing my username

Thanks in advance for your input!

Hey ! Did you find the solution for this problem ?

@A.Larribau at last somebody who cares! And nope.

aha yeah sometime you can feel lonely here !
First I think (because I see “Can’t open display: 0.0”) that you didn’t set your display. You can download vcxsrv. Once it is done, open xlaunch, select multiple windows and enter number 0, start no client, select the “disable access” and unselect “native open gl” and then just before running the sim_vehicle.py script type
$ export DISPLAY=0:0

an other possibility is trying to run the --no-mavproxy command when you try to build your sim_vehicle.py file and then connect to the vehicle using MissionPlanner or QGC. If it works it means that it is mavproxy that isn’t working for you and in this case I would recommand uninstalling everything and starting from scratch.

@A.Larribau It’s been a while since I looked at this since I got stuck, so let me go through the process again and try your suggestion as well. I had vcxsrv installed but removed it so I’ll have to reinstall that.

is your port5760 occupied? What other programs are you running your sim? I run my sim on a raspberry pi and nothing else is inside

@Josephjj I’m just running it on my laptop, I didn’t know you could run it on a raspberry pi! What do you mean by “what other programs [I’m] running my sim?” I wish I could afford a raspberry pi now lol, wish I would’ve bought one a few years ago when people weren’t charging $300.

No need for a raspi, my sitl is working just fine on my laptop but @Josephjj is right it might an issue with the port already occupied. Did you try my recommandations ? By running with --no-mavproxy flag you solve the issue of port already occupied because mission planner won’t be able to connect when you’ll try on 127.0.0.1:5760

Well in all the time that has passed since I first had this issue, I had installed visual studio 2022, and now I’m having “powershell not found” issues which is keeping me from building AirSim again, so I’m trying to work back through that, I’m thinking I’ll try the method to just use the binaries so I can avoid that, and currently just double checking that my SITL works fine on cygwin (I’m having to rebaseline since it’s been so long)

So no I haven’t tried your suggestions quite yet, but I’m gettting there.

Oh I’ve never tried to use visual studio for ardupilot I am using wsl sorry I can’t help you with this.

Is it better to use WSL? And are you using AirSim as well? I think I remember reading that you can only build custom autopilot code (with the intent to actually flash it to the flight controller) using Linux/WSL. I was using cygwin when compiling my SITL code and then executing the SITL.

I find wsl really efficient but I’ve never tried anything else so I can’t tell you sorry.

Are you using AirSim with wsl?

never tried it but gazebo worked

@A.Larribau hey so I am going the way of WSL now like you, and using WSL2 I tried to run sim_vehcile.py and got the same error I originally posted about. I tried your suggestions with vcxsrv and get this error
image

I also tried running sim_vehicle.py with the --no-mavproxy command and then I see this

SIM_VEHICLE: Using defaults from (Tools/autotest/default_params/copter.parm)
SIM_VEHICLE: Run ArduCopter
SIM_VEHICLE: "/home/user/GitHub/ardupilot/Tools/autotest/run_in_terminal_window.sh" "ArduCopter" "/home/user/GitHub/ardupilot/build/sitl/bin/arducopter" "-S" "--model" "+" "--speedup" "1" "--slave" "0" "--defaults" "Tools/autotest/default_params/copter.parm" "--sim-address=127.0.0.1" "-I0"
RiTW: Starting ArduCopter : /home/user/GitHub/ardupilot/build/sitl/bin/arducopter -S --model + --speedup 1 --slave 0 --defaults Tools/autotest/default_params/copter.parm --sim-address=127.0.0.1 -I0
xterm: Xt error: Can't open display: 0:0
SIM_VEHICLE: Waiting for SITL to exit

Which makes me think that it is a mavproxy thing and that I may need to reinstall everything. Do I have to reinstall mission planner or just mavproxy if so?

yeah the second error is because of the first one. The launch of vcxsrv didn’t worked properly. I’d suggest that once you’ve downloaded vcxsrv you switch off and restart your pc. then xlaunch, select multiple windows and enter number 0, start no client, select the “disable access” and unselect “native open gl”. Then you should have the following icon in your main windows bar :
image
and when you put your mouse over it it says “DESKTOP -XXXX0:0 -0 clients”
If you don’t have this uninstall and reinstall vcxsrv.
then type $ export DISPLAY=0:0 and run sim_vehicle.py

Okay so I did turn off my computer and then turned it back on, alright I do see that “DESKTOP -XXXX0:0 -0 clients” text when I hover over that icon, it was on my taskbar hidden in a drop down menu.

I did type “export DISPLAY=0:0” and then ran sim_vehicle.py but still get this

SIM_VEHICLE: Using defaults from (../Tools/autotest/default_params/copter.parm)
SIM_VEHICLE: Run ArduCopter
SIM_VEHICLE: "/home/user/GitHub/ardupilot/Tools/autotest/run_in_terminal_window.sh" "ArduCopter" "/home/user/GitHub/ardupilot/build/sitl/bin/arducopter" "-S" "--model" "+" "--speedup" "1" "--slave" "0" "--defaults" "../Tools/autotest/default_params/copter.parm" "--sim-address=127.0.0.1" "-I0"
RiTW: Starting ArduCopter : /home/user/GitHub/ardupilot/build/sitl/bin/arducopter -S --model + --speedup 1 --slave 0 --defaults ../Tools/autotest/default_params/copter.parm --sim-address=127.0.0.1 -I0
SIM_VEHICLE: Run MavProxy
SIM_VEHICLE: "mavproxy.py" "--out" "172.19.96.1:14550" "--out" "172.19.96.1:14551" "--master" "tcp:127.0.0.1:5760" "--sitl" "127.0.0.1:5501"
xterm: Xt error: Can't open display: 0:0
Connect tcp:127.0.0.1:5760 source_system=255
[Errno 111] Connection refused sleeping
[Errno 111] Connection refused sleeping
[Errno 111] Connection refused sleeping
[Errno 111] Connection refused sleeping
Failed to connect to tcp:127.0.0.1:5760 : [Errno 111] Connection refused
SIM_VEHICLE: MAVProxy exited
SIM_VEHICLE: Killing tasks

I’m going to see if I can figure out how to check if port5760 is already occupied, since that was suggested earlier. Though I’m not running anything else on my computer at the moment.

Alright when I run the “telnet + < IP adress > + 5760” command, I get

Could not open connection to the host, on port 5760: Connect failed

And for the record because I am using WSL2, here is the end of my bashrc file per the instructions from Using SITL with WSL and XWindows (Windows 10 only)

yeah, i have the same end for the bashrc… But i get this :

only when i don’t set the vc xsrv so I am sorry i don’t know what to tell you except redownload vcxsrv or maybe try an other app to visualize ubuntu app on windows…

Here are the capture just before clicking next
image
image
image