Skipping DPS layer to connect directly to IoT hub results in "client not authorized" error

Anoop Chandran 25 Reputation points
2023-08-04T19:11:56.28+00:00

Hello,

I am using iot-middleware-freertos-samples to implement MQTT in my project. I am able to establish the MQTTS connection, subscribe to the required topics and send telemetry data to the IoT hub after connecting to the DPS layer.

However, connecting through the DPS layer and then to the IoT hub is taking too long each time the device boots up. I tried skipping the DPS connection by saving the DEVICE id and HUB URL from the first connection and connecting directly to the IoT hub. But I received an error response of "05" which says client is not authorized to connect.

Can someone help me figure out if I missed any other details from the DPS connection?

Thank you,

Anoop

Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,120 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Sander van de Velde 28,546 Reputation points MVP
    2023-08-04T22:23:51.67+00:00

    Hello @Anoop Chandran,

    once a device connection string is established, you should be able to skip the DPS enrollment step.

    Only when the IoT Hub denies access, accessing the DPS could be a plausible solution.

    This will work for most DPS linking scenarios except for mobile devices, depending on the lowest latency.

    This brings us to the unexpected behavior you experience.

    In this scenario, I assume you use an individual enrollment based on symmetric keys.

    You need to store the complete device connection string, looking like this:

    HostName=[iot hub name].azure-devices.net;DeviceId=[device name];SharedAccessKey=[primary key]
    
    

    The primary key could be the same as the one used for individual PDS enrollment.

    The device name could differ from the registration name though.

    Compare the connection string with the one seen in the portal to be sure:

    User's image


    If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. All community members with similar issues will benefit by doing so. Your contribution is highly appreciated.