Remote Configuration

Updated at:

Before you can use this feature, enable Remote Configuration for the product in the cloud. You can use Remote Configuration to update device configuration information, such as system parameters, network parameters, or local policies.

Note For more information about the interfaces for Remote Configuration, see the IDeviceCOTA class.

Retrieve configurations on demand

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) {
        // Successfully retrieved the remote configuration.
    }

    @Override
    public void onFailure(ARequest aRequest, AError aError) {
        // Failed to retrieve the remote configuration.
    }
});
            

Retrieve configurations by subscription

Devices can retrieve remote configuration information using subscriptions.

// Note: The cloud limits COTA updates for all product categories to once 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) {
        // Received downstream data for the remote configuration.    
        if (aRequest instanceof MqttRrpcRequest){
            // Downstream data from the cloud. For a sample of the returned data, see the demo.
            // ((MqttRrpcRequest) aRequest).payloadObj;
        }
    }

    @Override
    public void onResponseSuccess(ARequest aRequest) {
        // Successfully responded to the remote configuration.
    }

    @Override
    public void onResponseFailed(ARequest aRequest, AError aError) {
        // Failed to respond to the remote configuration.
    }
});