功能定義完成后,平臺根據“標準功能” 和“自定義功能”,自動生成JSON格式的物模型。

前提條件

已完成標準功能和自定義功能的配置。

背景信息

物模型是對設備是什么,能做什么的描述,包括設備的屬性(properties)、服務(services)、事件(events)等。阿里IoT通過定義一種物的描述語言來描述物模型,稱之為 TSL(即 Thing Specification Language)。更多物模型介紹

操作步驟

  1. 進入產品-功能定義頁面。
  2. 在產品功能定義中,單擊查看物模型
    查看物模型物模型詳情
  3. 單擊導出模型文件,可以將JSON文件保存到本地。

操作樣例

TSL字段描述說明
{
    "schema": "物的TSL描述schema",
    "link": "云端系統級uri,用來調用服務/訂閱事件",
    "profile": {
        "productKey": "產品key",
        "deviceName": "設備名稱"
    },
    "properties": [
        {
            "identifier": "屬性唯一標識符(產品下唯一)",
            "name": "屬性名稱",
            "accessMode": "屬性讀寫類型,只讀(r),只寫(w),讀寫(rw)",
            "required": "是否是必選屬性",
            "dataType": {
                "type": "屬性類型: int(原生),float(原生),double(原生), text(原生),date(String類型UTC毫秒),bool(0或1的int類型),enum(int類型), struct(結構體類型,可包含前面6種類型)",
                "specs": {
                    "min": "屬性最小值(int,float,double類型特有)",
                    "max": "屬性最大值(int,float,double類型特有)",
                    "unit": "屬性單位",
                    "unitName": "單位的名稱"
                }
            }
        }
    ],
    "events": [
        {
            "name": "事件名稱",
            "identifier": "事件唯一標識符",
            "desc": "事件描述",
            "type": "事件類型(info,alert,error)",
            "required": "是否是必選事件",
            "outputData": [
                {
                    "identifier": "參數唯一標識符",
                    "name": "參數名稱",
                    "dataType": {
                        "type": "參數類型: int(原生),float(原生),double(原生), text(原生),date(String類型UTC毫秒),bool(0或1的int類型),enum(int類型), struct(結構體類型,可包含前面6種類型)",
                        "specs": {
                            "min": "參數最小值(int,float,double類型特有)",
                            "max": "參數最大值(int,float,double類型特有)",
                            "unit": "參數單位",
                            "unitName": "單位的名稱"
                        }
                    }
                }
            ],
            "method": "事件對應的方法名稱(根據identifier生成)"
        }
    ],
    "services": [
        {
            "name": "服務名稱",
            "identifier": "服務唯一標識符",
            "desc": "服務描述",
            "required": "是否是必選服務",
            "inputData": [
                {
                    "identifier": "入參唯一標識符",
                    "name": "入參名稱",
                    "dataType": {
                        "type": "入參類型: int(原生),float(原生),double(原生), text(原生),date(String類型UTC毫秒),bool(0或1的int類型),enum(int類型), struct(結構體類型,可包含前面6種類型)",
                        "specs": {
                            "min": "入參最小值(int,float,double類型特有)",
                            "max": "入參最大值(int,float,double類型特有)",
                            "unit": "入參單位",
                            "unitName": "單位的名稱"
                        }
                    }
                }
            ],
            "outputData": [
                {
                    "identifier": "出參唯一標識符",
                    "name": "出參名稱",
                    "dataType": {
                        "type": "出參類型: int(原生),float(原生),double(原生), text(原生),date(String類型UTC毫秒),bool(0或1的int類型),enum(int類型), struct(結構體類型,可包含前面6種類型)",
                        "specs": {
                            "min": "出參最小值(int,float,double類型特有)",
                            "max": "出參最大值(int,float,double類型特有)",
                            "unit": "出參單位",
                            "unitName": "單位的名稱"
                        }
                    }
                }
            ],
            "method": "服務對應的方法名稱(根據identifier生成)"
        }
    ]
}
TSL樣例
{
    "schema": "http://aliyun/iot/thing/desc/schema",
    "link": "/sys/q408EXte2fy/airCondition/thing/",
    "profile": {
        "productKey": "q408EXte2fy",
        "deviceName": "airCondition"
    },
    "properties": [
        {
            "identifier": "fan_doule_property",
            "name": "風扇雙精度型屬性",
            "accessMode": "r",
            "required": true,
            "dataType": {
                "type": "double",
                "specs": {
                    "min": "0.0",
                    "max": "100.0",
                    "unit": "g/ml",
                    "unitName": "毫升"
                }
            }
        },
        {
            "identifier": "fan_int_property",
            "name": "風扇整數型屬性",
            "accessMode": "rw",
            "required": true,
            "dataType": {
                "type": "int",
                "specs": {
                    "min": "0",
                    "max": "100",
                    "unit": "g/ml",
                    "unitName": "毫升"
                }
            }
        },
        {
            "identifier": "batch_enum_attr_id",
            "name": "風扇枚舉型屬性",
            "accessMode": "r",
            "required": true,
            "dataType": {
                "type": "enum",
                "specs": {
                    "0": "one",
                    "1": "two",
                    "2": "three"
                }
            }
        },
        {
            "identifier": "fan_float_property",
            "name": "風扇浮點型測試",
            "accessMode": "r",
            "required": true,
            "dataType": {
                "type": "float",
                "specs": {
                    "min": "0.0",
                    "max": "100.0",
                    "unit": "g/ml",
                    "unitName": "毫升"
                }
            }
        },
        {
            "identifier": "fan_text_property",
            "name": "風扇字符型屬性",
            "accessMode": "r",
            "required": true,
            "dataType": {
                "type": "text",
                "specs": {
                    "length": "64",
                    "unit": "g/ml",
                    "unitName": "毫升"
                }
            }
        },
        {
            "identifier": "fan_date_property",
            "name": "風扇時間型屬性",
            "accessMode": "r",
            "required": true,
            "dataType": {
                "type": "date",
                "specs": {}
            }
        },
        {
            "identifier": "batch_boolean_attr_id",
            "name": "風扇布爾型屬性",
            "accessMode": "r",
            "required": true,
            "dataType": {
                "type": "bool",
                "specs": {
                    "0": "close",
                    "1": "open"
                }
            }
        },
        {
            "identifier": "fan_struct_property",
            "name": "風扇結構型屬性",
            "accessMode": "r",
            "required": true,
            "dataType": {
                "type": "struct",
                "specs": [
                    {
                        "identifier": "fan_struct_property_float_child",
                        "name": "風扇雙精度型屬性",
                        "dataType": {
                            "type": "double",
                            "specs": {
                                "min": "0.0",
                                "max": "100.0",
                                "unit": "g/ml",
                                "unitName": "毫升"
                            }
                        }
                    },
                    {
                        "identifier": "fan_struct_property_float_child",
                        "name": "風扇結構型屬性浮點子屬性",
                        "dataType": {
                            "type": "float",
                            "specs": {
                                "min": "0.0",
                                "max": "255.0",
                                "unit": "°",
                                "unitName": "度"
                            }
                        }
                    },
                    {
                        "identifier": "fan_struct_property_int_child",
                        "name": "風扇結構型屬性整數子屬性",
                        "dataType": {
                            "type": "int",
                            "specs": {
                                "min": "0",
                                "max": "255",
                                "unit": "°",
                                "unitName": "度"
                            }
                        }
                    },
                    {
                        "identifier": "fan_struct_property_text_child",
                        "name": "風扇結構型屬性字符子屬性",
                        "dataType": {
                            "type": "text",
                            "specs": {
                                "length": "200",
                                "unit": "unit",
                                "unitName": "單位"
                            }
                        }
                    },
                    {
                        "identifier": "fan_struct_property_date_child",
                        "name": "風扇結構型屬性時間子屬性",
                        "dataType": {
                            "type": "date",
                            "specs": {}
                        }
                    },
                    {
                        "identifier": "fan_struct_property_enum_child",
                        "name": "風扇結構型屬性枚舉子屬性",
                        "dataType": {
                            "type": "enum",
                            "specs": {
                                "0": "one",
                                "1": "two",
                                "2": "three"
                            }
                        }
                    },
                    {
                        "identifier": "fan_struct_property_boolean_child",
                        "name": "風扇結構型屬性布爾子屬性",
                        "dataType": {
                            "type": "bool",
                            "specs": {
                                "0": "close",
                                "1": "open"
                            }
                        }
                    }
                ]
            }
        }
    ],
    "events": [
        {
            "name": "alarm",
            "identifier": "alarm",
            "desc": "警報",
            "type": "info",
            "required": true,
            "outputData": [
                {
                    "identifier": "errorCode",
                    "name": "錯誤碼",
                    "dataType": {
                        "type": "text",
                        "specs": {
                            "length": "255",
                            "unit": ""
                        }
                    }
                }
            ],
            "method": "thing.event.alarm.post"
        },
        {
            "identifier": "post",
            "name": "post",
            "type": "info",
            "required": true,
            "desc": "屬性上報",
            "method": "thing.event.property.post",
            "outputData": [
                {
                    "identifier": "fan_doule_property",
                    "name": "風扇雙精度型屬性",
                    "dataType": {
                        "type": "double",
                        "specs": {
                            "min": "0.0",
                            "max": "100.0",
                            "unit": "g/ml",
                            "unitName": "毫升"
                        }
                    }
                },
                {
                    "identifier": "fan_int_property",
                    "name": "風扇整數型屬性",
                    "dataType": {
                        "type": "int",
                        "specs": {
                            "min": "0",
                            "max": "100",
                            "unit": "g/ml",
                            "unitName": "毫升"
                        }
                    }
                },
                {
                    "identifier": "batch_enum_attr_id",
                    "name": "風扇枚舉型屬性",
                    "dataType": {
                        "type": "enum",
                        "specs": {
                            "0": "one",
                            "1": "two",
                            "2": "three"
                        }
                    }
                },
                {
                    "identifier": "fan_float_property",
                    "name": "風扇浮點型測試",
                    "dataType": {
                        "type": "float",
                        "specs": {
                            "min": "0.0",
                            "max": "100.0",
                            "unit": "g/ml",
                            "unitName": "毫升"
                        }
                    }
                },
                {
                    "identifier": "fan_text_property",
                    "name": "風扇字符型屬性",
                    "dataType": {
                        "type": "text",
                        "specs": {
                            "length": "64",
                            "unit": "g/ml",
                            "unitName": "毫升"
                        }
                    }
                },
                {
                    "identifier": "fan_date_property",
                    "name": "風扇時間型屬性",
                    "dataType": {
                        "type": "date",
                        "specs": {}
                    }
                },
                {
                    "identifier": "batch_boolean_attr_id",
                    "name": "風扇布爾型屬性",
                    "dataType": {
                        "type": "bool",
                        "specs": {
                            "0": "close",
                            "1": "open"
                        }
                    }
                },
                {
                    "identifier": "fan_struct_property",
                    "name": "風扇結構型屬性",
                    "dataType": {
                        "type": "struct",
                        "specs": [
                            {
                                "identifier": "fan_struct_property_double_child",
                                "name": "風扇雙精度型屬性",
                                "dataType": {
                                    "type": "double",
                                    "specs": {
                                        "min": "0.0",
                                        "max": "100.0",
                                        "unit": "g/ml",
                                        "unitName": "毫升"
                                    }
                                }
                            },
                            {
                                "identifier": "fan_struct_property_float_child",
                                "name": "風扇結構型屬性浮點子屬性",
                                "dataType": {
                                    "type": "float",
                                    "specs": {
                                        "min": "0.0",
                                        "max": "255.0",
                                        "unit": "°",
                                        "unitName": "度"
                                    }
                                }
                            },
                            {
                                "identifier": "fan_struct_property_int_child",
                                "name": "風扇結構型屬性整數子屬性",
                                "dataType": {
                                    "type": "int",
                                    "specs": {
                                        "min": "0",
                                        "max": "255",
                                        "unit": "°",
                                        "unitName": "度"
                                    }
                                }
                            },
                            {
                                "identifier": "fan_struct_property_text_child",
                                "name": "風扇結構型屬性字符子屬性",
                                "dataType": {
                                    "type": "text",
                                    "specs": {
                                        "length": "200",
                                        "unit": "unit",
                                        "unitName": "單位"
                                    }
                                }
                            },
                            {
                                "identifier": "fan_struct_property_date_child",
                                "name": "風扇結構型屬性時間子屬性",
                                "dataType": {
                                    "type": "date",
                                    "specs": {}
                                }
                            },
                            {
                                "identifier": "fan_struct_property_enum_child",
                                "name": "風扇結構型屬性枚舉子屬性",
                                "dataType": {
                                    "type": "enum",
                                    "specs": {
                                        "0": "one",
                                        "1": "two",
                                        "2": "three"
                                    }
                                }
                            },
                            {
                                "identifier": "fan_struct_property_boolean_child",
                                "name": "風扇結構型屬性布爾子屬性",
                                "dataType": {
                                    "type": "bool",
                                    "specs": {
                                        "0": "0",
                                        "1": "1"
                                    }
                                }
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "services": [
        {
            "name": "upgrade",
            "identifier": "upgrade",
            "desc": "升級服務",
            "inputData": [
                {
                    "identifier": "model",
                    "name": "模型",
                    "dataType": {
                        "type": "int",
                        "specs": {
                            "min": "1",
                            "max": "100",
                            "unit": "cm"
                        }
                    }
                },
                {
                    "identifier": "mac",
                    "name": "mac號",
                    "dataType": {
                        "type": "text",
                        "specs": {
                            "length": "255"
                        }
                    }
                }
            ],
            "outputData": [
                {
                    "identifier": "firmVersion",
                    "name": "固件版本號",
                    "dataType": {
                        "type": "int",
                        "specs": {
                            "min": "1",
                            "max": "100",
                            "unit": ""
                        }
                    }
                }
            ],
            "method": "thing.service.upgrade"
        },
        {
            "identifier": "set",
            "name": "set",
            "required": true,
            "desc": "屬性設置",
            "method": "thing.service.property.set",
            "inputData": [
                {
                    "identifier": "fan_int_property",
                    "name": "風扇整數型屬性",
                    "accessMode": "rw",
                    "required": true,
                    "dataType": {
                        "type": "int",
                        "specs": {
                            "min": "0",
                            "max": "100",
                            "unit": "g/ml",
                            "unitName": "毫升"
                        }
                    }
                }
            ],
            "outputData": []
        },
        {
            "identifier": "get",
            "name": "get",
            "required": true,
            "desc": "屬性獲取",
            "method": "thing.service.property.get",
            "inputData": [
                "fan_doule_property",
                "fan_int_property",
                "batch_enum_attr_id",
                "fan_float_property",
                "fan_text_property",
                "fan_date_property",
                "batch_boolean_attr_id",
                "fan_struct_property"
            ],
            "outputData": [
                {
                    "identifier": "fan_doule_property",
                    "name": "風扇雙精度型屬性",
                    "dataType": {
                        "type": "double",
                        "specs": {
                            "min": "0.0",
                            "max": "100.0",
                            "unit": "g/ml",
                            "unitName": "毫升"
                        }
                    }
                },
                {
                    "identifier": "fan_int_property",
                    "name": "風扇整數型屬性",
                    "dataType": {
                        "type": "int",
                        "specs": {
                            "min": "0",
                            "max": "100",
                            "unit": "g/ml",
                            "unitName": "毫升"
                        }
                    }
                },
                {
                    "identifier": "batch_enum_attr_id",
                    "name": "風扇枚舉型屬性",
                    "dataType": {
                        "type": "enum",
                        "specs": {
                            "0": "one",
                            "1": "two",
                            "2": "three"
                        }
                    }
                },
                {
                    "identifier": "fan_float_property",
                    "name": "風扇浮點型測試",
                    "dataType": {
                        "type": "float",
                        "specs": {
                            "min": "0.0",
                            "max": "100.0",
                            "unit": "g/ml",
                            "unitName": "毫升"
                        }
                    }
                },
                {
                    "identifier": "fan_text_property",
                    "name": "風扇字符型屬性",
                    "dataType": {
                        "type": "text",
                        "specs": {
                            "length": "64",
                            "unit": "g/ml",
                            "unitName": "毫升"
                        }
                    }
                },
                {
                    "identifier": "fan_date_property",
                    "name": "風扇時間型屬性",
                    "dataType": {
                        "type": "date",
                        "specs": {}
                    }
                },
                {
                    "identifier": "batch_boolean_attr_id",
                    "name": "風扇布爾型屬性",
                    "dataType": {
                        "type": "bool",
                        "specs": {
                            "0": "close",
                            "1": "open"
                        }
                    }
                },
                {
                    "identifier": "fan_struct_property",
                    "name": "風扇結構型屬性",
                    "dataType": {
                        "type": "struct",
                        "specs": [
                            {
                                "identifier": "fan_struct_property_double_child",
                                "name": "風扇雙精度型屬性",
                                "dataType": {
                                    "type": "double",
                                    "specs": {
                                        "min": "0.0",
                                        "max": "100.0",
                                        "unit": "g/ml",
                                        "unitName": "毫升"
                                    }
                                }
                            },
                            {
                                "identifier": "fan_struct_property_float_child",
                                "name": "風扇結構型屬性浮點子屬性",
                                "dataType": {
                                    "type": "float",
                                    "specs": {
                                        "min": "0.0",
                                        "max": "255.0",
                                        "unit": "°",
                                        "unitName": "度"
                                    }
                                }
                            },
                            {
                                "identifier": "fan_struct_property_int_child",
                                "name": "風扇結構型屬性整數子屬性",
                                "dataType": {
                                    "type": "int",
                                    "specs": {
                                        "min": "0",
                                        "max": "255",
                                        "unit": "°",
                                        "unitName": "度"
                                    }
                                }
                            },
                            {
                                "identifier": "fan_struct_property_text_child",
                                "name": "風扇結構型屬性字符子屬性",
                                "dataType": {
                                    "type": "text",
                                    "specs": {
                                        "length": "200",
                                        "unit": "unit",
                                        "unitName": "單位"
                                    }
                                }
                            },
                            {
                                "identifier": "fan_struct_property_date_child",
                                "name": "風扇結構型屬性時間子屬性",
                                "dataType": {
                                    "type": "date",
                                    "specs": {}
                                }
                            },
                            {
                                "identifier": "fan_struct_property_enum_child",
                                "name": "風扇結構型屬性枚舉子屬性",
                                "dataType": {
                                    "type": "enum",
                                    "specs": {
                                        "0": "one",
                                        "1": "two",
                                        "2": "three"
                                    }
                                }
                            },
                            {
                                "identifier": "fan_struct_property_boolean_child",
                                "name": "風扇結構型屬性布爾子屬性",
                                "dataType": {
                                    "type": "bool",
                                    "specs": {
                                        "0": "close",
                                        "1": "open"
                                    }
                                }
                            }
                        ]
                    }
                }
            ]
        }
    ]
}