Why is the log of device-cloud communication displayed in Base64-encoded format in the console rather than in the JSON format in which the data is passed?
Check whether you set the data format to custom format during product creation, and if so, the data will be Base64-encoded after it is transferred to the cloud. To display data in JSON format, you need to select the JSON format as the data format during product creation.
The demo for Android is in the corresponding application module of hub-demo
in the GitHub repository.
You can enter the PRODUCT_ID
, DEVICE_NAME
, and DEVICE_PSK
parameters as instructed in Device Connection Through MQTT over TCP - Overview - Entering parameters for authenticating device for connection.
It is a certificate handshake exception. Please carefully check whether the certificate and key passed in correspond to the device and whether they are correct.
What should I do if the error "Incorrect username or password" is reported when I use the SDK for Android to establish an MQTT connection?
If the device parameters (PRODUCT_ID
, DEVICE_NAME
, and DEVICE_PSK
) are all correctly configured, you can check whether the system time of the device is correct; for example, you can run adb shell date
to view the system time of an Android device.
The IoT access layer has the logic of exclusive device login. If the same device ID is logged in to in another place, the existing login will be kicked offline by the new login. Therefore, if the device keeps going online and offline, you can check whether there are different users or threads performing login operations by using the same device ID.
The onConnectionLost
callback for disconnection (32109) indicates that the device is disconnected. If this error is frequently thrown, it is because that the same device ID is logged in to multiple times and the existing login is kicked offline by the new login. You can find the log of exclusive device login (Device kicked) in Cloud Log in the console. As the connect
method is async, the connection is successful only after onConnectCompleted
is called back and the status becomes OK
. After onDisconnectCompleted
is called back successfully when the device is disconnected, call the connect
method again to create a new connection to make the device online.
You can view the message sending status in Cloud Log in the console. If it shows that the device is disconnected (device offline), check whether the device is online. If it shows "no subscriber", the device has not subscribed to the topic. If a QoS 1 message is sent and the device does not reply with an ack
(processed by the SDK internally), the backend will send it again. However, if a QoS 0 message isn't replied to with an ack
, the backend will not send it again.
You need to set setCleanSession
in MqttConnectOptions
to false
and the QoS level to QoS 1 during connection. After the device subscribes to the topic after connection, it can receive up to 150 heaped messages stored for up to 24 hours per device.
This is because that the device information passed in during MQTT connection doesn't match. You need to check the device information passed in (product ID, device name, and device key or device private key).
This error is caused by the version incompatibility between the two libraries (bcprov-jdk15on
and bcpkix-jdk15on
) that the SDK depends on and the JDK development environment. You can downgrade their versions.
dependencies {
...
implementation 'org.bouncycastle:bcprov-jdk15on:1.65'
implementation 'org.bouncycastle:bcpkix-jdk15on:1.65'
implementation ('com.tencent.iot.hub:hub-device-android-core:x.x.x') {// `x.x.x` is the version number of the imported SDK
exclude group: 'org.bouncycastle'
}
...
}
In options.setKeepAliveInterval(240)
, the unit of 240
is second. The server will use the maximum interval of keepalive*1.5
set by the client to determine whether a heartbeat packet is received and whether to disconnect from the client.
options.setAutomaticReconnect(true);
What should I do if the ERROR
is Connection failed
and msg
is MqttException (0) - javax.net.ssl.SSLHandshakeException
in the status
in the onConnectCompleted
callback?
If ssl://${ProductId}.iotcloud.tencentdevices.com:8883
is connected in the key authentication log, you need to add options.setSocketFactory(AsymcSslUtils.getSocketFactory());
to configure the handshake settings.
What should I do if the SocketFactory
type specified in the exception MqttClient connect failed
doesn't match the proxy URI (32105).
If tcp://${ProductId}.iotcloud.tencentdevices.com:1883
is connected in the key authentication log, you can remove options.setSocketFactory(AsymcSslUtils.getSocketFactory());tcp
with no need to configure the handshake settings.
What should I do if "code:1021,message: Device has been activated" is returned during dynamic registration?
This error indicates that the device corresponding to the device information passed in during dynamic registration has already been activated and cannot be dynamically registered again. You can delete it in the console and get its device key or certificate information through dynamic registration again.
This is because that the server domain name (iotcloud-mqtt.gz.tencentdevices.com) in the SDK v3.2.0 you use is legacy. Starting from SDK v3.2.1, the new domain name ${ProductId}.iotcloud.tencentdevices.com
is used. To solve this error, please update the SDK version. Note: the product manager replied that "although the new domain name is available, the legacy versions of the SDK can still use the legacy domain name", so this error may also be because that the local DNS goes wrong and the host cannot be resolved correctly.
In the proguard-rules.pro
file, add the following rules to add the classes related to the SDK to the "do not obfuscate" list:
-keep class org.apache.log4j.** { *; }
-keep class de.mindpipe.android.logging.log4j.** { *; }
-keep class org.eclipse.paho.client.mqttv3.** {*;}
-keepclasseswithmembers class org.eclipse.paho.** {*;}
For more information, please see the configuration in the demo.
What should I do if the error "java.lang.IllegalArgumentException: no NetworkModule installed for scheme" is reported after the obfuscation rules are configured?
Check the version number 'com.android.tools.build:gradle:x.x.x' of the Gradle plugin in the build.gradle file in the project root directory. We recommend v3.6 or above.
The limit is 16 KB.