Azure IoT
A category of Azure services for internet of things devices.
400 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
import os
import asyncio
from azure.iot.device.aio import IoTHubDeviceClient
from azure.iot.device import X509
x509_cert = X509(
cert_file="E:\\Repo\\RRR_1.crt",
key_file="E:\\Repo\\RRR_1.key"
# cert_file="20003C_1.crt",
# key_file="20003C_1.key",
)
async def main():
# Fetch the connection string from an environment variable
# conn_str = os.getenv("IOTHUB_DEVICE_CONNECTION_STRING")
# Create instance of the device client using the authentication provider
device_client = IoTHubDeviceClient.create_from_x509_certificate(device_id='RRR_1',hostname='monoiothub.azure-devices.net',x509=x509_cert)
# Connect the device client.
await device_client.connect()
# Send a single message
print("Sending message...")
await device_client.send_message("This is a message sent")
print("Message successfully sent!")
# finally, shut down the client
await device_client.shutdown()
if __name__ == "__main__":
asyncio.run(main())