Android Question DJI Component Classes

madru

Active Member
Licensed User
Longtime User
Good evening,

I am wondering if it would be possible to implement the DJIAirLink class to set the "Downlink Channel" for the downlink frequency (DJILightbridgeLink & DJIOcuSyncLink). We have massive interference on many channels in my area. :(
In DJIGo4 I can set the 'Downlink Channel' and I like to do the same with my own APP or is there a another way to set those?


THX
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Start with this untested code:
B4X:
Dim airlink As JavaObject = aircraft
   airlink = airlink.RunMethod("getAirLink", Null)
   If airlink.IsInitialized Then
       Dim WiFiLink As JavaObject = airlink.RunMethod("getWiFiLink", Null)
       If WiFiLink.IsInitialized Then
           Dim cc As Object = WiFiLink.CreateEventFromUI("dji.common.util.CommonCallbacks$CompletionCallbackWith", "callback", Null)
           WiFiLink.RunMethod("getAvailableChannelNumbers", Array(cc))
           Wait For (WiFiLink) Callback_Event (MethodName As String, Args() As Object)
           Log(MethodName)
           Dim numbers() As Object = Args(0)
           For i = 0 To numbers.Length - 1
               Log(numbers(i))
           Next
       End If
   End If

Call it from AfterAircraftConnected.
Do you see the available channel numbers?
 
Upvote 0

madru

Active Member
Licensed User
Longtime User
not really....

B4X:
java.lang.RuntimeException: Method: WiFiLink not found in: dji.sdk.airlink.AirLink
    at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(JavaObject.java:366)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:119)
    at com.dedrone.test.main$ResumableSub_ListChannel.resume(main.java:719)
    at com.dedrone.test.main._listchannel(main.java:671)
    at com.dedrone.test.main._sdk_productchanged(main.java:857)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
    at anywheresoftware.b4a.BA$2.run(BA.java:365)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5294)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
(RuntimeException) java.lang.RuntimeException: Method: WiFiLink not found in: dji.sdk.airlink.AirLink
java.lang.Exception: Sub sdk_activationstatechanged was not found.
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
    at anywheresoftware.b4a.BA$2.run(BA.java:365)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5294)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
(Exception) java.lang.Exception: Sub sdk_activationstatechanged was not found.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Maybe it is related to the newest SDK Version?

Quote from an email i got today:
Dear Developer,

We are excited to announce the release of the Windows SDK Public Beta, DJI Mobile SDK 4.8, and UX SDK 4.8. You can find them on our developer site at DJI WSDK Download, DJI MSDK Download, and DJI UXSDK Download, respectively.

Using the Windows SDK, you can now unlock the full potential of the DJI aerial platform by creating customized UWP applications. Highlights of the new SDK include control of aircraft components, Fly Safe, and Waypoint Missions.

This version of the Mobile SDK introduces support for the DJI Mavic 2 Enterprise, and includes some bug fixes and interface refinements. Please refer to the release notes for the full list of changes.

UX SDK 4.8 brings support for the Mavic 2 Pro, Mavic 2 Zoom, and Mavic 2 Enterprise, including all related accessories, as well as bug fixes. Please refer to the release notes for the full list of changes.
 
Upvote 0

madru

Active Member
Licensed User
Longtime User
Hi Erel,

yes, that was a type (as copy/past didn't work).

getWiFiLink does not work on a Mavic Pro, that is OK, as they use OcuSync and not Wifi.

changing your code to:

B4X:
    Dim airlink As JavaObject = aircraft
    airlink = airlink.RunMethod("getAirLink", Null)
    If airlink.IsInitialized Then
        Dim OcuSyncLink As JavaObject = airlink.RunMethod("getOcuSyncLink", Null)
        If OcuSyncLink.IsInitialized Then
            Dim cc As Object = OcuSyncLink.CreateEventFromUI("dji.common.util.CommonCallbacks$CompletionCallbackWith", "callback", Null)
            OcuSyncLink.RunMethod("getChannelNumber", Array(cc))
            Wait For (OcuSyncLink) Callback_Event (MethodName As String, Args() As Object)
            Log(MethodName)
            Dim numbers() As Object = Args(0)
            Dim a As List
            a.Initialize
            a.Add(numbers)
            For i = 0 To a.Size-1'numbers.Length - 1
                'Log(numbers(i))
                frequency = (a.Get(i))
            Next
        End If
    End If

get me the right result :)

next will be to set Cannel selection to Manual insted auf Auto and set a low 2.4xx GHz frequency

THX
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
as copy/past didn't work
Why copy / paste didn't work? Which browser are you using?

Your code looks wrong.

Start with this:
B4X:
Dim airlink As JavaObject = aircraft
   airlink = airlink.RunMethod("getAirLink", Null)
   If airlink.IsInitialized Then
       Dim OcuSyncLink As JavaObject = airlink.RunMethod("getOcuSyncLink", Null)
       If OcuSyncLink.IsInitialized Then
           Dim cc As Object = OcuSyncLink.CreateEventFromUI("dji.common.util.CommonCallbacks$CompletionCallbackWith", "callback", Null)
           OcuSyncLink.RunMethod("getChannelNumberValidRange", Array(cc))
           Wait For (OcuSyncLink) Callback_Event (MethodName As String, Args() As Object)
           Log(MethodName)
           Dim numbers() As Object = Args(0)
           For i = 0 To numbers.Length - 1
               Log(numbers(i))
           Next
       End If
   End If

Don't change anything. What is the output?
 
Upvote 0

madru

Active Member
Licensed User
Longtime User
no working copy/past is due to stucked pboard process on my MAC


B4X:
**************************** BaseApplication **************************
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
activation listener added
Registered successfully!
No connected product
Product connected
simulator: false
onFailure
Error occurred on line: 171 (Main) ----> Dim numbers() As Object = Args(0)
java.lang.ClassCastException: dji.common.error.DJIError cannot be cast to java.lang.Object[]
    at com.dedrone.test.main$ResumableSub_erel.resume(main.java:782)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:733)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:352)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:245)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
    at anywheresoftware.b4a.BA$1.run(BA.java:330)
    at android.os.Handler.handleCallback(Handler.java:761)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:156)
    at android.app.ActivityThread.main(ActivityThread.java:6523)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It means that 'getChannelNumberValidRange' has failed.

The correct code should be:
B4X:
Dim airlink As JavaObject = aircraft
   airlink = airlink.RunMethod("getAirLink", Null)
   If airlink.IsInitialized Then
       Dim OcuSyncLink As JavaObject = airlink.RunMethod("getOcuSyncLink", Null)
       If OcuSyncLink.IsInitialized Then
           Dim cc As Object = OcuSyncLink.CreateEventFromUI("dji.common.util.CommonCallbacks$CompletionCallbackWith", "callback", Null)
           OcuSyncLink.RunMethod("getChannelNumberValidRange", Array(cc))
           Wait For (OcuSyncLink) Callback_Event (MethodName As String, Args() As Object)
           If MethodName = "onSuccess" Then
            Dim numbers() As Object = Args(0)
            For i = 0 To numbers.Length - 1
                Log(numbers(i))
            Next
           Else
              Log("Error: " & Args(0))
           End If
       End If
   End If
 
Upvote 0
Top