云端将网关下所有子设备的连接配置和各子设备所属产品的物模型下发给网关。

配置下发

请求Topic:/sys/{productKey}/{deviceName}/thing/model/config/push

Alink配置推送数据格式:

{
  "id": 123,
  "version": "1.0",
  "method": "thing.model.config.push",
  "data": {
    "digest":"",
    "digestMethod":"",
    "url": ""
  }
}

参数说明如下:

参数 类型 说明
id String

消息ID号。String类型的数字,取值范围0~4294967295,且每个消息ID在当前设备中具有唯一性。

version String 协议版本号,目前协议版本号唯一取值为1.0
method String 请求方法,取值thing.model.config.push
data Object 数据。
digest String 签名,用于校验从对象存储URL中获取的数据的完整性。
digestMethod String 签名方法,默认sha256。
url String 存储子设备配置数据的对象存储URL,用于从对象存储OSS中获取子设备配置数据。

子设备配置数据格式

对象存储URL中的子设备配置数据示例:

{
  "modelList": [
    {
      "profile": {
        "productKey": "a1ZlGQv****"
      },
      "services": [
        {
          "outputData": "",
          "identifier": "AngleSelfAdaption",
          "inputData": [
            {
              "identifier": "test01",
              "index": 0
            }
          ],
          "displayName": "test01"
        }
      ],
      "properties": [
        {
          "identifier": "identifier",
          "displayName": "test02"
        },
        {
          "identifier": "identifier_01",
          "displayName": "identifier_01"
        }
      ],
      "events": [
        {
          "outputData": [
            {
              "identifier": "test01",
              "index": 0
            }
          ],
          "identifier": "event1",
          "displayName": "abc"
        }
      ]
    },
    {
      "profile": {
        "productKey": "a1ZlGQv****"
      },
      "properties": [
        {
          "originalDataType": {
            "specs": {
              "registerCount": 1,
              "reverseRegister": 0,
              "swap16": 0
            },
            "type": "bool"
          },
          "identifier": "test01",
          "registerAddress": "0x03",
          "scaling": 1,
          "operateType": "inputStatus",
          "pollingTime": 1000,
          "trigger": 1
        },
        {
          "originalDataType": {
            "specs": {
              "registerCount": 1,
              "reverseRegister": 0,
              "swap16": 0
            },
            "type": "bool"
          },
          "identifier": "test02",
          "registerAddress": "0x05",
          "scaling": 1,
          "operateType": "coilStatus",
          "pollingTime": 1000,
          "trigger": 2
        }
      ]
    },
    {
      "profile": {
        "productKey": "a1ZlGQv****"
      },
      "properties": [
        {
          "identifier": "test_02",
          "customize": {
            "test_02": 123
          }
        },
        {
          "identifier": "test_01",
          "customize": {
            "test01": 1
          }
        }
      ]
    }
  ],
  "serverList": [
    {
      "baudRate": 1200,
      "protocol": "RTU",
      "byteSize": 8,
      "stopBits": 2,
      "parity": 1,
      "name": "modbus01",
      "serialPort": "0",
      "serverId": "D73251B427****"
    },
    {
      "protocol": "TCP",
      "port": 8000,
      "ip": "192.168.0.1",
      "name": "modbus02",
      "serverId": "586CB066D****"
    },
    {
      "password": "XIJTginONohPEUAyZ****==",
      "secPolicy": "Basic128Rsa15",
      "name": "server_01",
      "secMode": "Sign",
      "userName": "123",
      "serverId": "55A9D276A7E****",
      "url": "tcp:00",
      "timeout": 10
    },
    {
      "password": "hAaX5s13gwX2JwyvUk****==",
      "name": "service_09",
      "secMode": "None",
      "userName": "1234",
      "serverId": "44895C63E3F****",
      "url": "tcp:00",
      "timeout": 10
    }
  ],
  "deviceList": [
    {
      "deviceConfig": {
        "displayNamePath": "123",
        "serverId": "44895C63E3FF4013924CEF31519A****"
      },
      "productKey": "a1ZlGQv****",
      "deviceName": "test_02"
    },
    {
      "deviceConfig": {
        "displayNamePath": "1",
        "serverId": "55A9D276A7****"
      },
      "productKey": "a1ZlGQv****",
      "deviceName": "test_03"
    },
    {
      "deviceConfig": {
        "slaveId": 1,
        "serverId": "D73251B4277****"
      },
      "productKey": "a1ZlGQv****",
      "deviceName": "test01"
    },
    {
      "deviceConfig": {
        "slaveId": 2,
        "serverId": "586CB066D6****"
      },
      "productKey": "a1ZlGQv****",
      "deviceName": "test02"
    }
  ],
  "tslList": [
    {
      "schema": "https://iotx-tsl.oss-ap-southeast-1.aliyuncs.com/schema.json",
      "profile": {
        "productKey": "a1ZlGQv****"
      },
      "services": [
        {
          "outputData": [],
          "identifier": "set",
          "inputData": [
            {
              "identifier": "test02",
              "dataType": {
                "specs": {
                  "unit": "mm",
                  "min": "0",
                  "max": "1"
                },
                "type": "int"
              },
              "name": "测试功能02"
            }
          ],
          "method": "thing.service.property.set",
          "name": "set",
          "required": true,
          "callType": "async",
          "desc": "属性设置"
        },
        {
          "outputData": [
            {
              "identifier": "test01",
              "dataType": {
                "specs": {
                  "unit": "m",
                  "min": "0",
                  "max": "1"
                },
                "type": "int"
              },
              "name": "测试功能01"
            },
            {
              "identifier": "test02",
              "dataType": {
                "specs": {
                  "unit": "mm",
                  "min": "0",
                  "max": "1"
                },
                "type": "int"
              },
              "name": "测试功能02"
            }
          ],
          "identifier": "get",
          "inputData": [
            "test01",
            "test02"
          ],
          "method": "thing.service.property.get",
          "name": "get",
          "required": true,
          "callType": "async",
          "desc": "属性获取"
        }
      ],
      "properties": [
        {
          "identifier": "test01",
          "dataType": {
            "specs": {
              "unit": "m",
              "min": "0",
              "max": "1"
            },
            "type": "int"
          },
          "name": "测试功能01",
          "accessMode": "r",
          "required": false
        },
        {
          "identifier": "test02",
          "dataType": {
            "specs": {
              "unit": "mm",
              "min": "0",
              "max": "1"
            },
            "type": "int"
          },
          "name": "测试功能02",
          "accessMode": "rw",
          "required": false
        }
      ],
      "events": [
        {
          "outputData": [
            {
              "identifier": "test01",
              "dataType": {
                "specs": {
                  "unit": "m",
                  "min": "0",
                  "max": "1"
                },
                "type": "int"
              },
              "name": "测试功能01"
            },
            {
              "identifier": "test02",
              "dataType": {
                "specs": {
                  "unit": "mm",
                  "min": "0",
                  "max": "1"
                },
                "type": "int"
              },
              "name": "测试功能02"
            }
          ],
          "identifier": "post",
          "method": "thing.event.property.post",
          "name": "post",
          "type": "info",
          "required": true,
          "desc": "属性上报"
        }
      ]
    },
    {
      "schema": "https://iotx-tsl.oss-ap-southeast-1.aliyuncs.com/schema.json",
      "profile": {
        "productKey": "a1ZlGQv****"
      },
      "services": [
        {
          "outputData": [],
          "identifier": "set",
          "inputData": [
            {
              "identifier": "identifier",
              "dataType": {
                "specs": {
                  "length": "2048"
                },
                "type": "text"
              },
              "name": "7614"
            },
            {
              "identifier": "identifier_01",
              "dataType": {
                "specs": {
                  "length": "2048"
                },
                "type": "text"
              },
              "name": "测试功能1"
            }
          ],
          "method": "thing.service.property.set",
          "name": "set",
          "required": true,
          "callType": "async",
          "desc": "属性设置"
        },
        {
          "outputData": [
            {
              "identifier": "identifier",
              "dataType": {
                "specs": {
                  "length": "2048"
                },
                "type": "text"
              },
              "name": "7614"
            },
            {
              "identifier": "identifier_01",
              "dataType": {
                "specs": {
                  "length": "2048"
                },
                "type": "text"
              },
              "name": "测试功能1"
            }
          ],
          "identifier": "get",
          "inputData": [
            "identifier",
            "identifier_01"
          ],
          "method": "thing.service.property.get",
          "name": "get",
          "required": true,
          "callType": "async",
          "desc": "属性获取"
        },
        {
          "outputData": [],
          "identifier": "AngleSelfAdaption",
          "inputData": [
            {
              "identifier": "test01",
              "dataType": {
                "specs": {
                  "min": "1",
                  "max": "10",
                  "step": "1"
                },
                "type": "int"
              },
              "name": "参数1"
            }
          ],
          "method": "thing.service.AngleSelfAdaption",
          "name": "角度自适应校准",
          "required": false,
          "callType": "async"
        }
      ],
      "properties": [
        {
          "identifier": "identifier",
          "dataType": {
            "specs": {
              "length": "2048"
            },
            "type": "text"
          },
          "name": "7614",
          "accessMode": "rw",
          "required": true
        },
        {
          "identifier": "identifier_01",
          "dataType": {
            "specs": {
              "length": "2048"
            },
            "type": "text"
          },
          "name": "测试功能1",
          "accessMode": "rw",
          "required": false
        }
      ],
      "events": [
        {
          "outputData": [
            {
              "identifier": "identifier",
              "dataType": {
                "specs": {
                  "length": "2048"
                },
                "type": "text"
              },
              "name": "7614"
            },
            {
              "identifier": "identifier_01",
              "dataType": {
                "specs": {
                  "length": "2048"
                },
                "type": "text"
              },
              "name": "测试功能1"
            }
          ],
          "identifier": "post",
          "method": "thing.event.property.post",
          "name": "post",
          "type": "info",
          "required": true,
          "desc": "属性上报"
        },
        {
          "outputData": [
            {
              "identifier": "test01",
              "dataType": {
                "specs": {
                  "min": "1",
                  "max": "20",
                  "step": "1"
                },
                "type": "int"
              },
              "name": "测试参数1"
            }
          ],
          "identifier": "event1",
          "method": "thing.event.event1.post",
          "name": "event1",
          "type": "info",
          "required": false
        }
      ]
    },
    {
      "schema": "https://iotx-tsl.oss-ap-southeast-1.aliyuncs.com/schema.json",
      "profile": {
        "productKey": "a1ZlGQv****"
      },
      "services": [
        {
          "outputData": [],
          "identifier": "set",
          "inputData": [
            {
              "identifier": "test_01",
              "dataType": {
                "specs": {
                  "min": "1",
                  "max": "100",
                  "step": "1"
                },
                "type": "int"
              },
              "name": "参数1"
            },
            {
              "identifier": "test_02",
              "dataType": {
                "specs": {
                  "min": "1",
                  "max": "100",
                  "step": "10"
                },
                "type": "double"
              },
              "name": "参数2"
            }
          ],
          "method": "thing.service.property.set",
          "name": "set",
          "required": true,
          "callType": "async",
          "desc": "属性设置"
        },
        {
          "outputData": [
            {
              "identifier": "test_01",
              "dataType": {
                "specs": {
                  "min": "1",
                  "max": "100",
                  "step": "1"
                },
                "type": "int"
              },
              "name": "参数1"
            },
            {
              "identifier": "test_02",
              "dataType": {
                "specs": {
                  "min": "1",
                  "max": "100",
                  "step": "10"
                },
                "type": "double"
              },
              "name": "参数2"
            }
          ],
          "identifier": "get",
          "inputData": [
            "test_01",
            "test_02"
          ],
          "method": "thing.service.property.get",
          "name": "get",
          "required": true,
          "callType": "async",
          "desc": "属性获取"
        }
      ],
      "properties": [
        {
          "identifier": "test_01",
          "dataType": {
            "specs": {
              "min": "1",
              "max": "100",
              "step": "1"
            },
            "type": "int"
          },
          "name": "参数1",
          "accessMode": "rw",
          "required": false
        },
        {
          "identifier": "test_02",
          "dataType": {
            "specs": {
              "min": "1",
              "max": "100",
              "step": "10"
            },
            "type": "double"
          },
          "name": "参数2",
          "accessMode": "rw",
          "required": false
        }
      ],
      "events": [
        {
          "outputData": [
            {
              "identifier": "test_01",
              "dataType": {
                "specs": {
                  "min": "1",
                  "max": "100",
                  "step": "1"
                },
                "type": "int"
              },
              "name": "参数1"
            },
            {
              "identifier": "test_02",
              "dataType": {
                "specs": {
                  "min": "1",
                  "max": "100",
                  "step": "10"
                },
                "type": "double"
              },
              "name": "参数2"
            }
          ],
          "identifier": "post",
          "method": "thing.event.property.post",
          "name": "post",
          "type": "info",
          "required": true,
          "desc": "属性上报"
        }
      ]
    }
  ]
}

参数说明如下:

参数 类型 描述
modelList Object 网关下面所有子设备的产品扩展信息。请参见modelList说明
serverList Object 网关下面所有的子设备连接通道。请参见serverList说明
deviceList Object 网关下面所有子设备的连接配置。请参见deviceList说明
tslList Object 网关下面所有子设备的TSL描述。请参见物模型格式

modelList说明

设备协议目前支持Modbus、OPC UA和自定义协议,不同协议的扩展信息不一致。

  • Modbus协议下子设备的产品扩展信息数据示例:

    {
      "profile": {
        "productKey": "a1ZlGQv****"
      },
      "properties": [
        {
          "originalDataType": {
            "specs": {
              "registerCount": 1,
              "reverseRegister": 0,
              "swap16": 0
            },
            "type": "bool"
          },
          "identifier": "test01",
          "registerAddress": "0x03",
          "scaling": 1,
          "operateType": "inputStatus",
          "pollingTime": 1000,
          "trigger": 1
        },
        {
          "originalDataType": {
            "specs": {
              "registerCount": 1,
              "reverseRegister": 0,
              "swap16": 0
            },
            "type": "bool"
          },
          "identifier": "test02",
          "registerAddress": "0x05",
          "scaling": 1,
          "operateType": "coilStatus",
          "pollingTime": 1000,
          "trigger": 2
        }
      ]
    }

    参数说明如下:

    参数 类型 说明
    identifier String 属性、事件和服务的标识符。
    operateType String 参数类型,取值可以为:
    • 线圈状态:coilStatus
    • 输入状态:inputStatus
    • 保持寄存器:holdingRegister
    • 输入寄存器:inputRegister
    registerAddress String 寄存器地址。
    originalDataType Object 数据原始类型。
    type String 数据类型。取值如下:

    int16、uint16、int32、uint32、int64、uint64、float、double、string、customized data。

    specs Object 描述信息。
    registerCount Integer 寄存器的数据个数。
    swap16 Integer 把寄存器内16位数据的前后8个bits互换。0表示false、1表示true。
    reverseRegister Integer 把原始数据32位数据的bits互换。
    • 0:不互换(false)
    • 1:互换(true)
    scaling Integer 缩放因子。
    pollingTime Integer 采集间隔。
    trigger Integer 数据的上报方式:
    • 1:按时上报
    • 2:变更上报
  • OPC UA协议下子设备的产品扩展信息数据示例:

    {
      "profile": {
        "productKey": "a1ZlGQv****"
      },
      "services": [
        {
          "outputData": "",
          "identifier": "AngleSelfAdaption",
          "inputData": [
            {
              "identifier": "test01",
              "index": 0
            }
          ],
          "displayName": "test01"
        }
      ],
      "properties": [
        {
          "identifier": "identifier",
          "displayName": "test02"
        },
        {
          "identifier": "identifier_01",
          "displayName": "identifier_01"
        }
      ],
      "events": [
        {
          "outputData": [
            {
              "identifier": "test01",
              "index": 0
            }
          ],
          "identifier": "event1",
          "displayName": "abc"
        }
      ]
    }

    参数说明如下:

    参数 类型 说明
    services Object 服务。
    properties Object 属性。
    events Object 事件。
    outputData Object 输出参数,如事件上报数据、服务调用的返回结果。
    identifier String 属性、事件或服务的标识符。
    inputData Object 输入参数,如服务的入参。
    index Integer 索引信息。
    displayName String 属性、事件或服务的名称。
  • 自定义协议下子设备的产品扩展信息数据示例:
    {
      "profile": {
        "productKey": "a1ZlGQv****"
      },
      "properties": [
        {
          "identifier": "test_02",
          "customize": {
            "test_02": 123
          }
        },
        {
          "identifier": "test_01",
          "customize": {
            "test01": 1
          }
        }
      ]
    }

    参数说明如下:

    参数 类型 说明
    productKey String 产品Key,物联网平台为产品颁发的唯一标识符。
    properties Object 属性信息集合。
    identifier String 属性标识符。
    customize Object 属性的自定义扩展信息,即定义属性时,扩展描述中填入的数据。

serverList说明

子设备连接通道的信息分为Modbus和OPC UA协议两种。

  • Modbus协议下的连接通道数据示例:

    [
      {
        "baudRate": 1200,
        "protocol": "RTU",
        "byteSize": 8,
        "stopBits": 2,
        "parity": 1,
        "name": "modbus01",
        "serialPort": "0",
        "serverId": "D73251B427****"
      },
      {
        "protocol": "TCP",
        "port": 8000,
        "ip": "192.168.0.1",
        "name": "modbus02",
        "serverId": "586CB066D****"
      }
    ]
    参数 类型 说明
    protocol String 协议类型,取值为TCP或者RTU。
    port Integer 端口号。
    ip String IP地址。
    name String 子设备通道名称。
    serverId String 子设备通道ID。
    baudRate Integer 波特率。
    byteSize Integer 字节数。
    stopBits Integer 停止位。
    parity Integer 奇偶校验位。
    • E:偶校验
    • O:奇校验
    • N:无校验
    serialPort String 串口号。
  • OPC UA协议下的连接通道数据示例:

    {
      "password": "XIJTginONohPEUAyZx****==",
      "secPolicy": "Basic128Rsa15",
      "name": "server_01",
      "secMode": "Sign",
      "userName": "123",
      "serverId": "55A9D276A7E****",
      "url": "tcp:00",
      "timeout": 10
    }

    参数说明如下:

    参数 类型 说明
    password String 密码,采用AES算法加密。具体说明见下文OPC UA的password加密方式。
    secPolicy String 加密策略,取值:None、Basic128Rsa15、Basic256。
    secMode String 加密模式,取值:None、Sign、SignAndEncrypt。
    name String 子设备通道名称。
    userName String 用户名。
    serverId String 子设备通道ID。
    url String 服务器连接地址。
    timeout Integer 超时时间。

    OPC UA的password加密方式

    加密算法采用AES算法,使用128位(16字节)分组,缺省的mode为CBC,缺省的padding为PKCS5Padding, 密钥使用设备的DeviceSecret,加密后的内容采用BASE64进行编码。

    加解密示例代码:
    说明 Java版本请采用Java 9、Java 8u161、Java 7u171、Java 6u181及以上版本。Java版本过低时运行以下示例会报错,此类报错具体解释,请参考Java Bug Database
    private static String instance = "AES/CBC/PKCS5Padding";
    
        private static String algorithm = "AES";
    
        private static String charsetName = "utf-8";
        /**
         * 加密算法
         *
         * @param data             待加密内容
         * @param deviceSecret     设备的密钥
         * @return
         */
        public static String aesEncrypt(String data, String deviceSecret) {
            try {
                Cipher cipher = Cipher.getInstance(instance);
                byte[] raw = deviceSecret.getBytes();
                SecretKeySpec key = new SecretKeySpec(raw, algorithm);
                IvParameterSpec ivParameter = new IvParameterSpec(deviceSecret.substring(0, 16).getBytes());
                cipher.init(Cipher.ENCRYPT_MODE, key, ivParameter);
                byte[] encrypted = cipher.doFinal(data.getBytes(charsetName));
    
                return new BASE64Encoder().encode(encrypted);
            } catch (Exception e) {
                e.printStackTrace();
            }
    
            return null;
        }
    
        public static String aesDecrypt(String data, String deviceSecret) {
            try {
                byte[] raw = deviceSecret.getBytes(charsetName);
                byte[] encrypted1 = new BASE64Decoder().decodeBuffer(data);
                SecretKeySpec key = new SecretKeySpec(raw, algorithm);
                Cipher cipher = Cipher.getInstance(instance);
                IvParameterSpec ivParameter = new IvParameterSpec(deviceSecret.substring(0, 16).getBytes());
                cipher.init(Cipher.DECRYPT_MODE, key, ivParameter);
                byte[] originalBytes = cipher.doFinal(encrypted1);
                String originalString = new String(originalBytes, charsetName);
                return originalString;
            } catch (Exception ex) {
                ex.printStackTrace();
            }
    
            return null;
        }
    
        public static void main(String[] args) throws Exception {
            String text = "test123";
            String secret = "testTNmjyWHQzniA8wEkTNmjyWH****";
            String data = null;
            data = aesEncrypt(text, secret);
            System.out.println(data);
            System.out.println(aesDecrypt(data, secret));
        }

deviceList说明

  • Modbus协议下子设备的连接配置数据示例:

    {
      "deviceConfig": {
        "slaveId": 1,
        "serverId": "D73251B42777****"
      },
      "productKey": "a1ZlGQv****",
      "deviceName": "test01"
    }

    参数说明如下:

    参数 类型 取值
    deviceConfig Object 设备连接配置信息。
    slaveId Integer 从站ID。
    serverId String 子设备通道ID。
    productKey String 子设备的产品Key。
    deviceName String 子设备名称。
  • OPC UA协议

    {
      "deviceConfig": {
        "displayNamePath": "123",
        "serverId": "44895C63E3FF4013924CEF31519A****"
      },
      "productKey": "a1ZlGQv****",
      "deviceName": "test_02"
    }

    参数说明如下:

    参数 类型 说明
    deviceConfig Object 设备连接配置信息。
    productKey String 子设备的产品Key。
    deviceName String 子设备名称。
    displayNamePath String 自定义的展示名称。
    serverId String 子设备通道ID。