Skip to content

Commit

Permalink
Merge pull request #180 from trevorm4x/bugfix/udp_port_collision
Browse files Browse the repository at this point in the history
UDP port collision fix
  • Loading branch information
M4GNV5 committed Apr 7, 2023
2 parents e46c452 + 7e2226a commit 5ee9dd7
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions djitellopy/tello.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ class Tello:

def __init__(self,
host=TELLO_IP,
retry_count=RETRY_COUNT):
retry_count=RETRY_COUNT,
vs_udp=VS_UDP_PORT):

global threads_initialized, client_socket, drones

Expand Down Expand Up @@ -126,6 +127,15 @@ def __init__(self,

self.LOGGER.info("Tello instance was initialized. Host: '{}'. Port: '{}'.".format(host, Tello.CONTROL_UDP_PORT))

self.vs_udp_port = vs_udp


def change_vs_udp(self, udp_port):
"""Change the UDP Port for sending video feed from the drone.
"""
self.vs_udp_port = udp_port
self.send_control_command(f'port 8890 {self.vs_udp_port}')

def get_own_udp_object(self):
"""Get own object from the global drones dict. This object is filled
with responses and state information by the receiver threads.
Expand Down Expand Up @@ -395,8 +405,8 @@ def get_battery(self) -> int:
def get_udp_video_address(self) -> str:
"""Internal method, you normally wouldn't call this youself.
"""
address_schema = 'udp://{ip}:{port}' # + '?overrun_nonfatal=1&fifo_size=5000'
address = address_schema.format(ip=self.VS_UDP_IP, port=self.VS_UDP_PORT)
address_schema = 'udp://@{ip}:{port}' # + '?overrun_nonfatal=1&fifo_size=5000'
address = address_schema.format(ip=self.VS_UDP_IP, port=self.vs_udp_port)
return address

def get_frame_read(self) -> 'BackgroundFrameRead':
Expand Down Expand Up @@ -516,7 +526,7 @@ def raise_result_error(self, command: str, response: str) -> bool:
"""
tries = 1 + self.retry_count
raise TelloException("Command '{}' was unsuccessful for {} tries. Latest response:\t'{}'"
.format(command, tries, response))
.format(command, tries, response))

def connect(self, wait_for_state=True):
"""Enter SDK mode. Call this before any of the control functions.
Expand Down

0 comments on commit 5ee9dd7

Please sign in to comment.