eclipse-ditto / ditto

Eclipse Ditto™: Digital Twin framework of Eclipse IoT - main repository

Home Page:https://eclipse.dev/ditto/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mqtt connection status is "misconfigured"

carozo opened this issue · comments

Hello. First of all, thank you for the amazing work!
I am running into an issue that I'm not quite sure how to fix. I'm trying to connect a mobile app and Eclipse Ditto using Mosquitto as a broker.

The connection between Ditto and Mosquitto is showing the status "misconfigured":
Screenshot 2024-06-25 at 23 32 31
and the error message is:

Socket could not be opened for 172.17.0.2:1883 due to Connect timed out
At first I thought that it may be that the broker is not running correctly, but the mobile app seems to be connected fine to Mosquitto.

This is the command I used to create the connection:

curl -X POST \
 'http://localhost:8080/devops/piggyback/connectivity?timeout=10' \
 -H 'Content-Type: application/json' \
 -u 'devops:foobar' \
 -d '{
   "targetActorSelection": "/system/sharding/connection",
   "headers": {
       "aggregate": false
   },
   "piggybackCommand": {
       "type": "connectivity.commands:createConnection",
       "connection": {
           "id": "mqtt-connection-android",
           "connectionType": "mqtt",
           "connectionStatus": "open",
           "failoverEnabled": true,
           "uri": "tcp://ditto:ditto@'"$mosquitto_ip"':1883",
           "sources": [{
               "addresses": ["android:mobile/things/twin/commands/modify"],
               "authorizationContext": ["nginx:ditto"],
               "qos": 0,
               "filters": []
           }],
           "targets": [{
               "address": "android:mobile/things/twin/events/modified",
               "topics": [
               "_/_/things/twin/events",
               "_/_/things/live/messages"
               ],
               "authorizationContext": ["nginx:ditto"],
               "qos": 0
           }]
       }
   }
}'

I can't figure out what I'm doing wrong. Any help would be greatly appreciated. Thanks!

I assume you are running ditto on your local computer and Mosquitto is running on some public server? Some hints:

  • Try to reach your Mosquitto from the same machine like you run ditto with e.g. mosquito_sub or mosquito_pub
  • How is authentication set-up in your Mosquitto broker? Do you use the same default ditto credentials for your MQTT server? How does your Android authenticate to the broker? I don't fully understand
  • You may give a try to connect to the sandbox Mosquitto hosted by Eclipse tcp://test.mosquitto.org:1883. There are several samples for ditto connections around. May be that helps to explore your issue.

Socket could not be opened

That looks like a network issue, eg you use the external IP of the mosquito server instead of the (docker network) internal one.

Do you use docker compose?
Then you should be able to just use the service name as hostname, the Docker DNS should resolve that correctly in the Docker network.

Thank you @thjaeckle and @thfries!
Yes, I am using docker compose, the IP of the mosquitto server was the issue.
In case anyone else runs into this issue, I was able to connect using my host IP in the local network ("localhost" didn't work).
Everything is working as expected now.
Thank you for your help, keep up the good work!