简体   繁体   English

如何启用Paho Mqtt Android客户端登录Android Studio

[英]How to enable Paho Mqtt Android Client logging in Android Studio

I have followed examples and docs to run MqttAndroidClient and successfully connect and pub/sub with mosquito broker, both in open and secure to ports 1883, 8883, 8884, & 8885. This success is built with this: implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1 implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.0我已经按照示例和文档运行 MqttAndroidClient 并成功连接和发布/订阅 mosquito 代理,在开放和安全端口 1883、8883、8884 和 8885 上。这个成功是建立在这个: implementation 'org.eclipse.paho :org.eclipse.paho.android.service:1.1.1 实施 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.0

But to connect to AWS IOT, I need the SNI extension added to mqttv3:1.2.3 or later.但是要连接到 AWS IOT,我需要将 SNI 扩展添加到 mqttv3:1.2.3 或更高版本。 Keeping it simple for now, just still connecting with mosquito broker, connection fails as soon as I use mqttv3:1.2.1 or later.现在保持简单,只是仍然与蚊子代理连接,一旦我使用 mqttv3:1.2.1 或更高版本,连接就会失败。

So I need to enable the mqttv3 logging to diagnose why, but I am bewildered on how to do it in Android Studio even after looking over some similar questions for command line invocation of java.因此,我需要启用 mqttv3 日志记录来诊断原因,但我对如何在 Android Studio 中执行此操作感到困惑,即使在查看了 java 的命令行调用的一些类似问题之后也是如此。

I have added the AndroidClient logging:我添加了 AndroidClient 日志记录:


mqttClient = MqttAndroidClient(context, serverURI, "PleaseHelpMeLog")


mqttClient.setTraceCallback(object : MqttTraceHandler {
    override fun traceDebug(tag: String?, message: String?) {
        Log.d("$tag", "$message")
    }

    override fun traceError(tag: String?, message: String?) {
        Log.d("$tag", "$message")
    }

    override fun traceException(tag: String?, message: String?, e: java.lang.Exception?) {
        Log.d("$tag", "$message")
    }
}
)

mqttClient.setTraceEnabled(true)

And I got the source of the failure in an AndroidClient log: connect fail, call connect to reconnect.reason:MqttException我在 AndroidClient 日志中得到了失败的根源:connect fail, call connect to reconnect.reason:MqttException

But this is not the mqttv3 logging, which I would need for what leads up to "MqttException".但这不是 mqttv3 日志记录,我需要它才能导致“MqttException”。

If I could get to the mqttClient used by the AndroidClient, I understand that I could use something like mqttDebug = mqttClient.getDebug() and then mqttDebug.dumpClientDebug()如果我可以访问 AndroidClient 使用的 mqttClient,我知道我可以使用类似 mqttDebug = mqttClient.getDebug() 然后 mqttDebug.dumpClientDebug()

How can this be enabled in an Android Studio build?如何在 Android Studio 构建中启用此功能?

I have found a way to enable the FINE logs from Paho buried in this AWS-Amplify issue: https://github.com/aws-amplify/aws-sdk-android/issues/3022我找到了一种方法来启用隐藏在这个 AWS-Amplify 问题中的 Paho 的 FINE 日志: https://github.com/aws-amplify/aws-sdk-android/issues/3022

To view the Paho logs, create a new file called newlogging.properties and save it in the app/src/main/res/raw/ directory of your project.要查看 Paho 日志,请创建一个名为 newlogging.properties 的新文件并将其保存在项目的 app/src/main/res/raw/ 目录中。 Add the following to that file:将以下内容添加到该文件:

handlers= java.util.logging.ConsoleHandler
# Global logging level.
.level= FINEST
# default file output is in user's home directory.
java.util.logging.FileHandler.pattern = %h/java%u.log
java.util.logging.FileHandler.limit = 50000
java.util.logging.FileHandler.count = 1
java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter
# Limit the message that are printed on the console to FINEST and above.
java.util.logging.ConsoleHandler.level = FINEST
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter

The file contents above are essentially a copy of the logging.properties file from the Java installation but with lower logging levels in order to see the debug logs from Paho.上面的文件内容本质上是 Java 安装中的 logging.properties 文件的副本,但具有较低的日志记录级别,以便查看来自 Paho 的调试日志。 Also add the following code to your app before creating the AWSIotMqttManager, which will set the logging properties to the newlogging.properties file created:在创建 AWSIotMqttManager 之前,还要将以下代码添加到您的应用程序,这会将日志记录属性设置为创建的 newlogging.properties 文件:

LogManager logManager = LogManager.getLogManager();
try {
    Context context = getApplicationContext();
    int resourceId = context.getResources().getIdentifier("newlogging", "raw", context.getPackageName());
    InputStream inputStream = context.getResources().openRawResource(resourceId);
    logManager.readConfiguration(inputStream);
} catch (IOException e) {
    e.printStackTrace();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将Paho-MQTT添加到android studio - how to add Paho-MQTT to android studio 如何在android中实现必须在多个活动中访问的paho MQTT客户端 - How to implement paho MQTT client in android that has to be accessed in multiple activities 如何强制 MQTT 代理不从 Android Paho 客户端清除 session? - How to force MQTT broker to NOT clean session from Android Paho client? Android上的Eclipse Paho MQTT客户端,性能较差 - Eclipse Paho MQTT client on Android, poor performance PAHO MQTT Android客户端,用于服务和MainActivity BinderProxy - PAHO MQTT Android client for service and MainActivity BinderProxy Paho Mqtt Android客户端未在Android中收到任何消息 - Paho Mqtt Android client is not receiving any message in Android 如何将 PAHO/Eclipse MQTT Android 服务带入 Android Studio 项目 - How can I bring the PAHO/Eclipse MQTT Android Service into an Android Studio Project 为什么Eclipse Paho Android MQTT客户端返回订阅失败? - Why Eclipse Paho Android MQTT Client Returns Subscribtion Failed? Android上的MQTT Eclipse Paho客户端,断开挂起并永不完成 - MQTT Eclipse Paho client on Android, disconnect hangs and never completes MQTT Paho Client无法自动重新连接到Android Service上的代理 - MQTT Paho Client not reconnect automatically to broker on Android Service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM