Python용 Azure IoT Hub 라이브러리Azure IoT Hub libraries for python
관리 APIManagement API
pip install azure-mgmt-iothub
관리 클라이언트 만들기Create the management client
다음 코드는 관리 클라이언트의 인스턴스를 만듭니다.The following code creates an instance of the management client.
구독 목록에서 검색할 수 있는 subscription_id
를 제공해야 합니다.You will need to provide your subscription_id
which can be retrieved from your subscription list.
Python SDK를 사용하여 Azure Active Directory 인증을 처리하고 Credentials
인스턴스를 만드는 방법에 대한 자세한 내용은 리소스 관리 인증을 참조하세요.See Resource Management Authentication for details on handling Azure Active Directory authentication with the Python SDK, and creating a Credentials
instance.
from azure.mgmt.iothub import IotHubClient
from azure.common.credentials import UserPassCredentials
# Replace this with your subscription id
subscription_id = '33333333-3333-3333-3333-333333333333'
# See above for details on creating different types of AAD credentials
credentials = UserPassCredentials(
'user@domain.com', # Your user
'my_password', # Your password
)
iothub_client = IotHubClient(
credentials,
subscription_id
)
IoT Hub 만들기Create an IoTHub
async_iot_hub = iothub_client.iot_hub_resource.create_or_update(
'MyResourceGroup',
'MyIoTHubAccount',
{
'location': 'westus',
'subscriptionid': subscription_id,
'resourcegroup': 'MyResourceGroup',
'sku': {
'name': 'S1',
'capacity': 2
},
'properties': {
'enable_file_upload_notifications': False,
'operations_monitoring_properties': {
'events': {
"C2DCommands": "Error",
"DeviceTelemetry": "Error",
"DeviceIdentityOperations": "Error",
"Connections": "Information"
}
},
"features": "None",
}
}
)
iothub = async_iot_hub.result() # Blocking wait for creation