-
-
Save KaSroka/7266cfb5ed1363c1114718aade9674a2 to your computer and use it in GitHub Desktop.
Toshiba Home AC AMQP connection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import asyncio | |
from six.moves import input | |
import threading | |
from azure.iot.device.aio import IoTHubDeviceClient | |
HOST_NAME = 'toshibasmaciothubprod.azure-devices.net' | |
DEVICE_ID = '<YOUR_DEVICE_ID>' | |
SHARED_ACCESS_KEY = '<YOUR_SHARED_ACCESS_KEY>' | |
CONNECTION_STRING = f'HostName={HOST_NAME};DeviceId={DEVICE_ID};SharedAccessKey={SHARED_ACCESS_KEY}' | |
async def main(): | |
conn_str = CONNECTION_STRING | |
# The client object is used to interact with your Azure IoT hub. | |
device_client = IoTHubDeviceClient.create_from_connection_string(conn_str) | |
# connect the client. | |
await device_client.connect() | |
print('Connected!!!') | |
def method_received(method): | |
print("Method handler") | |
print(method.name) | |
print(method.request_id) | |
print(method.payload) | |
device_client.on_method_request_received = method_received | |
# define behavior for halting the application | |
def stdin_listener(): | |
while True: | |
selection = input("Press Q to quit\n") | |
if selection == "Q" or selection == "q": | |
print("Quitting...") | |
break | |
# Run the stdin listener in the event loop | |
loop = asyncio.get_running_loop() | |
user_finished = loop.run_in_executor(None, stdin_listener) | |
# Wait for user to indicate they are done listening for messages | |
await user_finished | |
# Finally, shut down the client | |
await device_client.shutdown() | |
if __name__ == "__main__": | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment