Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Paho » Problem connecting mqtt for smart watch(connection failure)
Problem connecting mqtt for smart watch [message #1840586] Mon, 19 April 2021 22:15
volkan koç is currently offline volkan koçFriend
Messages: 2
Registered: April 2021
Junior Member
Hello to everyone
I want to do mqtt communication for amazfit verge smart watch. The code I wrote works fine on the phone and on the emulator. But it doesn't work on the hour.
The watch has wifi and an active internet connection.
I am getting a connection failure error. I cannot see the details of the error either.

I tested the clock with a different apk that I installed externally and mqtt can work. But I want to run the code I wrote myself.

I would be glad if you could help.

Amazfit verge use Android 5.1

Android manifest xml
<?xml version="1.0" encoding="utf-8"?>

    package="com.dai.dai_clock">
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service android:name="org.eclipse.paho.android.service.MqttService" />
    </application>

</manifest>


MainActivity.java

package com.dai.dai_clock;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import org.eclipse.paho.android.service.MqttAndroidClient;
import org.eclipse.paho.client.mqttv3.IMqttActionListener;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.IMqttToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;

public class MainActivity extends AppCompatActivity {
    private final String TAG = "dmqtt";
    MqttAndroidClient mqttAndroidClient;
    final String host = "tcp://broker.emqx.io:1883";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        /* Create an MqttAndroidClient object and configure the callback. */
        MqttConnectOptions mqttConnectOptions = new MqttConnectOptions();
        mqttConnectOptions.setCleanSession(true);

        mqttAndroidClient = new MqttAndroidClient(getApplicationContext(), host, "client");
        mqttAndroidClient.setCallback(new MqttCallback() {
            @Override
            public void connectionLost(Throwable cause) {
                Log.i(TAG, "connection lost");
            }

            @Override
            public void messageArrived(String topic, MqttMessage message) throws Exception {
                Log.i(TAG, "topic: " + topic + ", msg: " + new String(message.getPayload()));
            }

            @Override
            public void deliveryComplete(IMqttDeliveryToken token) {
                Log.i(TAG, "msg delivered");
            }
        });

        /* Establish a connection to IoT Platform by using MQTT. */
        try {
            mqttAndroidClient.connect(mqttConnectOptions, null, new IMqttActionListener() {
                @Override
                public void onSuccess(IMqttToken asyncActionToken) {
                    Log.i(TAG, "connect succeed");

                  
                }

                @Override
                public void onFailure(IMqttToken asyncActionToken, Throwable exception) {
                    Log.i(TAG, "connect failed");
                  
                }
            });

        } catch (MqttException e) {
            e.printStackTrace();
        }




    }



logcat
04-20 01:03:07.261 6302-6302/? I/art: Late-enabling -Xcheck:jni
04-20 01:03:07.932 6302-6314/com.dai.dai.clock W/art: Suspending all threads took: 17.628ms
04-20 01:03:07.941 6302-6314/com.dai.dai.clock I/art: Background sticky concurrent mark sweep GC freed 1515(90KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 619KB/619KB, paused 20.054ms total 171.853ms
04-20 01:03:08.046 6302-6314/com.dai.dai.clock W/art: Suspending all threads took: 19.964ms
04-20 01:03:08.054 6302-6314/com.dai.dai.clock I/art: Background partial concurrent mark sweep GC freed 77(18KB) AllocSpace objects, 0(0B) LOS objects, 44% free, 639KB/1151KB, paused 22.324ms total 105.548ms
04-20 01:03:08.423 6302-6302/com.dai.dai.clock W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter androidx.vectordrawable.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
04-20 01:03:08.531 6302-6314/com.dai.dai.clock I/art: Background sticky concurrent mark sweep GC freed 503(90KB) AllocSpace objects, 0(0B) LOS objects, 17% free, 948KB/1151KB, paused 6.454ms total 57.510ms
04-20 01:03:08.785 6302-6314/com.dai.dai.clock W/art: Suspending all threads took: 6.299ms
04-20 01:03:08.814 6302-6314/com.dai.dai.clock I/art: Background sticky concurrent mark sweep GC freed 163(19KB) AllocSpace objects, 0(0B) LOS objects, 12% free, 1008KB/1151KB, paused 31.963ms total 66.289ms
04-20 01:03:08.865 6302-6314/com.dai.dai.clock I/art: Background sticky concurrent mark sweep GC freed 19(7KB) AllocSpace objects, 0(0B) LOS objects, 9% free, 1036KB/1151KB, paused 20.417ms total 38.242ms
04-20 01:03:08.942 6302-6314/com.dai.dai.clock W/art: Suspending all threads took: 10.658ms
04-20 01:03:08.949 6302-6314/com.dai.dai.clock I/art: Background partial concurrent mark sweep GC freed 191(26KB) AllocSpace objects, 0(0B) LOS objects, 32% free, 1057KB/1569KB, paused 13.040ms total 75.503ms
04-20 01:03:08.966 6302-6302/com.dai.dai.clock I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$2>
04-20 01:03:08.967 6302-6302/com.dai.dai.clock I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$2>
04-20 01:03:09.425 6302-6314/com.dai.dai.clock W/art: Suspending all threads took: 6.762ms
04-20 01:03:09.437 6302-6314/com.dai.dai.clock I/art: Background sticky concurrent mark sweep GC freed 1643(155KB) AllocSpace objects, 0(0B) LOS objects, 10% free, 1407KB/1569KB, paused 10.298ms total 49.400ms
04-20 01:03:09.545 6302-6314/com.dai.dai.clock W/art: Suspending all threads took: 6.852ms
04-20 01:03:09.554 6302-6314/com.dai.dai.clock I/art: Background sticky concurrent mark sweep GC freed 26(9KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 1555KB/1569KB, paused 14.479ms total 38.327ms
04-20 01:03:09.661 6302-6314/com.dai.dai.clock I/art: Background partial concurrent mark sweep GC freed 245(36KB) AllocSpace objects, 0(0B) LOS objects, 25% free, 1548KB/2MB, paused 22.732ms total 102.915ms
04-20 01:03:09.730 6302-6318/com.dai.dai.clock D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
04-20 01:03:09.799 6302-6302/com.dai.dai.clock D/Atlas: Validating map...
04-20 01:03:09.963 6302-6318/com.dai.dai.clock I/OpenGLRenderer: Initialized EGL, version 1.4
04-20 01:03:10.073 6302-6318/com.dai.dai.clock D/OpenGLRenderer: Enabling debug mode 0
04-20 01:03:10.110 6302-6302/com.dai.dai.clock D/PowerManager: HM_acquireLocked pkg: com.dai.dai.clock tag: WakeLock (MQTT)
04-20 01:03:10.167 6302-6302/com.dai.dai.clock D/PowerManager: HM_release pkg: com.dai.dai.clock tag: WakeLock (MQTT)
04-20 01:03:10.232 6302-6302/com.dai.dai.clock W/art: Failed to open zip archive '/system/framework/telephony-common.jar': I/O Error
04-20 01:03:10.234 6302-6302/com.dai.dai.clock W/art: Failed to open zip archive '/system/framework/ims-common.jar': I/O Error
04-20 01:03:10.234 6302-6302/com.dai.dai.clock W/art: Failed to open zip archive '/system/framework/mms-common.jar': I/O Error
04-20 01:03:10.269 6302-6302/com.dai.dai.clock W/art: Failed to open zip archive '/system/framework/telephony-common.jar': I/O Error
04-20 01:03:10.269 6302-6302/com.dai.dai.clock W/art: Failed to open zip archive '/system/framework/ims-common.jar': I/O Error
04-20 01:03:10.269 6302-6302/com.dai.dai.clock W/art: Failed to open zip archive '/system/framework/mms-common.jar': I/O Error
04-20 01:03:10.278 6302-6302/com.dai.dai.clock W/art: Failed to open zip archive '/system/framework/telephony-common.jar': I/O Error
04-20 01:03:10.278 6302-6302/com.dai.dai.clock W/art: Failed to open zip archive '/system/framework/ims-common.jar': I/O Error
04-20 01:03:10.278 6302-6302/com.dai.dai.clock W/art: Failed to open zip archive '/system/framework/mms-common.jar': I/O Error
04-20 01:03:10.633 6302-6314/com.dai.dai.clock I/art: Background sticky concurrent mark sweep GC freed 5344(218KB) AllocSpace objects, 0(0B) LOS objects, 12% free, 2MB/2MB, paused 5.519ms total 28.730ms
04-20 01:03:10.891 6302-6302/com.dai.dai.clock W/art: Failed to open zip archive '/system/framework/telephony-common.jar': I/O Error
04-20 01:03:10.891 6302-6302/com.dai.dai.clock W/art: Failed to open zip archive '/system/framework/ims-common.jar': I/O Error
04-20 01:03:10.891 6302-6302/com.dai.dai.clock W/art: Failed to open zip archive '/system/framework/mms-common.jar': I/O Error
04-20 01:03:10.899 6302-6302/com.dai.dai.clock W/art: Failed to open zip archive '/system/framework/telephony-common.jar': I/O Error
04-20 01:03:10.899 6302-6302/com.dai.dai.clock W/art: Failed to open zip archive '/system/framework/ims-common.jar': I/O Error
04-20 01:03:10.900 6302-6302/com.dai.dai.clock W/art: Failed to open zip archive '/system/framework/mms-common.jar': I/O Error
04-20 01:03:10.905 6302-6302/com.dai.dai.clock W/art: Failed to open zip archive '/system/framework/telephony-common.jar': I/O Error
04-20 01:03:10.905 6302-6302/com.dai.dai.clock W/art: Failed to open zip archive '/system/framework/ims-common.jar': I/O Error
04-20 01:03:10.905 6302-6302/com.dai.dai.clock W/art: Failed to open zip archive '/system/framework/mms-common.jar': I/O Error
04-20 01:03:10.997 6302-6302/com.dai.dai.clock I/Choreographer: Skipped 49 frames!  The application may be doing too much work on its main thread.
04-20 01:03:11.044 6302-6302/com.dai.dai.clock I/dmqtt: connect failed
04-20 01:03:11.054 6302-6302/com.dai.dai.clock W/IInputConnectionWrapper: showStatusIcon on inactive InputConnection

Previous Topic:Testing MQTT for dot net sample from two windows computer
Next Topic:Paho connection/disconnection freezing
Goto Forum:
  


Current Time: Fri May 03 10:20:37 GMT 2024

Powered by FUDForum. Page generated in 0.03560 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top