Search code examples
azuremqttioteclipse-dittoeclipse-iot

Create connection from Eclipse-ditto to Azure IoT hub using MQTT


I'm trying to create an outgoing connection from Ditto to Azure IoT hub using MQTT. We are in charge of Ditto while somebody else (interested in the digital twin Live data) is in charge of the Azure IoT Hub. I'm getting following error while connecting with Azure IoT hub (in Connectivity micro service): Not authorized to connect (5). we also tried connecting with mosquitto_pub and received the same error when we omitted the -i client-id option. Everything else seems ok.

Some extra information:

  • This is the mosquitto_pub command which currently works:
    mosquitto_pub -h [hostname] -p [port] -t [topic] -m "" -u [username] -P [password] --cafile cert.cer -i [deviceName]
  • We have been provided with the hostname, port, topic, username (which is a long string containing slaches, dashes and equality operators), password (which is also a long string containing spaces, percentage signs and equality operators) and a certificate file. I've URL encoded the username and the password and stitched them together in the connecting url as described on the ditto page (https://www.eclipse.org/ditto/connectivity-protocol-bindings-mqtt.html): ssl://[url-encoded-username]:[url-encoded-password]@[hostname]:[port-number].
  • I've added the certificate and I'm not getting the certificate error ("unable to find valid certification path to requested target") anymore.

Does anyone have experience with this?
Maybe the solution is using another protocol (amqp for example)?
Hopefully I haven't missed any other relevant questions or information on the internet. If so, please show me where I can find it.

Thanks


Solution

  • Ditto appends "-publisher" to the ID of an outgoing connection.
    However, Azure IoT Hub expects the connectionID to be the same as the device configured in the Azure IoT Hub. To get it to work for the device/connection called 'test', you should do the following:

    • Create a new incoming connection in Azure IoT Hub named "test-publisher"
    • Create a ditto outgoing connection with:
      • ID: 'test'
      • Connection details provided by Azure IoT Hub including "test-publisher"