how to fix error in provisioning dps while after environmental variables. Ex: It shows unsuccessful JSON error and failed to create IOThub device client

Anonymous
2023-09-12T08:25:53.34+00:00

while provisioning iot hub dps environmental variables it shows error like unsucessful JSON error, "errorCode":401000.

It also shows failed creating IOT hub device client

Azure IoT
Azure IoT
A category of Azure services for internet of things devices.
391 questions
Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,149 questions
{count} votes

Accepted answer
  1. LeelaRajeshSayana-MSFT 13,951 Reputation points
    2023-09-15T15:21:49.1433333+00:00

    Hi @Anonymous Thank you for sharing the details on resources you have provided. The articles you have provided use two different approaches to provision a device.

    Approach 1 - Through Azure Portal UI

    For this you would first set up the Azure DPS through Azure portal using the steps provided in the link Set up the IoT Hub Device Provisioning Service with the Azure portal and follow the steps in the article Provision a simulated symmetric key device. This approach does not require you to set any environment variables. You just need to provide the DPS ID scope value and the enrollment group Primary key in the code. Please ensure that your system is configured per the instructions provided in the prerequisites section to run the code.

    Approach 2 - Using IoT Plug and play models

    The resources Set up your environment for the IoT Plug and Play quickstarts and tutorials and Connect a sample IoT Plug and Play device application running on Linux or Windows to IoT Hub rely on using local copies of the model files used by the sample applications and the Azure IoT explorer tool. Here are few things you can revalidate to help you understand the possible cause of the issue.

    1. Make sure your IoT Hub is linked correctly with DPS
      1. The section Create the resources provides a command to link IoT Hub with DPS. This can also be achieved through the Azure portal UI using the steps provided in the section Link the IoT hub and your Device Provisioning Service instance. Make sure that you are passing the correct DPS scope ID, Enrollment group primary key and IoT Hub connection string to the environment variables. You can check the values of the variables using the following command
                  echo %VARIABLE_NAME
      
      Replace "VARIABLE_NAME" with the name of the environment variable you want to view.
    2. In addition to setting up the environment variables, you would also need to follow the steps provided in the Download the model files and Install the Azure IoT explorer for this approach to work.

    The JSON error you see is most likely from the misconfiguration of this JSON files.

    I would recommend using the first approach as it is easier to implement and less error prone. Hope this helps. Please do not hesitate to reach out to us through the comments below with any additional questions. We would be glad to help you.


    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.


0 additional answers

Sort by: Most helpful