How to fixed errorCode 401000 when run Azure Iot SDK csharp on windows simulator

hao chen 0 Reputation points
2023-11-15T07:27:09.2166667+00:00

when I run command: dotnet run --i xxx --r xxx --p xxx get the follow log;

Provisioning API Version: 1.10.1

 

Registering Device

 

Provisioning Status: PROV_DEVICE_REG_STATUS_CONNECTED

Error: Time:Mon Nov 13 10:48:04 2023 File:D:\Project\AzureIoT\azure-iot-sdk-c\provisioning_client\src\prov_device_ll_client.c Func:prov_transport_process_json_reply Line:677 Unsuccessful json encountered: {"errorCode":401000,"trackingId":"7e5781ac-2d65-4812-ac15-93c7163ee257","message":"Unauthorized","timestampUtc":"2023-11-13T02:48:59.2842939Z"}

Error: Time:Mon Nov 13 10:48:04 2023 File:D:\Project\AzureIoT\azure-iot-sdk-c\provisioning_client\src\prov_transport_mqtt_common.c Func:prov_transport_common_mqtt_dowork Line:979 Unable to process registration reply.

Error: Time:Mon Nov 13 10:48:04 2023 File:D:\Project\AzureIoT\azure-iot-sdk-c\provisioning_client\src\prov_device_ll_client.c Func:on_transport_registration_data Line:777 Failure retrieving data from the provisioning service

 

Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,124 questions
Azure IoT SDK
Azure IoT SDK
An Azure software development kit that facilitates building applications that connect to Azure IoT services.
208 questions
{count} votes

1 answer

Sort by: Most helpful
  1. LeelaRajeshSayana-MSFT 13,471 Reputation points
    2023-11-16T02:01:25.6+00:00

    Hi @hao chen Greetings! Welcome to Microsoft Q&A forum. Thank you for posting this question here.

    Based on the details you have provided on the thread, it looks like you may have missed granting access to the DPS instance to authorize with IoT Hub. This may be the reason you are seeing the unauthorized error. Could you please revalidate if your DPS instance has enough permissions on the IoT Hub where you are trying to provision your device. Please refer the below image for reference.

     

    Screenshot showing how to link an IoT hub to the Device Provisioning Service instance in the portal blade.

     

    Please also refer the following resources that will help you guide through the steps needed to use the SDK and provision a device.

    Kindly let us know if you still experience any issues after following the steps from the above articles.


    If the response helped, please do click Accept Answer and Yes for the answer provided. Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.