IPC Control (Android)

Last Updated on : 2024-06-17 08:45:23download

Data points (DPs) are configured to implement smart device control between the app and cloud. Standard DPs apply to interactions between devices and the app.

The APP SDK is uniquely identified by the DP Code (the device is uniquely identified by the DP ID), so when creating a custom DP on the Developer Platform, please ensure the uniqueness of the DP Code (DP ID).

Get an object

IThingIPCDpHelper provides the capabilities to transmit device information. For example, send control commands and query DP data of the current device.

API description

Initializes the device control class by device ID.

IThingIPCDpHelper createIPCDpHelper(@NonNull String devId)

Example

IThingIPCDpHelper ipcDpHelper = ThingIPCSdk.createIPCDpHelper(devId);

Query DP Code based on DP ID

API description

This method can query the DP Code corresponding to the DP ID

String getDPCodeById(String dpId);

Example

String dpCode = dpHelper.getDPCodeById(dpId);

Query DP ID according to DP Code

API description

This method can query the DP ID corresponding to the DP Code

String getDPIdByCode(String dpCode);

Example

String dpId = dpHelper.getDPCodeById(dpCode);

Query supported features

API description

Checks whether a specific DP is supported by a device. If the DP is not supported, the API requests to send and query DP data will fail. The request parameter is the DP Code of the device.

boolean querySupportByDPCode(String dpCode);

Example

boolean support = dpHelper.querySupportByDPCode(WAKEUP_CODE);

Get DP

API description

The data corresponding to the device function is obtained through the cache, and the DP Code and the specified DP data type are passed in to return the query result.

<T> T getCurrentValue(String dpCode, @NonNull Class<T> tClass);

Example

 String currentValue = ipcDpHelper.getCurrentValue(dpCode, String.class);

Query DP

API description

By sending instructions to the device to query the data of the corresponding function, pass in the DP Code, the specified DP data type and the returned IQueryDpsCallback.

<T> void queryDpValueFromRemote(String dpCode, IQueryDpsCallback<T> callback, Class<T> tClass);

Example

 ipcDpHelper.queryValueByDPCodeRemote(dpCode, new IQueryDpsCallback<Object>() {
                @Override
                public void onQueryDpsSuccess(String dpCode, Object value) {
                    // return device value
                }

                @Override
                public void onQueryDpsFail(String dpCode, String errorCode, String errorMsg) {
                    L.i(TAG, "onQueryDpsFail ");
                }
            }, Object.class);

Send DPs

API description

Sends DPs over a local area network (LAN) or from the cloud.

void publishDps(String dpCode, Object value, IResultCallback callback);

Example

IResultCallback iResultCallback = new IResultCallback() {
            @Override
            public void onError(String code, String error) {
                
            }

            @Override
            public void onSuccess() {
                
            }
        };
dpHelper.publishDps(dpCode, true, iResultCallback);

Register data listener

API description

You can use this interface to register to monitor the reporting information of the device status, Send DPs or Get/Query DP If you do not set a callback, you can use this monitoring to obtain the reported information of the device.

void addDevListener(OnDeviceChangedListener listener);

Example


OnDeviceChangedListener onDeviceChangedListener = new OnDeviceChangedListener() {
            @Override
            public void onDeviceDpUpdate(String dpCode) {
                // dp update
            }

            @Override
            public void onDeviceRemoved() {
            }

            @Override
            public void onDeviceStatusChanged(boolean online) {
            }

            @Override
            public void onDeviceNetworkStatusChanged(boolean status) {
            }

            @Override
            public void onDeviceInfoUpdate() {
            }
        };
mDPHelper.addDevListener(onDeviceChangedListener);

UnRegister data listener

API description

If you have registered the above listener, please unregister when you exit, otherwise there is a risk of memory leaks.

void removeDevListener(OnDeviceChangedListener listener);

Example

mDPHelper.removeDevListener(onDeviceChangedListener);

Destroy

API description

You need to destroy the resource when the object is used, usually when exiting, otherwise there is a risk of memory leaks.

void onDestroy();

Standard DP features

You can view the functional definitions of standard DPs for camera products on the Tuya Developer Platform.