# Trouble connecting to PX4 SITL using DroneKit

**URL:** <https://discuss.px4.io/t/trouble-connecting-to-px4-sitl-using-dronekit/28709>\
**Category:** PX4 Autopilot\
**Created:** [August 12, 2022, 10:15pm UTC](https://discuss.px4.io/t/trouble-connecting-to-px4-sitl-using-dronekit/28709 "2022-08-12T22:15:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikey-joyce](https://discuss.px4.io/user_avatar/discuss.px4.io/mikey-joyce/32/11378_2.png) [@mikey-joyce](https://discuss.px4.io/u/mikey-joyce)\
**Post date:** [August 12, 2022, 10:15pm UTC](https://discuss.px4.io/t/trouble-connecting-to-px4-sitl-using-dronekit/28709/1 "2022-08-12T22:15:46Z")

</div>

I am trying to connect to my PX4 SITL drone using DroneKit, but I run into a few problems.

When I try to connect on port 14540 I get an error that says:

```auto
Start simulator (SITL)
Connecting to vehicle on: udpin:127.0.0.1:14540
Traceback (most recent call last):
  File "/Users/mikeyjoyce/Documents/Drone Delivery/scripts/test.py", line 40, in <module>
    vehicle = connect(connection_string, wait_ready=False)
  File "/usr/local/lib/python3.9/site-packages/dronekit-2.9.2-py3.9.egg/dronekit/ __init__.py", line 3204, in connect
  File "/usr/local/lib/python3.9/site-packages/dronekit-2.9.2-py3.9.egg/dronekit/mavlink.py", line 128, in __init__
  File "/usr/local/lib/python3.9/site-packages/dronekit-2.9.2-py3.9.egg/dronekit/mavlink.py", line 54, in __init__
OSError: [Errno 48] Address already in use

```

If I try to connect on the other ports (14550, 14030, and 13280) it times out because it does not receive a heartbeat.

The other technologies I am using are:  
Mac OS 12.4  
Unreal 4.27  
AirSim plugin for Unreal (this is my simulator)

This is the code I am running to try and establish a connection:

```auto
connection_string = 'udpin:127.0.0.1:14540'
print("Connecting to vehicle on: %s" % (connection_string,))
vehicle = connect(connection_string, wait_ready=False)
vehicle.wait_ready(True, raise_exception=False)

```

When I am running the SITL simulation I am also getting this error which may or may not be related to this problem:

```auto
px4 starting.

INFO [px4] Calling startup script: /bin/sh etc/init.d-posix/rcS 0
INFO [init] found model autostart file as SYS_AUTOSTART=10016
INFO [param] selected parameter default file eeprom/parameters_10016
INFO [parameters] BSON document size 233 bytes, decoded 233 bytes (INT32:10, FLOAT:2)
[param] Loaded: eeprom/parameters_10016
INFO [dataman] data manager file './dataman' size is 7866640 bytes
PX4 SIM HOST: localhost
INFO [simulator] Waiting for simulator to accept connection on TCP port 4560
INFO [simulator] Simulator connected on TCP port 4560.
INFO [commander] LED: open /dev/led0 failed (22)
  PWM_AUX_OUT: curr: 0 -> new: 1234
  PWM_MAIN_OUT: curr: 0 -> new: 1234
INFO [init] Mixer: etc/mixers/quad_w.main.mix on /dev/pwm_output0
INFO [init] setting PWM_AUX_OUT none
INFO [mavlink] mode: Normal, data rate: 4000000 B/s on udp port 18570 remote port 14550
INFO [mavlink] mode: Onboard, data rate: 4000000 B/s on udp port 14580 remote port 14540
INFO [mavlink] mode: Onboard, data rate: 4000 B/s on udp port 14280 remote port 14030
INFO [mavlink] mode: Gimbal, data rate: 400000 B/s on udp port 13030 remote port 13280
INFO [logger] logger started (mode=all)
INFO [logger] Start file log (type: full)
INFO [mavlink] MAVLink only on localhost (set param MAV_{i}_BROADCAST = 1 to enable network)
INFO [mavlink] MAVLink only on localhost (set param MAV_{i}_BROADCAST = 1 to enable network)
INFO [px4] Startup script returned successfully
INFO [logger] [logger] ./log/2022-08-12/22_04_05.ulg	
INFO [logger] Opened full log file: ./log/2022-08-12/22_04_05.ulg
pxh> ERROR [simulator] poll timeout 0, 60
ERROR [simulator] poll timeout 0, 60
ERROR [simulator] poll timeout 0, 60
ERROR [simulator] poll timeout 0, 60
ERROR [simulator] poll timeout 0, 60
ERROR [simulator] poll timeout 0, 60
ERROR [simulator] poll timeout 0, 60
ERROR [simulator] poll timeout 0, 60

```
