MQTT client connect attempt failed - ESP8266/ESP32 to Azure IOT Central

yash shah 0 Reputation points
2024-03-01T02:35:03.04+00:00

Seeing this error on Serial Monitor when attempting to connect ESP32 to Azure IOT Central using the Azure provided example for ESP32 to AzureIOTCentral

  • ERROR: MQTT client connect attempt failed. Check host, deviceId, username and password. (state -2)
  • Is connected ? NO (4)

X - Error at connection.h:32

Error @ iotc_connect. Code 1
  • ERROR: Client was not connected.
    • iotc.dps : getting auth...
    • iotc.dps : getting operation id...
    • iotc.dps : getting host name...

The deviceid, username, and password have been triple checked

Azure IoT Central
Azure IoT Central
An Azure hosted internet of things (IoT) application platform.
347 questions
{count} votes

1 answer

Sort by: Most helpful
  1. LeelaRajeshSayana-MSFT 13,471 Reputation points
    2024-03-01T22:34:40.86+00:00

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

    I am checking to see if you are using the sample provided in the GitHub sample The sample uses Azure IoT Central Provisioning Service ID Scope, your device registration ID and device ID for authenticating with the Azure IoT Central application. The article Quickstart: Connect an ESPRESSIF ESP32-Azure IoT Kit to IoT Central provides the detailed steps needed to set up the device on IoT Central and configure the sample code to connect the device.

    I highly appreciate it if you can review the approach suggested in the article and let us know if you still encounter any issues with connecting to the IoT central application.


    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 comments No comments