MissionPlanner is unable to connect to SITL via UDP/TCP

Hello, I am trying to build the Matlab SITL example Sim_multicopter.m and therefore want to send commans via UDP to SITL and display it also via UDP on MissionPlanner.

Matlab is running and produces an MEX-file and also SITL is running. But SITL displayes: No JSON sensor message received, resending servos.

When I try to connect MissionPlanner via UDP port 14550 it shows a connection error. The same happens when I try it with TCP port 5760.

I am quiet new to this so doas anybody can give me a hint what I am doing wrong or where error might be?

Thank you!

The specific connection errors you see will help, since there are quite a few causes.

For UDP, Mission Planner sometimes opens ports by default for you, and if you try to do it yourself you’ll see a certain kind of error, so we need a little more information from you here.

Hello Joshua,

When I try the TCP connection on 127.0.0.1:5760 I get this error message:

The sequence contains no elements.

at System.Linq.Enumerable.Aggregate[TSource](IEnumerable`1 source, Func`3 func)

at MissionPlanner.MAVLinkInterface.OpenBg(IProgressReporterDialogue PRsender, Boolean getparams) in C:\Users\mich1\Desktop\CubePilot\MissionPlanner\ExtLibs\ArduPilot\Mavlink\MAVLinkInterface.cs:line 960.

at MissionPlanner.Controls.ProgressReporterDialogue.RunBackgroundOperation(Object o) in C:\Users\mich1\Desktop\CubePilot\MissionPlanner\ExtLibs\Controls\ProgressReporterDialogue.cs:line 111.

and when I try to connect via UDP on port 14550 I get this error message:

Normally, each socket address (protocol, network address, or port) may only be used once

in System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)

in System.Net.Sockets.Socket.Bind (EndPoint localEP)

in MissionPlanner.Comms.UdpSerial.Open() in C:\Users\mich1\Desktop\CubePilot\MissionPlanner\ExtLibs\Comms\CommsUdpSerial.cs:line 130.

at MissionPlanner.MAVLinkInterface.OpenBg(IProgressReporterDialogue PRsender, Boolean getparams) in C:\Users\mich1\Desktop\CubePilot\MissionPlanner\ExtLibs\ArduPilot\Mavlink\MAVLinkInterface.cs:line 960.

at MissionPlanner.Controls.ProgressReporterDialogue.RunBackgroundOperation(Object o) in C:\Users\mich1\Desktop\CubePilot\MissionPlanner\ExtLibs\Controls\ProgressReporterDialogue.cs:line 111.

I also tried UDPCI with the lokal IP 172.23…:14550, but I got the same error message as with TCP-connection.

I attached the screenshots and one of the SITL code.

SC_TCP_connection_error-compressed.pdf (129.7 KB)

SC_UDP_connection_error-compressed.pdf (127.7 KB)

Thank you upfront!

Perhaps silly questions… or perhaps fundamental issues:

  • Are you using Windows, Linux, or both?
  • Are you working with 1 computer, or more than 1? If more than 1, where is each thing running (Matlab, SITL, Mission Planner)? And how are your computers connected?

Hello hunt0r,

I am running everything on one PC (Windows 11) and for SITL I am using WSL.

So the TCP error means that you’re connected to “something” but not picking up a heartbeat.

The UDP error means that something is already listening on the port you’re trying to open, which is a common problem here. Mission planner often opens the ports by default, and so does mavproxy.

Try disabling your firewall, since unsolicited UDP is blocked by default (and is what the UDP style used in these systems often consists of). Mission planner might just connect by default.

If your WSL is not set up for mirrored mode, then consult Accessing network applications with WSL | Microsoft Learn, and also SITL on Windows using WSL — Dev documentation particularly the part about –no-wsl2-networking. You’ll have to decide if this is appropriate for you or not.

The difference is that in order for WSL app clients to reach Windows host applications, you’ll need to use the host IP in the NAT case, or use 127.0.0.1 in the “mirrored mode” case.