The steps for this recipe are as follows:
-
On the device side, import the necessary libraries:
import asyncio
from six.moves import input
from azure.iot.device.aio import IoTHubDeviceClient
- Create a main() function and connect to the device:
async def main():
device_client = \
IoTHubDeviceClient.create_from_connection_string("Connection
String")
await device_client.connect()
- Create a twin listener:
def quit_listener():
while True:
selection = input("Press Q to quit\n")
if selection == "Q" or selection == "q":
print("Quitting...")
break
- Create a listen task:
asyncio.create_task(twin_patch_listener(device_client))
- Listen for a quit signal:
loop = asyncio.get_running_loop()
user_finished = loop.run_in_executor(None, quit_listener)
- Wait for the user finish signal and disconnect:
await user_finished...