OPCFoundation / UA-CloudCommander

A cross-platform OPC UA cloud command & control reference implementation leveraging MQTT and Kafka. It runs in a Docker container and executing commands, reads and writes on on-prem OPC UA servers from the cloud.
MIT License
21 stars 6 forks source link

Azure IoT Hub MQTT broker configuration - connection failed #3

Closed Lyvz closed 2 years ago

Lyvz commented 2 years ago

Hi!

First of all thanks for sharing this module! It seems to be just what I was looking for.

Problem description and what I've tried:

I'm trying to deploy this as an Azure IoT Edge module and I tried setting the environment variables as instructed. I keep running into the same error:

Connection to MQTT broker failed with 5!

So I guess the MQTT client fails to connect with the given client name, username and password.

For MQTT_CLIENTNAME I have <my IoT Device name>/<my IoT Edge Module Name>.

For MQTT_USERNAME I'm using the instructed string.

For MQTT_PASSWORD I have tried the "iothubowner" and "device" keys from the Shared access policies. I also tried the Primary Key from my IoT Edge device.

With these settings I also set the CREATE_SAS_PASSWORD environment variable (='true'). Then I tried to omit this and I generated a SAS token from my Azure CLI and set that as the MQTT_PASSWORD.

What I think could help:

Knowing which key to select from IoT Hub could help me rule out some issues. Also I would like to know if you tested that the SAS password generation works.

I will look into my firewall settings next and see if that could be the cause.

Sorry if the issue seems a bit trivial. I'm just starting out with IoT Edge modules and MQTT messaging.

Thanks!

Lyvz commented 2 years ago

Solved the issue by setting my uacommander IoT Edge Module primary key as the MQTT_PASSWORD.

barnstee commented 2 years ago

Ah good, I was just about to look into it! :-) Did you see this file? https://github.com/barnstee/UACommander/blob/main/.env.local

Lyvz commented 2 years ago

Yeah that's where I got the correct ideas for the environment variables. Just the password wasn't instantly intuitive to me and I falsely assumed it had to be one of the keys under IoT Hub's Shared access policies.

Thanks again!

barnstee commented 2 years ago

Yeah, good point, I just updated the docs to make that a little clearer.