0

我正在尝试在 Visual Studio 中运行以下代码:

import sys
import os
from azure.iot.hub import IoTHubRegistryManager
from azure.iot.hub.models import ExportImportDevice, AuthenticationMechanism, SymmetricKey

iothub_connection_str = "HostName=bulkdevice.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=YsKedao6li9wKbpMC5sJftPXNhB0km6Jt6bAD3KqBes="

try:
    # Create IoTHubRegistryManager
    iothub_registry_manager = IoTHubRegistryManager(iothub_connection_str)

    # primary_key1 = "aaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnoo"
    # secondary_key1 = "111222333444555666777888999000aaabbbcccdddee"
    # symmetric_key1 = SymmetricKey(
    #     primary_key=primary_key1, secondary_key=secondary_key1)
    # authentication1 = AuthenticationMechanism(
    #     type="sas", symmetric_key=symmetric_key1)
    device1 = ExportImportDevice(
        id="BulkDevice1")

    # primary_key2 = "cccbbbaaadddeeefffggghhhiiijjjkkklllmmmnnnoo"
    # secondary_key2 = "333222111444555666777888999000aaabbbcccdddee"
    # symmetric_key2 = SymmetricKey(
    #     primary_key=primary_key2, secondary_key=secondary_key2)
    # authentication2 = AuthenticationMechanism(
    #     type="sas", symmetric_key=symmetric_key2)
    device2 = ExportImportDevice(
        id="BulkDevice2")

    # Create devices
    device1.import_mode = "create"
    device2.import_mode = "create"
    device_list = [device1, device2]

    iothub_registry_manager.bulk_create_or_update_devices(device_list)

    # Get devices (max. 1000 with get_devices API)
    # max_number_of_devices = 10
    # devices = iothub_registry_manager.get_devices(max_number_of_devices)
    # if devices:
    #     x = 0
    #     for d in devices:
    #         print_device_info("Get devices {0}".format(x), d)
    #         x += 1
    # else:
    #     print("No device found")

    # Delete devices
    # device1.import_mode = "delete"
    # device2.import_mode = "delete"
    # device_list = [device1, device2]

    # iothub_registry_manager.bulk_create_or_update_devices(device_list)

except Exception as ex:
    print("Unexpected error {0}".format(ex))
except KeyboardInterrupt:
    print("iothub_registry_manager_sample stopped")

我收到一个错误unable to register multiple devices in IoThub,请帮我注册。

4

0 回答 0