001.
import
asyncio
002.
from
azure.iot.device.aio
IoTHubDeviceClient
003.
djitellopy
tello
004.
KeyPressModule as kp
005.
time
sleep
006.
007.
008.
kp.init()
009.
me
=
tello.Tello()
010.
me.connect()
011.
012.
013.
014.
015.
def
getKeyboardInput():
016.
lr, fb, ud, yv
0
,
017.
speed
15
018.
019.
020.
if
kp.getKey(
"LEFT"
):
021.
lr
-
022.
elif
"RIGHT"
023.
024.
025.
026.
"UP"
027.
fb
028.
"DOWN"
029.
030.
031.
032.
"w"
033.
ud
034.
"s"
035.
036.
037.
038.
"a"
039.
yv
040.
"d"
041.
042.
043.
044.
"q"
045.
me.land()
046.
"e"
047.
me.takeoff()
048.
049.
050.
return
[lr, fb, ud, yv]
051.
052.
053.
054.
055.
# define behavior for receiving a message
056.
# NOTE: this could be a function or a coroutine
057.
message_received_handler(message):
058.
059.
060.
print
(
"the data in the message received was "
)
061.
(message.data)
062.
message.data
b
'left'
:
063.
064.
'right'
065.
066.
067.
068.
'forward'
069.
070.
'back'
071.
072.
073.
074.
'up'
075.
076.
'down'
077.
078.
079.
080.
'yaw'
081.
082.
'roll'
083.
084.
085.
086.
'land'
087.
088.
'takeoff'
089.
090.
091.
092.
me.send_rc_control(lr, fb, ud, yv)
093.
094.
095.
096.
097.
async
main():
098.
conn_str
"your connection string"
099.
# The client object is used to interact with your Azure IoT hub.
100.
device_client
IoTHubDeviceClient.create_from_connection_string(conn_str)
101.
102.
103.
# connect the client.
104.
await device_client.connect()
105.
106.
107.
# set the message received handler on the client
108.
device_client.on_message_received
message_received_handler
109.
110.
111.
while
True
112.
vals
getKeyboardInput()
113.
# me.send_rc_control(vals[0], vals[1], vals[2], vals[3])
114.
sleep(
0.1
115.
116.
117.
118.
119.
__name__
"__main__"
120.
asyncio.run(main())