Search code examples
androiddji-sdk

DJI remote controller data is null


Context

I'm trying to get the following data from the remote controller: name, lower signal strength between the two antenna and the GPS data.

Problem

All those data are coming null. The only exception is for the Phantom 4 Pro V2, that the name is coming as a replacement character (black diamond with a white question mark).

Code

@NonNull
public RemoteControllerInfo getRemoteControllerInfo() {
  final String name = (String) getValueFromDjiKey(
    RemoteControllerKey.create(RemoteControllerKey.NAME)
  );
  
  final LightbridgeAntennaRSSI antennas =
    (LightbridgeAntennaRSSI) getValueFromDjiKey(
      AirLinkKey.create(AirLinkKey.REMOTE_CONTROLLER_ANTENNA_RSSI)
    );
  final Integer signalStrengthInPercent = antennas == null
    ? null
    : Math.min(antennas.getAntenna1(), antennas.getAntenna2());
  
  final RemoteControllerGps remoteControllerGps;
  final GPSData gpsData = (GPSData) getValueFromDjiKey(
    RemoteControllerKey.create(RemoteControllerKey.GPS_DATA)
  );
  if (gpsData != null && gpsData.isValid()) {
    final GPSData.GPSLocation gpsLocation = gpsData.getLocation();
    final GPSData.Time gpsDateTime = gpsData.getTime();
    remoteControllerGps = RemoteControllerGps.builder()
      .latitude(gpsLocation.getLatitude())
      .longitude(gpsLocation.getLongitude())
      .year(gpsDateTime.getYear())
      .month((int) gpsDateTime.getMonth())
      .day((int) gpsDateTime.getDay())
      .hour((int) gpsDateTime.getHour())
      .minute((int) gpsDateTime.getMinute())
      .second((int) gpsDateTime.getSecond())
      .build();
  }
  
  return RemoteControllerInfo.builder()
    .name(name)
    .signalStrengthPercentage(signalStrengthInPercent)
    .remoteControllerGps(remoteControllerGps)
    .build();
}

@Nullable
private Object getValueFromDjiKey(@Nullable final DJIKey key) {
  final Object[] result = new Object[1];
  
  final CountDownLatch onFinishSignal = new CountDownLatch(1);
  KeyManager.getInstance().getValue(key, new GetCallback() {
    @Override
    public void onSuccess(@NonNull final Object o) {
      result[0] = o;
      
      onFinishSignal.countDown();
    }
    
    @Override
    public void onFailure(@NonNull final DJIError djiError) {
      onFinishSignal.countDown();
    }
  });
  synchronized (onFinishSignal) {
    try {
      onFinishSignal.await();
    } catch (final InterruptedException ignored) {
    }
  }
  
  return result[0];
}

Environment:

  • Phantom 4 Pro/Pro V2/Advanced/Standard
  • Android 9
  • MSDK v4.13.1

Solution

  • If I understand your problem, you are calling the SDK to read GPS data from the remote controller for the Phantom series controller?

    The controller for the Phantom aircrafts do not have built-in GPS so the values would be null.

    If I remember correctly, only the controllers for the Inspire series (and maybe the other higher-end aircraft controllers) include GPS.