1

with the code below i am able to retrieve serial number of the dji drone remote controller. however, I cannot get battery level. is there anyway I can retrieve battery level? please advise.

the code for serial number (which is fine):

public void getSerialNumber(CommonCallbacks.CompletionCallbackWith<String> callback)
    {
        if(baseProduct != null && baseProduct.isConnected()) {
            if (baseProduct instanceof Aircraft) {
                ((Aircraft) baseProduct).getFlightController().getSerialNumber(callback);
            }
            else callback.onFailure(null);
        }
        else callback.onFailure(null);
    }

the code for remaining battery (which doesn't work):

public void getBatteryLevel(CommonCallbacks.CompletionCallbackWith<Integer> callback)
    {
        if(baseProduct != null && baseProduct.isConnected()) {
            if (baseProduct instanceof Aircraft) {
                ((Aircraft) baseProduct).getBattery().getChargeRemaining(callback);
            }
            else callback.onFailure(null);
        }
        else callback.onFailure(null);
    }
Andrej Istomin
  • 2,527
  • 2
  • 15
  • 22
Shareef
  • 53
  • 2
  • 13

1 Answers1

1

The code you have provided looks correct, assuming that baseProduct is a valid reference to your DJI remote controller.

However, to get the battery level of the remote controller, you need to call the getRemoteControllerBatteryInfo method instead of getBatteryLevel as follows:

public void getBatteryLevel(CommonCallbacks.CompletionCallbackWith<Integer> callback) {
    if (baseProduct != null && baseProduct.isConnected()) {
        if (baseProduct instanceof Aircraft) {
            ((Aircraft) baseProduct).getRemoteController().getBatteryInfo().getChargeRemainingInPercent(callback);
        } else {
            callback.onFailure(null);
        }
    } else {
        callback.onFailure(null);
    }
}

This will return the battery level of the remote controller as an integer between 0 and 100, representing the percentage of charge remaining.

Make sure that your app has the necessary permissions to access the DJI SDK functions, and that the remote controller is connected to the aircraft and turned on before calling this method.

  • when I use this code, it showed this error: Cannot resolve method 'getBatteryInfo' in 'RemoteController' – Shareef Apr 05 '23 at 11:12