-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnexion.py
54 lines (44 loc) · 1.33 KB
/
connexion.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""This module handle connexion
between router and Trello : First we connect to Tello's,
then send ap command to reboot then connected to the router
(This is a copy off Tello3.py from github)
original file : https://github.com/katoy/dron-tello/blob/master/tello3.py
mail of original author : [email protected]
"""
import threading
import socket
# Create a UDP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(('', 9000))
tello_address = ('192.168.10.1', 8889)
def recv():
while True:
try:
data, server = sock.recvfrom(1518)
print(data.decode(encoding="utf-8"))
except Exception:
print('\nExit . . .\n')
break
print('\n\nTello Python3 Demo.\n')
print('Tello: command takeoff land flip forward back left right\n')
print(' up down cw ccw speed speed?\n')
print('end -- quit demo.\n')
# recvThread create
recvThread = threading.Thread(target=recv)
recvThread.start()
while True:
try:
msg = input('')
if not msg:
break
if 'end' in msg:
print('...')
sock.close()
break
# Send data
msg = msg.encode(encoding="utf-8")
sent = sock.sendto(msg, tello_address)
except KeyboardInterrupt:
print('\n . . .\n')
sock.close()
break