How to allow remote connection of Paho MQTT client to Mosquitto MQTT broker hosted on Digital Ocean

I have hosted the mosquitto MQTT broker on Digital Ocean Cloud following this tutorial. ( I tried to connect it to the Paho MQTT Android Client to which it could not connect. To debug I removed the SSL certificates that were added to the broker through letsencrypt but still it could not connect.This is my /etc/mosquitto/conf.d/default.conf file. I have also allowed firewall for port 1883.

allow_anonymous true
 password_file /etc/mosquitto/passwd

 listener 1883
 protocol mqtt

Here is my Android code:

public class MainActivity extends AppCompatActivity {

public MqttAndroidClient CLIENT;
public MqttConnectOptions MQTT_CONNECTION_OPTIONS;


protected void onCreate(Bundle savedInstanceState) {
    String clientId = MqttClient.generateClientId();
    MqttAndroidClient client =
            new MqttAndroidClient(this.getApplicationContext(), 

    try {
        IMqttToken token = client.connect();
        token.setActionCallback(new IMqttActionListener() {
            public void onSuccess(IMqttToken asyncActionToken ) {
                // We are connected
                Log.d("mqtt", "connected, token:" );

            public void onFailure(IMqttToken asyncActionToken, Throwable 
                                  exception) {
                // Something went wrong e.g. connection timeout or 
                   firewall problems
                Log.d("mqtt", "not connected" + exception.toString());

    } catch (MqttException e) {


These are the error I am getting in android:

D/AlarmPingSender: Unregister alarmreceiver to
2020-06-18 21:44:29.316 9084-9115/com.example.testmqtt D/AlarmPingSender:
Unregister alarmreceiver to MqttServicepaho16017475349560
2020-06-18 21:44:51.127 9084-9118/com.example.testmqtt D/AlarmPingSender:
Unregister alarmreceiver to MqttServicepaho16008840983860
2020-06-18 21:44:51.145 9084-9084/com.example.testmqtt D/mqtt: not
connectedMqttException (0) - connect timed

Please guide me on how I should try to solve this error. I will be grateful for your guidance.


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!