全部产品
云市场

远程配置

更新时间:2019-02-21 20:14:59

使用该功能前,需在云端开启产品的远程配置功能。远程配置可以用于更新设备的配置信息,包括设备的系统参数、网络参数或者本地策略等等。

说明 远程配置相关接口参见 设备 IDeviceCOTA

主动获取配置

  1. RequestModel<Map> requestModel = new RequestModel<Map>();
  2. requestModel.id = "123";
  3. requestModel.method = "thing.config.get";
  4. requestModel.version = "1.0";
  5. Map<String, String> paramsMap = new HashMap<String, String>();
  6. paramsMap.put("configScope", "product");
  7. paramsMap.put("getType", "file");
  8. requestModel.params = paramsMap;
  9. LinkKit.getInstance().getDeviceCOTA().COTAGet(requestModel, new IConnectSendListener() {
  10. @Override
  11. public void onResponse(ARequest aRequest, AResponse aResponse) {
  12. ALog.d(TAG, "onResponse() called with: aRequest = [" + aRequest + "], aResponse = [" + (aResponse == null ? null : aResponse.data) + "]");
  13. }
  14. @Override
  15. public void onFailure(ARequest aRequest, AError aError) {
  16. ALog.d(TAG, "onFailure() called with: aRequest = [" + aRequest + "], aError = [" + getError(aError) + "]");
  17. }
  18. });

订阅获取

设备端可以通过订阅获取远程配置信息

  1. LinkKit.getInstance().getDeviceCOTA().setCOTAChangeListener(new IConnectRrpcListener() {
  2. @Override
  3. public void onSubscribeSuccess(ARequest aRequest) {
  4. ALog.d(TAG, "onSubscribeSuccess() called with: aRequest = [" + aRequest + "]");
  5. }
  6. @Override
  7. public void onSubscribeFailed(ARequest aRequest, AError aError) {
  8. ALog.d(TAG, "onSubscribeFailed() called with: aRequest = [" + aRequest + "], aError = [" + getError(aError) + "]");
  9. }
  10. @Override
  11. public void onReceived(ARequest aRequest, IConnectRrpcHandle iConnectRrpcHandle) {
  12. ALog.d(TAG, "onReceived() called with: aRequest = [" + aRequest + "], iConnectRrpcHandle = [" + iConnectRrpcHandle + "]");
  13. if (aRequest instanceof MqttRrpcRequest) {
  14. // 云端下行数据 拿到
  15. String cotaData = new String((byte[]) ((MqttRrpcRequest) aRequest).payloadObj);
  16. ALog.d(TAG, "received data=" + cotaData);
  17. // ((MqttRrpcRequest) aRequest).payloadObj;
  18. // ResponseModel<Map<String, String>> responseModel = JSONObject.parseObject(((MqttRrpcRequest) aRequest).payloadObj, new TypeReference<ResponseModel<Map<String, String>>>(){}.getType());
  19. }
  20. // 返回数据示例
  21. /*{
  22. "id": "123",
  23. "version": "1.0",
  24. "code": 200,
  25. "data": {
  26. "configId": "123dagdah",
  27. "configSize": 1234565,
  28. "sign": "123214adfadgadg",
  29. "signMethod": "Sha256",
  30. "url": "https://iotx-config.oss-cn-shanghai.aliyuncs.com/nopoll_0.4.4.tar.gz?Expires=1502955804&OSSAccessKeyId=XXXXXXXXXXXXXXXXXXXX&Signature=XfgJu7P6DWWejstKJgXJEH0qAKU%3D&security-token=CAISuQJ1q6Ft5B2yfSjIpK6MGsyN1Jx5jo6mVnfBglIPTvlvt5D50Tz2IHtIf3NpAusdsv03nWxT7v4flqFyTINVAEvYZJOPKGrGR0DzDbDasumZsJbo4f%2FMQBqEaXPS2MvVfJ%2BzLrf0ceusbFbpjzJ6xaCAGxypQ12iN%2B%2Fr6%2F5gdc9FcQSkL0B8ZrFsKxBltdUROFbIKP%2BpKWSKuGfLC1dysQcO1wEP4K%2BkkMqH8Uic3h%2Boy%2BgJt8H2PpHhd9NhXuV2WMzn2%2FdtJOiTknxR7ARasaBqhelc4zqA%2FPPlWgAKvkXba7aIoo01fV4jN5JXQfAU8KLO8tRjofHWmojNzBJAAPpYSSy3Rvr7m5efQrrybY1lLO6iZy%2BVio2VSZDxshI5Z3McKARWct06MWV9ABA2TTXXOi40BOxuq%2B3JGoABXC54TOlo7%2F1wTLTsCUqzzeIiXVOK8CfNOkfTucMGHkeYeCdFkm%2FkADhXAnrnGf5a4FbmKMQph2cKsr8y8UfWLC6IzvJsClXTnbJBMeuWIqo5zIynS1pm7gf%2F9N3hVc6%2BEeIk0xfl2tycsUpbL2FoaGk6BAF8hWSWYUXsv59d5Uk%3D",
  31. "getType": "file"
  32. }
  33. }*/
  34. }
  35. @Override
  36. public void onResponseSuccess(ARequest aRequest) {
  37. ALog.d(TAG, "onResponseSuccess() called with: aRequest = [" + aRequest + "]");
  38. }
  39. @Override
  40. public void onResponseFailed(ARequest aRequest, AError aError) {
  41. ALog.d(TAG, "onResponseFailed() called with: aRequest = [" + aRequest + "], aError = [" + getError(aError) + "]");
  42. }
  43. });