01.
from
djitellopy
import
tello
02.
azure.iot.device.aio
IoTHubDeviceClient
03.
azure.iot.device
Message
04.
asyncio
05.
time
06.
uuid
07.
08.
me
=
tello.Tello()
09.
me.connect()
10.
11.
async
def
send_tello_telemetry(device_client):
12.
# Connect the client.
13.
await device_client.connect()
14.
15.
# Send tello telemetry
16.
while
True
:
17.
msg
Message(str(me.get_current_state()))
18.
msg.message_id
uuid.uuid4()
19.
msg.correlation_id
"correlation-1234"
20.
msg.custom_properties[
"tornado-warning"
]
"yes"
21.
msg.content_encoding
"utf-8"
22.
msg.content_type
"application/json"
23.
print
(
"sending message: "
+
str(me.get_current_state()))
24.
await device_client.send_message(msg)
25.
time.sleep(
5
)
26.
27.
28.
main():
29.
# The connection string for a device.
30.
conn_str
"your connection string"
31.
# The client object is used to interact with your Azure IoT hub.
32.
device_client
IoTHubDeviceClient.create_from_connection_string(conn_str)
33.
34.
"IoTHub Device Client Sending Tello Telemetry"
35.
"Press Ctrl+C to exit"
36.
loop
asyncio.get_event_loop()
37.
try
38.
loop.run_until_complete(send_tello_telemetry(device_client))
39.
except
KeyboardInterrupt:
40.
"User initiated exit"
41.
Exception:
42.
"Unexpected exception!"
43.
raise
44.
finally
45.
loop.run_until_complete(device_client.shutdown())
46.
loop.close()
47.
48.
49.
if
__name__
"__main__"
50.
main()