更新时间:2024-03-13 GMT+08:00
分享

修改规则

功能介绍

应用服务器可调用此接口修改物联网平台中指定规则的配置。

调用方法

请参见如何调用API

URI

PUT /v5/iot/{project_id}/rules/{rule_id}

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

参数说明:项目ID。获取方法请参见 获取项目ID

rule_id

String

参数说明:规则ID,用于唯一标识一条规则,在创建规则时由物联网平台分配获得。 取值范围:长度不超过32,只允许字母、数字的组合。

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

参数说明:用户Token。通过调用IAM服务 获取IAM用户Token接口获取,接口返回的响应消息头中“X-Subject-Token”就是需要获取的用户Token。简要的获取方法样例请参见 Token认证

Instance-Id

String

参数说明:实例ID。物理多租下各实例的唯一标识,建议携带该参数,在使用专业版时必须携带该参数。您可以在IoTDA管理控制台界面,选择左侧导航栏“总览”页签查看当前实例的ID,具体获取方式请参考查看实例详情

表3 请求Body参数

参数

是否必选

参数类型

描述

name

String

参数说明:规则名称。

最小长度:1

最大长度:128

description

String

参数说明:规则的描述信息。

最大长度:256

condition_group

ConditionGroup object

参数说明:规则的条件组,包含简单规则和复杂规则集合。

actions

Array of RuleAction objects

参数说明:规则的动作列表,单个规则最多支持设置10个动作。

rule_type

String

参数说明:规则的类型。 取值范围

  • DEVICE_LINKAGE:云端联动规则。

  • DEVICE_SIDE:端侧规则。

status

String

参数说明:规则的状态,默认值:active。 取值范围

  • active:激活。

  • inactive:未激活。

app_id

String

参数说明:资源空间ID。此参数为非必选参数,存在多资源空间的用户需要使用该接口时,建议携带该参数指定创建的规则归属到哪个资源空间下,否则创建的规则将会归属到默认资源空间下。 取值范围:长度不超过36,只允许字母、数字、下划线(_)、连接符(-)的组合。

device_side

DeviceSide object

参数说明:端侧执行下发设备信息,当规则类型为DEVICE_SIDE时,该参数必填。

表4 ConditionGroup

参数

是否必选

参数类型

描述

conditions

Array of RuleCondition objects

参数说明:规则的条件列表,单个规则最多支持设置10个条件。

logic

String

参数说明:规则条件列表中多个条件之间的逻辑关系,默认值:and。 取值范围

  • and:逻辑且。

  • or:逻辑或。

time_range

TimeRange object

参数说明:规则条件触发的有效时间段。

表5 RuleCondition

参数

是否必选

参数类型

描述

type

String

参数说明:规则条件的类型。 取值范围

  • DEVICE_DATA:设备属性数据类型条件。

  • SIMPLE_TIMER:简单定时类型条件。

  • DAILY_TIMER:每日定时类型条件。

  • DEVICE_LINKAGE_STATUS:设备状态类型条件。

device_property_condition

DeviceDataCondition object

参数说明:条件中设备数据类型的信息,当type为DEVICE_DATA时,为必选参数。

simple_timer_condition

SimpleTimerType object

参数说明:条件中简单定时类型的信息,当type为SIMPLE_TIMER时,为必选参数。

daily_timer_condition

DailyTimerType object

参数说明:条件中每日定时类型的信息,当type为DAILY_TIMER时,为必选参数。

device_linkage_status_condition

DeviceLinkageStatusCondition object

参数说明:条件中设备状态类型的信息,当规则类型为DEVICE_LINKAGE且type为DEVICE_LINKAGE_STATUS时,为必选参数。

表6 DeviceDataCondition

参数

是否必选

参数类型

描述

device_id

String

参数说明:设备ID,用于唯一标识一个设备,在注册设备时由物联网平台分配获得。存在该参数时设备属性触发根据指定设备触发,该参数值和product_id不能同时为空。如果该参数和product_id同时存在时,以该参数值对应的设备进行条件过滤。 取值范围:长度不超过128,只允许字母、数字、下划线(_)、连接符(-)的组合。

product_id

String

参数说明:设备关联的产品ID,用于唯一标识一个产品模型,创建产品后获得。方法请参见 创建产品。存在该参数且device_id为空时设备属性触发匹配该产品下所有设备触发,该参数值和device_id不能同时为空。

最大长度:128

filters

Array of PropertyFilter objects

数据过滤条件。

表7 PropertyFilter

参数

是否必选

参数类型

描述

path

String

参数说明:设备属性的路径信息,格式:service_id/DataProperty,例如门磁状态为“DoorWindow/status”。

最大长度:128

operator

String

参数说明:数据比较的操作符。 取值范围:当前支持的操作符有:>,<,>=,<=,=,in:表示在指定值中匹配和between:表示数值区间。

value

String

参数说明:数据比较表达式的右值。与数据比较操作符between联用时,右值表示最小值和最大值,用逗号隔开,如“20,30”表示大于等于20小于30。

最大长度:64

in_values

Array of strings

参数说明:当operator为in时该字段必填,使用该字段传递比较表达式右值,上限为20个。

最大长度:128

strategy

Strategy object

参数说明:规则条件的处理策略,用于确定规则是否判断上次数据是否满足条件。当rule_type为DEVICE_LINKAGE时,该参数值不能为空。端侧执行不支持该字段。

表8 Strategy

参数

是否必选

参数类型

描述

trigger

String

参数说明:规则条件触发的判断策略,默认为pulse。 取值范围

  • pulse:设备上报的数据满足条件则触发,不判断上一次上报的数据。

  • reverse:设备上一次上报的数据不满足条件,本次上报的数据满足条件则触发。

event_valid_time

Integer

参数说明:设备数据的有效时间,单位为秒,设备数据的产生时间以上报数据中的eventTime为基准。

最小值:-1

表9 SimpleTimerType

参数

是否必选

参数类型

描述

start_time

String

参数说明:规则触发的开始时间,使用UTC时区,格式:yyyyMMdd'T'HHmmss'Z'。

最大长度:128

repeat_interval

Integer

参数说明:规则触发的重复时间间隔,单位为秒。

最小值:1

最大值:31536000

repeat_count

Integer

参数说明:规则触发的重复次数。

最小值:1

最大值:9999

表10 DailyTimerType

参数

是否必选

参数类型

描述

time

String

参数说明:规则触发的时间,格式:HH:MM。

最大长度:128

days_of_week

String

参数说明:星期列表,以逗号分隔。1代表周日,2代表周一,依次类推,默认为每天。

最大长度:128

表11 DeviceLinkageStatusCondition

参数

是否必选

参数类型

描述

device_id

String

参数说明:设备ID,用于唯一标识一个设备,在注册设备时由物联网平台分配获得。存在该参数时设备状态触发根据指定设备触发,该参数值和product_id不能同时为空。如果该参数和product_id同时存在时,以该参数值对应的设备进行条件过滤。 取值范围:长度不超过128,只允许字母、数字、下划线(_)、连接符(-)的组合。

product_id

String

参数说明:设备关联的产品ID,用于唯一标识一个产品模型,创建产品后获得。方法请参见 创建产品。存在该参数且device_id为空时设备状态触发匹配该产品下所有设备触发,该参数值和device_id不能同时为空。

最大长度:128

status_list

Array of strings

参数说明:状态列表,设备状态条件携带该参数。 取值范围

  • ONLINE:设备上线

  • OFFLINE:设备下线

最大长度:128

duration

Integer

持续时长:设备状态持续时长,取值范围: 0-60(分钟)。

最小值:0

最大值:60

缺省值:0

表12 TimeRange

参数

是否必选

参数类型

描述

start_time

String

参数说明:规则条件触发的开始时间,格式:HH:mm。

end_time

String

参数说明:规则条件触发的结束时间,格式:HH:mm。若结束时间与开始时间一致,则时间为全天。

days_of_week

String

参数说明:星期列表,以逗号分隔。1代表周日,2代表周一,依次类推,默认为每天。星期列表中的日期为开始时间的日期。

表13 RuleAction

参数

是否必选

参数类型

描述

type

String

参数说明:规则动作的类型,端侧执行只支持下发设备命令消息类型。 取值范围

  • DEVICE_CMD:下发设备命令消息类型。

  • SMN_FORWARDING:发送SMN消息类型。

  • DEVICE_ALARM:上报设备告警消息类型。当选择该类型时,condition中必须有DEVICE_DATA条件类型。该类型动作只能唯一。

device_command

ActionDeviceCommand object

下发设备命令消息内容。当type为DEVICE_CMD时,必填。

smn_forwarding

ActionSmnForwarding object

发送给SMN消息结构。当规则类型为DEVICE_LINKAGE且type为SMN_FORWARDING时,必填。

device_alarm

ActionDeviceAlarm object

上报设备告警消息内容。当规则类型为DEVICE_LINKAGE且type为DEVICE_ALARM时,必填。

表14 ActionDeviceCommand

参数

是否必选

参数类型

描述

device_id

String

参数说明:下发命令的设备ID。

  • 当创建设备数据规则时,若device_id为空,则命令下发给触发条件的设备。

  • 当创建定时规则时,不允许为空。 取值范围:长度不超过128,只允许字母、数字、下划线(_)、连接符(-)的组合。

cmd

CMD object

参数说明:下发的命令信息。

表15 CMD

参数

是否必选

参数类型

描述

command_name

String

参数说明:设备命令名称,在设备关联的产品模型中定义。

最大长度:128

command_body

Object

参数说明:设备命令参数,Json格式。 使用LWM2M协议设备命令示例:{"value":"1"},里面是一个个键值对,每个键都是产品模型中命令的参数名(paraName)。 使用MQTT协议设备命令示例:{"header": {"mode": "ACK","from": "/users/testUser","method": "SET_TEMPERATURE_READ_PERIOD","to":"/devices/{device_id}/services/{service_id}"},"body": {"value" : "1"}}。

  • mode:必选,设备收到命令后是否需要回复确认消息,默认为ACK模式。ACK表示需要回复确认消息,NOACK表示不需要回复确认消息,其它值无效。

  • from:可选,命令发送方的地址。App发起请求时格式为/users/{userId} ,应用服务器发起请求时格式为/{serviceName},物联网平台发起请求时格式为/cloud/{serviceName}。

  • to:可选,命令接收方的地址,格式为/devices/{device_id}/services/{service_id}。

  • method:可选,产品模型中定义的命令名称。

  • body:可选,命令的消息体,里面是一个个键值对,每个键都是产品模型中命令的参数名(paraName)。具体格式需要应用和设备约定。

service_id

String

参数说明:设备命令所属的设备服务ID,在设备关联的产品模型中定义。

最大长度:64

buffer_timeout

Integer

参数说明:设备命令的缓存时间,单位为秒,表示物联网平台在把命令下发给设备前缓存命令的有效时间,超过这个时间后命令将不再下发,默认值为172800s(48小时)。 如果buffer_timeout设置为0,则无论物联网平台上设置的命令下发模式是什么,该命令都会立即下发给设备。

最小值:0

最大值:31536000

缺省值:172800

response_timeout

Integer

参数说明:命令响应的有效时间,单位为秒,表示设备接收到命令后,在response_timeout时间内响应有效,超过这个时间未收到命令的响应,则认为命令响应超时,默认值为1800s。

最小值:1

最大值:31536000

缺省值:1800

mode

String

参数说明:设备命令的下发模式,仅当buffer_timeout的值大于0时有效。

  • ACTIVE:主动模式,物联网平台主动将命令下发给设备。

  • PASSIVE:被动模式,物联网平台创建设备命令后,会直接缓存命令。等到设备再次上线或者上报上一条命令的执行结果后才下发命令。

表16 ActionSmnForwarding

参数

是否必选

参数类型

描述

region_name

String

参数说明:SMN服务对应的region区域。

最大长度:256

project_id

String

参数说明:SMN服务对应的projectId信息。

theme_name

String

参数说明:SMN服务对应的主题名称。

最大长度:256

topic_urn

String

参数说明:SMN服务对应的topic的主题URN。

最大长度:256

message_content

String

参数说明:短信或邮件的内容。

最大长度:1024

message_template_name

String

参数说明:SMN服务对应的模板名称。

message_title

String

参数说明:短信或邮件的主题。最大长度支持UTF-8编码后的521个字节。

表17 ActionDeviceAlarm

参数

是否必选

参数类型

描述

name

String

参数说明:告警名称。

最大长度:256

alarm_status

String

参数说明:告警状态。 取值范围

  • fault:上报告警。

  • recovery:恢复告警。

severity

String

参数说明:告警级别。 取值范围:warning(警告)、minor(一般)、major(严重)和critical(致命)。

dimension

String

参数说明:告警维度,与告警名称和告警级别组合起来共同标识一条告警,默认不携带该字段为用户维度告警,支持设备维度和资源空间维度告警。 取值范围

  • device:设备维度。

  • app:资源空间维度。

description

String

参数说明:告警的描述信息。

最大长度:256

表18 DeviceSide

参数

是否必选

参数类型

描述

device_ids

Array of strings

参数说明:端侧执行下发的目标设备ID列表。设备ID,用于唯一标识一个设备,在注册设备时由物联网平台分配获得。

最大长度:128

响应参数

状态码: 200

表19 响应Body参数

参数

参数类型

描述

rule_id

String

规则id。

最大长度:128

name

String

规则名称。

最小长度:1

最大长度:128

description

String

规则的描述信息。

最大长度:256

condition_group

ConditionGroup object

规则的条件组,包含简单规则和复杂规则集合。

actions

Array of RuleAction objects

规则的动作列表,单个规则最多支持设置10个动作。

rule_type

String

规则的类型

  • DEVICE_LINKAGE:云端联动规则。

  • DEVICE_SIDE:端侧规则。

status

String

规则的状态,默认值:active。

  • active:激活。

  • inactive:未激活。

app_id

String

资源空间ID。此参数为非必选参数,存在多资源空间的用户需要使用该接口时,建议携带该参数指定创建的规则归属到哪个资源空间下,否则创建的规则将会归属到默认资源空间下。

edge_node_ids

Array of strings

归属边缘侧节点设备ID列表。

last_update_time

String

规则最后更新时间,使用UTC时区,格式:yyyyMMdd'T'HHmmss'Z'。

device_side

DeviceSide object

参数说明:端侧执行下发设备信息,当规则类型为DEVICE_SIDE时,该参数必填。

表20 ConditionGroup

参数

参数类型

描述

conditions

Array of RuleCondition objects

参数说明:规则的条件列表,单个规则最多支持设置10个条件。

logic

String

参数说明:规则条件列表中多个条件之间的逻辑关系,默认值:and。 取值范围

  • and:逻辑且。

  • or:逻辑或。

time_range

TimeRange object

参数说明:规则条件触发的有效时间段。

表21 RuleCondition

参数

参数类型

描述

type

String

参数说明:规则条件的类型。 取值范围

  • DEVICE_DATA:设备属性数据类型条件。

  • SIMPLE_TIMER:简单定时类型条件。

  • DAILY_TIMER:每日定时类型条件。

  • DEVICE_LINKAGE_STATUS:设备状态类型条件。

device_property_condition

DeviceDataCondition object

参数说明:条件中设备数据类型的信息,当type为DEVICE_DATA时,为必选参数。

simple_timer_condition

SimpleTimerType object

参数说明:条件中简单定时类型的信息,当type为SIMPLE_TIMER时,为必选参数。

daily_timer_condition

DailyTimerType object

参数说明:条件中每日定时类型的信息,当type为DAILY_TIMER时,为必选参数。

device_linkage_status_condition

DeviceLinkageStatusCondition object

参数说明:条件中设备状态类型的信息,当规则类型为DEVICE_LINKAGE且type为DEVICE_LINKAGE_STATUS时,为必选参数。

表22 DeviceDataCondition

参数

参数类型

描述

device_id

String

参数说明:设备ID,用于唯一标识一个设备,在注册设备时由物联网平台分配获得。存在该参数时设备属性触发根据指定设备触发,该参数值和product_id不能同时为空。如果该参数和product_id同时存在时,以该参数值对应的设备进行条件过滤。 取值范围:长度不超过128,只允许字母、数字、下划线(_)、连接符(-)的组合。

product_id

String

参数说明:设备关联的产品ID,用于唯一标识一个产品模型,创建产品后获得。方法请参见 创建产品。存在该参数且device_id为空时设备属性触发匹配该产品下所有设备触发,该参数值和device_id不能同时为空。

最大长度:128

filters

Array of PropertyFilter objects

数据过滤条件。

表23 PropertyFilter

参数

参数类型

描述

path

String

参数说明:设备属性的路径信息,格式:service_id/DataProperty,例如门磁状态为“DoorWindow/status”。

最大长度:128

operator

String

参数说明:数据比较的操作符。 取值范围:当前支持的操作符有:>,<,>=,<=,=,in:表示在指定值中匹配和between:表示数值区间。

value

String

参数说明:数据比较表达式的右值。与数据比较操作符between联用时,右值表示最小值和最大值,用逗号隔开,如“20,30”表示大于等于20小于30。

最大长度:64

in_values

Array of strings

参数说明:当operator为in时该字段必填,使用该字段传递比较表达式右值,上限为20个。

最大长度:128

strategy

Strategy object

参数说明:规则条件的处理策略,用于确定规则是否判断上次数据是否满足条件。当rule_type为DEVICE_LINKAGE时,该参数值不能为空。端侧执行不支持该字段。

表24 Strategy

参数

参数类型

描述

trigger

String

参数说明:规则条件触发的判断策略,默认为pulse。 取值范围

  • pulse:设备上报的数据满足条件则触发,不判断上一次上报的数据。

  • reverse:设备上一次上报的数据不满足条件,本次上报的数据满足条件则触发。

event_valid_time

Integer

参数说明:设备数据的有效时间,单位为秒,设备数据的产生时间以上报数据中的eventTime为基准。

最小值:-1

表25 SimpleTimerType

参数

参数类型

描述

start_time

String

参数说明:规则触发的开始时间,使用UTC时区,格式:yyyyMMdd'T'HHmmss'Z'。

最大长度:128

repeat_interval

Integer

参数说明:规则触发的重复时间间隔,单位为秒。

最小值:1

最大值:31536000

repeat_count

Integer

参数说明:规则触发的重复次数。

最小值:1

最大值:9999

表26 DailyTimerType

参数

参数类型

描述

time

String

参数说明:规则触发的时间,格式:HH:MM。

最大长度:128

days_of_week

String

参数说明:星期列表,以逗号分隔。1代表周日,2代表周一,依次类推,默认为每天。

最大长度:128

表27 DeviceLinkageStatusCondition

参数

参数类型

描述

device_id

String

参数说明:设备ID,用于唯一标识一个设备,在注册设备时由物联网平台分配获得。存在该参数时设备状态触发根据指定设备触发,该参数值和product_id不能同时为空。如果该参数和product_id同时存在时,以该参数值对应的设备进行条件过滤。 取值范围:长度不超过128,只允许字母、数字、下划线(_)、连接符(-)的组合。

product_id

String

参数说明:设备关联的产品ID,用于唯一标识一个产品模型,创建产品后获得。方法请参见 创建产品。存在该参数且device_id为空时设备状态触发匹配该产品下所有设备触发,该参数值和device_id不能同时为空。

最大长度:128

status_list

Array of strings

参数说明:状态列表,设备状态条件携带该参数。 取值范围

  • ONLINE:设备上线

  • OFFLINE:设备下线

最大长度:128

duration

Integer

持续时长:设备状态持续时长,取值范围: 0-60(分钟)。

最小值:0

最大值:60

缺省值:0

表28 TimeRange

参数

参数类型

描述

start_time

String

参数说明:规则条件触发的开始时间,格式:HH:mm。

end_time

String

参数说明:规则条件触发的结束时间,格式:HH:mm。若结束时间与开始时间一致,则时间为全天。

days_of_week

String

参数说明:星期列表,以逗号分隔。1代表周日,2代表周一,依次类推,默认为每天。星期列表中的日期为开始时间的日期。

表29 RuleAction

参数

参数类型

描述

type

String

参数说明:规则动作的类型,端侧执行只支持下发设备命令消息类型。 取值范围

  • DEVICE_CMD:下发设备命令消息类型。

  • SMN_FORWARDING:发送SMN消息类型。

  • DEVICE_ALARM:上报设备告警消息类型。当选择该类型时,condition中必须有DEVICE_DATA条件类型。该类型动作只能唯一。

device_command

ActionDeviceCommand object

下发设备命令消息内容。当type为DEVICE_CMD时,必填。

smn_forwarding

ActionSmnForwarding object

发送给SMN消息结构。当规则类型为DEVICE_LINKAGE且type为SMN_FORWARDING时,必填。

device_alarm

ActionDeviceAlarm object

上报设备告警消息内容。当规则类型为DEVICE_LINKAGE且type为DEVICE_ALARM时,必填。

表30 ActionDeviceCommand

参数

参数类型

描述

device_id

String

参数说明:下发命令的设备ID。

  • 当创建设备数据规则时,若device_id为空,则命令下发给触发条件的设备。

  • 当创建定时规则时,不允许为空。 取值范围:长度不超过128,只允许字母、数字、下划线(_)、连接符(-)的组合。

cmd

CMD object

参数说明:下发的命令信息。

表31 CMD

参数

参数类型

描述

command_name

String

参数说明:设备命令名称,在设备关联的产品模型中定义。

最大长度:128

command_body

Object

参数说明:设备命令参数,Json格式。 使用LWM2M协议设备命令示例:{"value":"1"},里面是一个个键值对,每个键都是产品模型中命令的参数名(paraName)。 使用MQTT协议设备命令示例:{"header": {"mode": "ACK","from": "/users/testUser","method": "SET_TEMPERATURE_READ_PERIOD","to":"/devices/{device_id}/services/{service_id}"},"body": {"value" : "1"}}。

  • mode:必选,设备收到命令后是否需要回复确认消息,默认为ACK模式。ACK表示需要回复确认消息,NOACK表示不需要回复确认消息,其它值无效。

  • from:可选,命令发送方的地址。App发起请求时格式为/users/{userId} ,应用服务器发起请求时格式为/{serviceName},物联网平台发起请求时格式为/cloud/{serviceName}。

  • to:可选,命令接收方的地址,格式为/devices/{device_id}/services/{service_id}。

  • method:可选,产品模型中定义的命令名称。

  • body:可选,命令的消息体,里面是一个个键值对,每个键都是产品模型中命令的参数名(paraName)。具体格式需要应用和设备约定。

service_id

String

参数说明:设备命令所属的设备服务ID,在设备关联的产品模型中定义。

最大长度:64

buffer_timeout

Integer

参数说明:设备命令的缓存时间,单位为秒,表示物联网平台在把命令下发给设备前缓存命令的有效时间,超过这个时间后命令将不再下发,默认值为172800s(48小时)。 如果buffer_timeout设置为0,则无论物联网平台上设置的命令下发模式是什么,该命令都会立即下发给设备。

最小值:0

最大值:31536000

缺省值:172800

response_timeout

Integer

参数说明:命令响应的有效时间,单位为秒,表示设备接收到命令后,在response_timeout时间内响应有效,超过这个时间未收到命令的响应,则认为命令响应超时,默认值为1800s。

最小值:1

最大值:31536000

缺省值:1800

mode

String

参数说明:设备命令的下发模式,仅当buffer_timeout的值大于0时有效。

  • ACTIVE:主动模式,物联网平台主动将命令下发给设备。

  • PASSIVE:被动模式,物联网平台创建设备命令后,会直接缓存命令。等到设备再次上线或者上报上一条命令的执行结果后才下发命令。

表32 ActionSmnForwarding

参数

参数类型

描述

region_name

String

参数说明:SMN服务对应的region区域。

最大长度:256

project_id

String

参数说明:SMN服务对应的projectId信息。

theme_name

String

参数说明:SMN服务对应的主题名称。

最大长度:256

topic_urn

String

参数说明:SMN服务对应的topic的主题URN。

最大长度:256

message_content

String

参数说明:短信或邮件的内容。

最大长度:1024

message_template_name

String

参数说明:SMN服务对应的模板名称。

message_title

String

参数说明:短信或邮件的主题。最大长度支持UTF-8编码后的521个字节。

表33 ActionDeviceAlarm

参数

参数类型

描述

name

String

参数说明:告警名称。

最大长度:256

alarm_status

String

参数说明:告警状态。 取值范围

  • fault:上报告警。

  • recovery:恢复告警。

severity

String

参数说明:告警级别。 取值范围:warning(警告)、minor(一般)、major(严重)和critical(致命)。

dimension

String

参数说明:告警维度,与告警名称和告警级别组合起来共同标识一条告警,默认不携带该字段为用户维度告警,支持设备维度和资源空间维度告警。 取值范围

  • device:设备维度。

  • app:资源空间维度。

description

String

参数说明:告警的描述信息。

最大长度:256

表34 DeviceSide

参数

参数类型

描述

device_ids

Array of strings

参数说明:端侧执行下发的目标设备ID列表。设备ID,用于唯一标识一个设备,在注册设备时由物联网平台分配获得。

最大长度:128

请求示例

修改联动规则,在周二的18点至24点运行规则,当满足visibility小于30或者到19点或者到达指定时触发告警设备属异常,并下发设备命令。

PUT https://{endpoint}/v5/iot/{project_id}/rules/{rule_id}

{
  "name" : "openLight",
  "description" : "string",
  "condition_group" : {
    "time_range" : {
      "days_of_week" : 2,
      "start_time" : "18:00",
      "end_time" : "23:00"
    },
    "logic" : "or",
    "conditions" : [ {
      "device_property_condition" : {
        "device_id" : "07b69d78-c716-4be6-9545-869920738397",
        "product_id" : "074abacf-cdb1-4f52-8c88-5864e50d332c",
        "filters" : [ {
          "path" : "StreetLight/visibility",
          "strategy" : {
            "event_valid_time" : 300,
            "trigger" : "reverse"
          },
          "value" : "30",
          "operator" : "<"
        } ]
      },
      "daily_timer_condition" : {
        "days_of_week" : 2,
        "time" : "19:00"
      },
      "type" : "DEVICE_DATA",
      "simple_timer_condition" : {
        "start_time" : "20190122T141500Z",
        "repeat_interval" : 1,
        "repeat_count" : 1
      }
    } ]
  },
  "actions" : [ {
    "device_alarm" : {
      "severity" : "warning",
      "alarm_status" : "fault",
      "name" : "设备属性异常",
      "description" : "****设备属性异常。"
    },
    "type" : "DEVICE_CMD",
    "smn_forwarding" : {
      "message_content" : "message_content",
      "project_id" : "project_id",
      "message_title" : "message_title",
      "theme_name" : "theme_name",
      "region_name" : "region_name",
      "topic_urn" : "topic_urn"
    },
    "device_command" : {
      "device_id" : "3a9e52d9-3ebf-4985-89e9-6d2396748a2f",
      "cmd" : {
        "buffer_timeout" : 0,
        "mode" : "string",
        "response_timeout" : 1800,
        "command_body" : {
          "value" : 0
        },
        "service_id" : "Switch",
        "command_name" : "SET_LIGHT_SWITCH"
      }
    }
  } ],
  "rule_type" : "DEVICE_LINKAGE",
  "status" : "string",
  "app_id" : "string"
}

响应示例

状态码: 200

OK

{
  "rule_id" : "5eb3628d017d9105d0cf9aec",
  "name" : "openLight",
  "condition_group" : {
    "conditions" : [ {
      "type" : "DEVICE_DATA",
      "device_property_condition" : {
        "device_id" : "07b69d78-c716-4be6-9545-869920738397",
        "filters" : [ {
          "path" : "StreetLight/visibility",
          "operator" : "<",
          "value" : "30",
          "strategy" : {
            "trigger" : "reverse",
            "event_valid_time" : 300
          }
        } ]
      }
    } ],
    "logic" : "and"
  },
  "actions" : [ {
    "type" : "DEVICE_CMD",
    "device_command" : {
      "device_id" : "3a9e52d9-3ebf-4985-89e9-6d2396748a2f",
      "cmd" : {
        "command_name" : "SET_LIGHT_SWITCH",
        "command_body" : {
          "value" : 0
        },
        "service_id" : "Switch",
        "buffer_timeout" : 0,
        "response_timeout" : 1800
      }
    }
  } ],
  "rule_type" : "DEVICE_LINKAGE",
  "status" : "active",
  "app_id" : "9562bf8541e44361b6ae3a7e9fbe1144",
  "last_update_time" : "20221017T025425Z"
}

SDK代码示例

SDK代码示例如下。

Java

修改联动规则,在周二的18点至24点运行规则,当满足visibility小于30或者到19点或者到达指定时触发告警设备属异常,并下发设备命令。

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.AbstractCredentials;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.iotda.v5.region.IoTDARegion;
import com.huaweicloud.sdk.iotda.v5.*;
import com.huaweicloud.sdk.iotda.v5.model.*;

import java.util.List;
import java.util.ArrayList;

public class UpdateRuleSolution {

    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");

        ICredential auth = new BasicCredentials()
                .withDerivedPredicate(AbstractCredentials.DEFAULT_DERIVED_PREDICATE) // Used in derivative ak/sk authentication scenarios
                .withAk(ak)
                .withSk(sk);

        IoTDAClient client = IoTDAClient.newBuilder()
                .withCredential(auth)
                .withRegion(IoTDARegion.valueOf("<YOUR REGION>"))
                .build();
        UpdateRuleRequest request = new UpdateRuleRequest();
        Rule body = new Rule();
        ActionDeviceAlarm deviceAlarmActions = new ActionDeviceAlarm();
        deviceAlarmActions.withName("设备属性异常")
            .withAlarmStatus("fault")
            .withSeverity("warning")
            .withDescription("****设备属性异常。");
        ActionSmnForwarding smnForwardingActions = new ActionSmnForwarding();
        smnForwardingActions.withRegionName("region_name")
            .withProjectId("project_id")
            .withThemeName("theme_name")
            .withTopicUrn("topic_urn")
            .withMessageContent("message_content")
            .withMessageTitle("message_title");
        Cmd cmdDeviceCommand = new Cmd();
        cmdDeviceCommand.withCommandName("SET_LIGHT_SWITCH")
            .withCommandBody("{\"value\":0}")
            .withServiceId("Switch")
            .withBufferTimeout(0)
            .withResponseTimeout(1800)
            .withMode("string");
        ActionDeviceCommand deviceCommandActions = new ActionDeviceCommand();
        deviceCommandActions.withDeviceId("3a9e52d9-3ebf-4985-89e9-6d2396748a2f")
            .withCmd(cmdDeviceCommand);
        List<RuleAction> listbodyActions = new ArrayList<>();
        listbodyActions.add(
            new RuleAction()
                .withType("DEVICE_CMD")
                .withDeviceCommand(deviceCommandActions)
                .withSmnForwarding(smnForwardingActions)
                .withDeviceAlarm(deviceAlarmActions)
        );
        TimeRange timeRangeConditionGroup = new TimeRange();
        timeRangeConditionGroup.withStartTime("18:00")
            .withEndTime("23:00")
            .withDaysOfWeek("2");
        DailyTimerType dailyTimerConditionConditions = new DailyTimerType();
        dailyTimerConditionConditions.withTime("19:00")
            .withDaysOfWeek("2");
        SimpleTimerType simpleTimerConditionConditions = new SimpleTimerType();
        simpleTimerConditionConditions.withStartTime("20190122T141500Z")
            .withRepeatInterval(1)
            .withRepeatCount(1);
        Strategy strategyFilters = new Strategy();
        strategyFilters.withTrigger("reverse")
            .withEventValidTime(300);
        List<PropertyFilter> listDevicePropertyConditionFilters = new ArrayList<>();
        listDevicePropertyConditionFilters.add(
            new PropertyFilter()
                .withPath("StreetLight/visibility")
                .withOperator("<")
                .withValue("30")
                .withStrategy(strategyFilters)
        );
        DeviceDataCondition devicePropertyConditionConditions = new DeviceDataCondition();
        devicePropertyConditionConditions.withDeviceId("07b69d78-c716-4be6-9545-869920738397")
            .withProductId("074abacf-cdb1-4f52-8c88-5864e50d332c")
            .withFilters(listDevicePropertyConditionFilters);
        List<RuleCondition> listConditionGroupConditions = new ArrayList<>();
        listConditionGroupConditions.add(
            new RuleCondition()
                .withType("DEVICE_DATA")
                .withDevicePropertyCondition(devicePropertyConditionConditions)
                .withSimpleTimerCondition(simpleTimerConditionConditions)
                .withDailyTimerCondition(dailyTimerConditionConditions)
        );
        ConditionGroup conditionGroupbody = new ConditionGroup();
        conditionGroupbody.withConditions(listConditionGroupConditions)
            .withLogic("or")
            .withTimeRange(timeRangeConditionGroup);
        body.withAppId("string");
        body.withStatus("string");
        body.withRuleType("DEVICE_LINKAGE");
        body.withActions(listbodyActions);
        body.withConditionGroup(conditionGroupbody);
        body.withDescription("string");
        body.withName("openLight");
        request.withBody(body);
        try {
            UpdateRuleResponse response = client.updateRule(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}

Python

修改联动规则,在周二的18点至24点运行规则,当满足visibility小于30或者到19点或者到达指定时触发告警设备属异常,并下发设备命令。

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# coding: utf-8

from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcore.auth.credentials import DerivedCredentials
from huaweicloudsdkiotda.v5.region.iotda_region import IoTDARegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkiotda.v5 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = __import__('os').getenv("CLOUD_SDK_AK")
    sk = __import__('os').getenv("CLOUD_SDK_SK")

    credentials = BasicCredentials(ak, sk) \
            .with_derived_predicate(DerivedCredentials.get_default_derived_predicate()) \

    client = IoTDAClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(IoTDARegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = UpdateRuleRequest()
        deviceAlarmActions = ActionDeviceAlarm(
            name="设备属性异常",
            alarm_status="fault",
            severity="warning",
            description="****设备属性异常。"
        )
        smnForwardingActions = ActionSmnForwarding(
            region_name="region_name",
            project_id="project_id",
            theme_name="theme_name",
            topic_urn="topic_urn",
            message_content="message_content",
            message_title="message_title"
        )
        cmdDeviceCommand = Cmd(
            command_name="SET_LIGHT_SWITCH",
            command_body="{\"value\":0}",
            service_id="Switch",
            buffer_timeout=0,
            response_timeout=1800,
            mode="string"
        )
        deviceCommandActions = ActionDeviceCommand(
            device_id="3a9e52d9-3ebf-4985-89e9-6d2396748a2f",
            cmd=cmdDeviceCommand
        )
        listActionsbody = [
            RuleAction(
                type="DEVICE_CMD",
                device_command=deviceCommandActions,
                smn_forwarding=smnForwardingActions,
                device_alarm=deviceAlarmActions
            )
        ]
        timeRangeConditionGroup = TimeRange(
            start_time="18:00",
            end_time="23:00",
            days_of_week="2"
        )
        dailyTimerConditionConditions = DailyTimerType(
            time="19:00",
            days_of_week="2"
        )
        simpleTimerConditionConditions = SimpleTimerType(
            start_time="20190122T141500Z",
            repeat_interval=1,
            repeat_count=1
        )
        strategyFilters = Strategy(
            trigger="reverse",
            event_valid_time=300
        )
        listFiltersDevicePropertyCondition = [
            PropertyFilter(
                path="StreetLight/visibility",
                operator="<",
                value="30",
                strategy=strategyFilters
            )
        ]
        devicePropertyConditionConditions = DeviceDataCondition(
            device_id="07b69d78-c716-4be6-9545-869920738397",
            product_id="074abacf-cdb1-4f52-8c88-5864e50d332c",
            filters=listFiltersDevicePropertyCondition
        )
        listConditionsConditionGroup = [
            RuleCondition(
                type="DEVICE_DATA",
                device_property_condition=devicePropertyConditionConditions,
                simple_timer_condition=simpleTimerConditionConditions,
                daily_timer_condition=dailyTimerConditionConditions
            )
        ]
        conditionGroupbody = ConditionGroup(
            conditions=listConditionsConditionGroup,
            logic="or",
            time_range=timeRangeConditionGroup
        )
        request.body = Rule(
            app_id="string",
            status="string",
            rule_type="DEVICE_LINKAGE",
            actions=listActionsbody,
            condition_group=conditionGroupbody,
            description="string",
            name="openLight"
        )
        response = client.update_rule(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Go

修改联动规则,在周二的18点至24点运行规则,当满足visibility小于30或者到19点或者到达指定时触发告警设备属异常,并下发设备命令。

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    iotda "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iotda/v5"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iotda/v5/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iotda/v5/region"
    core_auth "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        WithDerivedPredicate(core_auth.GetDefaultDerivedPredicate()). // Used in derivative ak/sk authentication scenarios
        Build()

    client := iotda.NewIoTDAClient(
        iotda.IoTDAClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.UpdateRuleRequest{}
	descriptionDeviceAlarm:= "****设备属性异常。"
	deviceAlarmActions := &model.ActionDeviceAlarm{
		Name: "设备属性异常",
		AlarmStatus: "fault",
		Severity: "warning",
		Description: &descriptionDeviceAlarm,
	}
	messageContentSmnForwarding:= "message_content"
	smnForwardingActions := &model.ActionSmnForwarding{
		RegionName: "region_name",
		ProjectId: "project_id",
		ThemeName: "theme_name",
		TopicUrn: "topic_urn",
		MessageContent: &messageContentSmnForwarding,
		MessageTitle: "message_title",
	}
	var commandBodyCmd interface{} = "{\"value\":0}"
	bufferTimeoutCmd:= int32(0)
	responseTimeoutCmd:= int32(1800)
	modeCmd:= "string"
	cmdDeviceCommand := &model.Cmd{
		CommandName: "SET_LIGHT_SWITCH",
		CommandBody: &commandBodyCmd,
		ServiceId: "Switch",
		BufferTimeout: &bufferTimeoutCmd,
		ResponseTimeout: &responseTimeoutCmd,
		Mode: &modeCmd,
	}
	deviceIdDeviceCommand:= "3a9e52d9-3ebf-4985-89e9-6d2396748a2f"
	deviceCommandActions := &model.ActionDeviceCommand{
		DeviceId: &deviceIdDeviceCommand,
		Cmd: cmdDeviceCommand,
	}
	var listActionsbody = []model.RuleAction{
        {
            Type: "DEVICE_CMD",
            DeviceCommand: deviceCommandActions,
            SmnForwarding: smnForwardingActions,
            DeviceAlarm: deviceAlarmActions,
        },
    }
	daysOfWeekTimeRange:= "2"
	timeRangeConditionGroup := &model.TimeRange{
		StartTime: "18:00",
		EndTime: "23:00",
		DaysOfWeek: &daysOfWeekTimeRange,
	}
	daysOfWeekDailyTimerCondition:= "2"
	dailyTimerConditionConditions := &model.DailyTimerType{
		Time: "19:00",
		DaysOfWeek: &daysOfWeekDailyTimerCondition,
	}
	simpleTimerConditionConditions := &model.SimpleTimerType{
		StartTime: "20190122T141500Z",
		RepeatInterval: int32(1),
		RepeatCount: int32(1),
	}
	triggerStrategy:= "reverse"
	eventValidTimeStrategy:= int32(300)
	strategyFilters := &model.Strategy{
		Trigger: &triggerStrategy,
		EventValidTime: &eventValidTimeStrategy,
	}
	valueFilters:= "30"
	var listFiltersDevicePropertyCondition = []model.PropertyFilter{
        {
            Path: "StreetLight/visibility",
            Operator: "<",
            Value: &valueFilters,
            Strategy: strategyFilters,
        },
    }
	deviceIdDevicePropertyCondition:= "07b69d78-c716-4be6-9545-869920738397"
	productIdDevicePropertyCondition:= "074abacf-cdb1-4f52-8c88-5864e50d332c"
	devicePropertyConditionConditions := &model.DeviceDataCondition{
		DeviceId: &deviceIdDevicePropertyCondition,
		ProductId: &productIdDevicePropertyCondition,
		Filters: &listFiltersDevicePropertyCondition,
	}
	var listConditionsConditionGroup = []model.RuleCondition{
        {
            Type: "DEVICE_DATA",
            DevicePropertyCondition: devicePropertyConditionConditions,
            SimpleTimerCondition: simpleTimerConditionConditions,
            DailyTimerCondition: dailyTimerConditionConditions,
        },
    }
	logicConditionGroup:= "or"
	conditionGroupbody := &model.ConditionGroup{
		Conditions: &listConditionsConditionGroup,
		Logic: &logicConditionGroup,
		TimeRange: timeRangeConditionGroup,
	}
	appIdRule:= "string"
	statusRule:= "string"
	descriptionRule:= "string"
	request.Body = &model.Rule{
		AppId: &appIdRule,
		Status: &statusRule,
		RuleType: "DEVICE_LINKAGE",
		Actions: listActionsbody,
		ConditionGroup: conditionGroupbody,
		Description: &descriptionRule,
		Name: "openLight",
	}
	response, err := client.UpdateRule(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

OK

400

Bad Request

403

Forbidden

404

Not Found

500

Internal Server Error

错误码

请参见错误码

分享:

    相关文档

    相关产品