1

Hi I am using Android paho library for getting connect with an mqtt server.

My app level Gradle side Code :

implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0'
implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'

Project Level

allprojects {

    repositories {
        jcenter()
        maven {
            url "https://repo.eclipse.org/content/repositories/paho-snapshots/"
        }
        maven { url "https://jitpack.io" }
        maven {
            url "https://maven.google.com"
        }
    }
}

In Manifest File

<service android:name="org.eclipse.paho.android.service.MqttService" />

permisiions

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

My issue is I am able to connect, publish data and subscribe to a topic when my server url is tcp://:1883

When I changed my url to mqtts://:8883 its failed to get connect

So what is the difference in the schemes tcp:// and mqtts:// or mqtt:// Why I am not able to connect if scheme starts with mqtt?

Please help!!!

Zoe
  • 27,060
  • 21
  • 118
  • 148
Sonia John Kavery
  • 2,099
  • 2
  • 20
  • 36

2 Answers2

0

tcp://hostname:1883 and mqtt://hostname:1883 are exactly the same.

mqtts://hostname:8883 is MQTT over TLS and will require that the broker has been correctly configured to support a TLS connection on port 8883.

Without details of the error when it fails to connect we can say nothing more.

hardillb
  • 54,545
  • 11
  • 67
  • 105
0

FYI - in order use Paho Android Client over TLS/SSL I found it invaluable to follow this example: https://www.emqx.com/en/blog/android-mqtt-ssl-tls-authentication

Unfortunately, a tiny but crucial missing bit of information is to mention about how to properly change the MQTT broker URL - for this I spent an enormous amount of time searching and finally found that golden nugget here: https://www.thethingsnetwork.org/forum/t/cannot-connect-to-mqtt-broker-over-tls-port/48316

So using the above-mentioned "mqtts://hostname:8883" failed to make a simple test connect to test.mosquitto.org using their CA certificate provided at their website.

It only finally connected by using "ssl://test.mosquitto.org:8883"

The most hideous (and thereby time-consuming) aspect of this was that the failure was silent - nothing showed up on the Android Studio LogCat, no Exception thrown, nada.

I am sure that to all the programmers with even minimal internet/stack experience it is soooooo obvious that you have to change 'tcp' to 'ssl' whenever you change 1883 to 8883, but not to a noob - it's a painful lesson to be well remembered.

Scott Lohr
  • 74
  • 7