mqtt.js returned Failure on first connection (Not authorized): Connection refused: Not authorized error

Jonas Trumpfheller 21 Reputation points
2021-02-18T09:38:56.157+00:00

Hi,

i am trying to connect a raspberry pi to my IoT-Hub. I am using this tutorial: iot-hub-raspberry-pi-kit-node-get-started

but when i am this command: sudo node index.js '<YOUR AZURE IOT HUB DEVICE CONNECTION STRING>'

i get this Error: "mqtt.js returned Failure on first connection (Not authorized): Connection refused: Not authorized error"

I hope you can help me.

Thank you very much.

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

1 answer

Sort by: Most helpful
  1. Sander van de Velde | MVP 31,931 Reputation points MVP
    2021-02-18T10:09:05.22+00:00

    Hello @Jonas Trumpfheller ,

    did you fill in your own specific IoT Hub Device connection string?

    if looks like

    HostName=mslearn.azure-devices.net;DeviceId=testdevice;SharedAccessKey=0iE[skipped big part]wY=  
    

    You find it in the Azure Portal:

    69521-image.png

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.