Obtain Log via JSBridge

2022-07-19
No Rating

Overview

In the process of using DJI Pilot 2, it is inevitable to encounter problems such as abnormal interface communication and function failure, and it is necessary to pull the DJI Pilot 2 log for diagnosis(Refer to Log Export). In order to solve this problem, DJI Pilot 2 also provides JSBridge interface for developers to pull the log. And upload the Webview to the developer's own server for analysis.

Note:

DJI Pilot 2 logs are encrypted, so the developer needs to provide the public key information for log encryption through the JSBridge interface, and the pulled logs also need to be decrypted to view them. DJI provides a JAR library for decrypting logs that can be decrypted by developers running scripts.

Decryption method: Use plogdecoder. jar library to run scripts to decrypt the pulled logs. Download

Example:

java -jar PlogDecoder.jar -key "Desktop/rsa_keys/pri.key" -log "/open_platform/log-2022-01-18.log".
//If the public key is not set, you can omit the -key parameter.

API Interface

Get Logs Path

The developer can get the path to the logs saved by the DJI Pilot 2 via the js method and then can upload the logs via file upload.

API: Refer to App API > JSBridge API References-window.djiBridge.platformGetLogPath()

Set Logs Encrypt Key

DJI Pilot 2 encrypts the logs when they are saved. If no encryption key has been set by the developer, it will be encrypted according to DJI Pilot 2's default key. If a key is set, the logs will be encrypted according to the developer's key.

API: Refer to App API > JSBridge API References-window.djiBridge.platformSetLogEncryptKey(String key)

Clear Logs Encrypt Key

If the encryption key set by the developer needs to be changed, you will need to clear the key saved in DJI Pilot 2 and then set it again.

API: Refer to App API > JSBridge API References-window.djiBridge.platformClearLogEncryptKey()

Note: When clearing the encryption key, if there is already part of the log using the original key, it will not be re-encrypted. In this case, the developer needs to save the historical key himself to prevent the log file from not being opened.