To use this feature, you must enable remote configuration in the IoT Platform console. You can use this feature to update device configurations, such as system parameters, network parameters, and local policies of devices.

Automatically obtain configurations

String COTA_get = "{" + "  \"id\": 123," + "  \"version\": \"1.0\"," +
        "  \"params\": {" + "\"configScope\": \"product\"," + "\"getType\": \"file\"" +
        "  }," + "  \"method\": \"thing.config.get\"" + "}";

RequestModel<Map> requestModel = JSONObject.parseObject(COTA_get, new TypeReference<RequestModel<Map>>() {
    }.getType());
LinkKit.getInstance().getDeviceCOTA().COTAGet(requestModel, new IConnectSendListener() {
    @Override
    public void onResponse(ARequest aRequest, AResponse aResponse) {
        // The remote configuration information is obtained.
    }

    @Override
    public void onFailure(ARequest aRequest, AError aError) {
        // The remote configuration information failed to be obtained.
    }
});
            

Obtain remote configurations by subscription

A device can subscribe to remote configurations and obtain them.

// Note: IoT Platform requires that only one Config Over The Air (COTA) update be issued for all devices of a product per hour.
LinkKit.getInstance().getDeviceCOTA().setCOTAChangeListener(new IConnectRrpcListener() {
    @Override
    public void onSubscribeSuccess(ARequest aRequest) {
        // The subscription is successful.
    }

    @Override
    public void onSubscribeFailed(ARequest aRequest, AError aError) {
        // The subscription failed.
    }

    @Override
    public void onReceived(ARequest aRequest, IConnectRrpcHandle iConnectRrpcHandle) {
        // Remote configuration data is received from IoT Platform.    
        if (aRequest instanceof MqttRrpcRequest){
            // Downstream data from IoT Platform. For more information about the sample response, see the demo.
            // ((MqttRrpcRequest) aRequest).payloadObj;
        }
    }

    @Override
    public void onResponseSuccess(ARequest aRequest) {
        // The remote configuration information is returned.
    }

    @Override
    public void onResponseFailed(ARequest aRequest, AError aError) {
        // The remote configuration information failed to be returned.
    }
});