简介
物模型通过将物理实体设备进行数字化描述,构建其数字模型。在物联网开发平台定义物模型即定义产品功能。完成功能定义后,系统将自动生成该产品的物模型。
单击已创建的产品,进入产品开发环节,产品开发第一步即定义物模型。
功能类型
产品的功能包括标准功能和自定义功能。
功能类型 | 功能描述 |
标准功能 | 该产品类别下提供的常用功能,默认已创建。分为必选属性和可选属性,必选属性不可删除,其中部分属性可编辑;可选属性则可删除、可编辑。 |
自定义功能 | 如果标准功能无法满足您的需求,您可以自定义功能。可由开发者自由删除和编辑。 注意:已发布的产品不能编辑、删除属性及事件。 |
功能类型包含三元素:属性、事件和行为。
功能元素 | 功能描述 | 功能标识符 |
属性 | 用于描述设备的实时状态,支持读取和设置,如模式、亮度、开关等。 包括以下六种基本数据类型: 布尔型:非真即假的二值型变量。例如,开关功能。 整数型:可用于线性调节的整数变量。例如,空调的温度。 字符型:以字符串形式表达的功能点,例如,灯的位置。 浮点型:精度为浮点型的功能点。例如,压力值的范围:0.0 - 24.0。 枚举型:自定义的有限集合值。例如,灯的颜色:白色、红色、黄色等。 时间型:string 类型的 UTC 时间戳(毫秒)。 | PropertiesId |
事件 | 用于描述设备运行时的事件,包括告警、信息和故障三种事件类型,事件型功能属性可以添加具体的事件参数,这些参数可以由属性中六种基本数据类型组成。可添加多个输出参数,例如环境传感器检测到空气质量很差,空调异常告警等。 | EventId |
行为 | 用于实现更复杂的业务逻辑,可添加多个调用参数和返回参数。行为的输入参数和输出参数可添加属性中六种基本数据类型,用于让设备执行某项特定的任务。例如,开锁动作需要知道是哪个用户在什么时间开锁,锁的状态如何等。 | ActionId |
功能示例
属性、事件功能在用户创建的产品已包含一定标准功能,若用户需要根据业务场景新增,也可在自定义功能栏中新增。
注意:
下文提供了部分自定义功能示例:
进入控制台目标产品物模型页,单击添加自定义功能,进入对应设置界面:
属性示例:
事件示例:
选择事件功能,EventId 为用户自定义的事件标识符。描述内容为选填,可填写对事件功能的描述,描述功能场景,在什么情况下触发事件等。
行为示例:
选择行为功能,根据用户场景设置行为信息,ActionId 为用户自定义的行为标识符。如图,设置闪烁行为功能,将行为标识符设置为 blink(ActionId),设置调用参数和返回参数,实现闪灯动作。
说明:
数据模板,它是一个 JSON 格式的文件,使用数据模板协议,用户的设备需按数据模板定义要求传输设备数据到云端,并可使用基于数据模板的诸多业务功能。
数据模板格式参考
以下为智能高级路灯的数据模板字段描述说明,包括各种数据类型和事件类型。示例代码如下:
{"version": "1.0","profile": {"ProductId": "2300UMK31M","CategoryId": "3"},"properties": [{"id": "power_switch","name": "电灯开关","desc": "控制电灯开灭","required": true,"mode": "rw","define": {"type": "bool","mapping": {"0": "关","1": "开"}}},{"id": "color","name": "颜色","desc": "灯光颜色","mode": "rw","define": {"type": "enum","mapping": {"0": "Red","1": "Green","2": "Blue"}}},{"id": "brightness","name": "亮度","desc": "灯光亮度","mode": "rw","define": {"type": "int","unit": "%","step": "1","min": "0","max": "100","start": "1"}},{"id": "name","name": "灯位置名称","desc": "灯位置名称:书房、客厅等","mode": "rw","required": false,"define": {"type": "string","min": "0","max": "64"}}],"events": [{"id": "status_report","name": "DeviceStatus","desc": "Report the device status","type": "info","required": false,"params": [{"id": "status","name": "running_state","desc": "Report current device running state","define": {"type": "bool","mapping": {"0": "normal","1": "fault"}}},{"id": "message","name": "Message","desc": "Some extra message","define": {"type": "string","min": "0","max": "64"}}]},{"id": "low_voltage","name": "LowVoltage","desc": "Alert for device voltage is low","type": "alert","required": false,"params": [{"id": "voltage","name": "Voltage","desc": "Current voltage","define": {"type": "float","unit": "V","step": "1","min": "0.0","max": "24.0","start": "1"}}]},{"id": "hardware_fault","name": "Hardware_fault","desc": "Report hardware fault","type": "fault","required": false,"params": [{"id": "name","name": "Name","desc": "Name like: memory,tf card, censors ...","define": {"type": "string","min": "0","max": "64"}},{"id": "error_code","name": "Error_Code","desc": "Error code for fault","define": {"type": "int","unit": "","step": "1","min": "0","max": "2000","start": "1"}}]}],"actions": [{"id": "unlock","name": "开灯行为检测","desc": "用于描述开灯的动作","input": [{"id": "open","name": "开关","define": {"type": "bool","mapping": {"0": "关","1": "开"}}},{"id": "user","name": "用户","define": {"type": "string","min": "0","max": "2048"}}],"output": [{"id": "user","name": "用户","define": {"type": "string","min": "0","max": "2048"}},{"id": "time","name": "开灯时间","define": {"type": "timestamp"}},{"id": "state","name": "灯的状态","define": {"type": "bool","mapping": {"0": "关","1": "开"}}}],"required": false}]}