pythonsocketsudpdji-sdktello-drone

Unable to receive vídeo Stream from tello drone


I am writhing a python script in order to communicate to my tello drone via wifi. Once connected with the drone I can send UDP packets to send commands (this works perfectly fine). I want to receive the video stream from the drone via UDP packets arriving at my udp server on port 11111. This is described in the SDK documentation, "https://dl-cdn.ryzerobotics.com/downloads/tello/20180910/Tello%20SDK%20Documentation%20EN_1.3.pdf".


print ('\r\n\r\nTello drone communication tool\r\n')

print("...importing modules...")

import threading 
import socket
import sys
import time
import platform  
import cv2

print("Modules imported")

print("...Initialiasing UDP server to get video stream....")

drone_videostream = cv2.VideoCapture('udp://@0.0.0.0:11111')

print("Server initialised")

# my local adress to receive UDP packets from tello DRONE
host = ''
port = 9000
locaddr = (host,port) 

print("...creation of UDP socket...")
# Create a UDP socket (UDP Portocol to receive and send UDP packets from/to drone)
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

# Got drone port and ip adress from network (explained in official SDK documentation)
tello_address = ('192.168.10.1', 8889)

print("UDP socket created")


sock.bind(locaddr)

width = 320
height = 240


def receiveStream() :
    print("...receiving stream...")
    while True :
        ret, frame = drone_videostream.read()
        img = cv2.resize(frame, (width, height))
        cv2.imshow("LiveStream", frame)
        cv2.waitKey(1)
        drone_videostream.release()
        cv2.destroyAllWindows()
        
   
def receiving():
    while True: 
        try:
            data, server = sock.recvfrom(1518)
            print(data.decode(encoding="utf-8"))
        except Exception:
            print ('\nExit . . .\n')
            break


print ("...initialiazing connection with tello drone...")

message = "command"
message = message.encode(encoding="utf-8") 
sent = sock.sendto(message, tello_address)

print("Connection established")

#create a thread that will excute the receiving() function
receiveThread = threading.Thread(target=receiving)
receiveThread.start()

receiveStreamThread = threading.Thread(target=receiveStream)


while True :
    message = input(str("Enter a command :\r\n"))
    if message == "streamon" :
        message = message.encode(encoding="utf-8") 
        sent = sock.sendto(message, tello_address)
        receiveStreamThread.start()
    else :
        message = message.encode(encoding="utf-8") 
        sent = sock.sendto(message, tello_address)


When I send the "streamon" command to the drone, I am unable to read the sended UDP packets. I get the following error :

error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'

This means that the frames are empty, thus, no image received.

Do you know why I dont receive them ?

Thank you very much for your help in advance, Best :)


Solution

  • The problem on my side was solved as follows, it appear that my antivirus was blocking the incoming video packets from the tello drone. If you have windows defender, turn off public and private network firewalls while you use the tello drone.