Device fails to create MQTT connection to Azure DPS

Wang, David 25 Reputation points
2023-03-06T10:44:31.2833333+00:00

I am trying to connect with a device to Azure DPS, but keep getting MQTT CONNACK with error code 5 (The Client is not authorized to connect).

"

/api-version=2019-03-31&ClientVersion=1.3.7 | CLEAN: 130 | USERNAME: 0ne001A13DC/registrations/80220928000279

<- 09:36:04 CONNACK | SESSION_PRESENT: false | RETURN_CODE: 0x5

"

Would you please tell what kind of inputting information involved in MQTT CONNECT request will result in CONNACK(error code 5)?MQTT connection fail.png

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

Accepted answer
  1. AshokPeddakotla-MSFT 27,401 Reputation points
    2023-03-08T15:55:29.2533333+00:00

    Wang, David Welcome to Microsoft Q&A forum!

    Which documentation are you following? How exactly are you connecting a device to DPS?

    Did you check Communicate with your DPS using the MQTT protocol?

    /api-version=2019-03-31&ClientVersion=1.3.7 | CLEAN: 130 | USERNAME: 0ne001A13DC/registrations/80220928000279 <- 09:36:04 CONNACK | SESSION_PRESENT: false | RETURN_CODE: 0x5

    The error code 5 in the MQTT CONNACK response indicates that the client is not authorized to connect. This error can occur if the SAS token used in the MQTT CONNECT request is invalid or has expired.

    To resolve this issue, you should check the format of the SAS token and make sure it is correct. The format of the SAS token should be the same as for both the HTTPS and AMQP protocols: SharedAccessSignature sr={URL-encoded-resourceURI}&sig={signature-string}&se={expiry}&skn=registration The resourceURI should be in the format {idScope}/registrations/{registration_id}. The policy name (skn) should be set to registration.

    If you need further help in this matter, please comment in the below section and we are happy to discuss!


    If this answers your query, do click Accept Answer and Yes for this answer as helpful. And, if you have any further query do let us know by commenting in the below section.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful