Unable to read UDP packets

344 views Asked by At

I have a little problem concerning my python script that communicates with my drone. My program works perfectly fine but after sending the command "streamon" to the drone I should receive the video stream of the drone. However I dont get anything. To narrow down the problem I send my code to a friend so he could try it out. He can receive the video, I tried it with my drone on his pc it also works. So I guess the problem is linked to my pc. I tried everything from updating python, the terminal to debug, trying it on a virtual linux machine.... Have you any idea what the problem could be ? heres my python script :

# Communication script with tello drone, connected via TELLO wifi network
​
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 :
        
​
        try :
            ret, frame = drone_videostream.read()
        except Exception :
            print(Exception)
        if ret : 
            cv2.imshow("LiveStream", frame)
        if cv2.waitKey(25) & 0xFF == ord('q') :
            break
            
​
    cap.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
​
receiveStreamThread = threading.Thread(target=receiveStream)
​
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()

​
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)

Best

1

There are 1 answers

0
Kim On

Try running wireshark while you run your program. That way you can see exactly what traffic is being sent and received. Your friend can do the same and you can compare the output to try and work out where it is failing.

The problem may be caused by your computer's network settings. Are you running a firewall which is blocking the drone traffic?