Cranes - Amazon IoT Events
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 Amazon Web Services 服务入门

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

Cranes

背景故事

许多起重机的操作员希望检测机器何时需要维护或更换,并触发适当的通知。每台起重机都有一个马达。电机发出有关压力和温度信息的信息(输入)。操作员需要两个级别的事件检测器:

  • 起重机级事件检测器

  • 电机级事件检测器

使用来自电动机的消息(其中包含"craneId""motorId"),操作员可以使用适当的路由执行两个级别的事件检测器。满足事件条件后,应向相应的 Amazon SNS 主题发送通知。操作员可以配置检测器模型,以便不会引发重复的通知。

此示例演示了以下功能功能:

  • 创建、读取、更新、删除 (CRUD) 输入。

  • 创建、读取、更新、删除 (CRUD) 事件检测器模型和不同版本的事件检测器。

  • 将一个输入路由到多个事件检测器。

  • 将输入引入检测器模型。

  • 触发条件和生命周期事件的评估。

  • 能够引用条件中的状态变量并根据条件设置它们的值。

  • 包含定义、状态、触发器赋值器和操作执行程序的运行时协调。

  • 中的操作的执行ActionsExecutor带有 SNS 目标。

Commands

#Create Pressure Input aws iotevents create-input --cli-input-json file://pressureInput.json aws iotevents describe-input --input-name PressureInput aws iotevents update-input --cli-input-json file://pressureInput.json aws iotevents list-inputs aws iotevents delete-input --input-name PressureInput #Create Temperature Input aws iotevents create-input --cli-input-json file://temperatureInput.json aws iotevents describe-input --input-name TemperatureInput aws iotevents update-input --cli-input-json file://temperatureInput.json aws iotevents list-inputs aws iotevents delete-input --input-name TemperatureInput #Create Motor Event Detector using pressure and temperature input aws iotevents create-detector-model --cli-input-json file://motorDetectorModel.json aws iotevents describe-detector-model --detector-model-name motorDetectorModel aws iotevents update-detector-model --cli-input-json file://updateMotorDetectorModel.json aws iotevents list-detector-models aws iotevents list-detector-model-versions --detector-model-name motorDetectorModel aws iotevents delete-detector-model --detector-model-name motorDetectorModel #Create Crane Event Detector using temperature input aws iotevents create-detector-model --cli-input-json file://craneDetectorModel.json aws iotevents describe-detector-model --detector-model-name craneDetectorModel aws iotevents update-detector-model --cli-input-json file://updateCraneDetectorModel.json aws iotevents list-detector-models aws iotevents list-detector-model-versions --detector-model-name craneDetectorModel aws iotevents delete-detector-model --detector-model-name craneDetectorModel #Replace craneIds sed -i '' "s/100008/100009/g" messages/* #Replace motorIds sed -i '' "s/200008/200009/g" messages/* #Send HighPressure message aws iotevents-data batch-put-message --cli-input-json file://messages/highPressureMessage.json #Send HighTemperature message aws iotevents-data batch-put-message --cli-input-json file://messages/highTemperatureMessage.json #Send LowPressure message aws iotevents-data batch-put-message --cli-input-json file://messages/lowPressureMessage.json #Send LowTemperature message aws iotevents-data batch-put-message --cli-input-json file://messages/lowTemperatureMessage.json

探测器模型数

file:craneDetectorModel.json

{ "detectorModelName": "craneDetectorModel", "detectorModelDefinition": { "states": [ { "stateName": "Running", "onEnter": { "events": [ { "eventName": "init", "condition": "true", "actions": [ { "setVariable": { "variableName": "craneThresholdBreached", "value": "0" } } ] } ] }, "onInput": { "events": [ { "eventName": "Overheated", "condition": "$input.TemperatureInput.temperature > 35", "actions": [ { "setVariable": { "variableName": "craneThresholdBreached", "value": "$variable.craneThresholdBreached + 1" } } ] }, { "eventName": "Crane Threshold Breached", "condition": "$variable.craneThresholdBreached > 5", "actions": [ { "sns": { "targetArn": "arn:aws:sns:us-east-1:123456789012:CraneSNSTopic" } } ] }, { "eventName": "Underheated", "condition": "$input.TemperatureInput.temperature < 25", "actions": [ { "setVariable": { "variableName": "craneThresholdBreached", "value": "0" } } ] } ] } } ], "initialStateName": "Running" }, "key": "craneid", "roleArn": "arn:aws:iam::123456789012:role/columboSNSRole" }

更新现有检测器型号。file:updateCraneDetectorModel.json

{ "detectorModelName": "craneDetectorModel", "detectorModelDefinition": { "states": [ { "stateName": "Running", "onEnter": { "events": [ { "eventName": "init", "condition": "true", "actions": [ { "setVariable": { "variableName": "craneThresholdBreached", "value": "0" } }, { "setVariable": { "variableName": "alarmRaised", "value": "'false'" } } ] } ] }, "onInput": { "events": [ { "eventName": "Overheated", "condition": "$input.TemperatureInput.temperature > 30", "actions": [ { "setVariable": { "variableName": "craneThresholdBreached", "value": "$variable.craneThresholdBreached + 1" } } ] }, { "eventName": "Crane Threshold Breached", "condition": "$variable.craneThresholdBreached > 5 && $variable.alarmRaised == 'false'", "actions": [ { "sns": { "targetArn": "arn:aws:sns:us-east-1:123456789012:CraneSNSTopic" } }, { "setVariable": { "variableName": "alarmRaised", "value": "'true'" } } ] }, { "eventName": "Underheated", "condition": "$input.TemperatureInput.temperature < 10", "actions": [ { "setVariable": { "variableName": "craneThresholdBreached", "value": "0" } } ] } ] } } ], "initialStateName": "Running" }, "roleArn": "arn:aws:iam::123456789012:role/columboSNSRole" }

file:motorDetectorModel.json

{ "detectorModelName": "motorDetectorModel", "detectorModelDefinition": { "states": [ { "stateName": "Running", "onEnter": { "events": [ { "eventName": "init", "condition": "true", "actions": [ { "setVariable": { "variableName": "motorThresholdBreached", "value": "0" } } ] } ] }, "onInput": { "events": [ { "eventName": "Overheated And Overpressurized", "condition": "$input.PressureInput.pressure > 70 && $input.TemperatureInput.temperature > 30", "actions": [ { "setVariable": { "variableName": "motorThresholdBreached", "value": "$variable.motorThresholdBreached + 1" } } ] }, { "eventName": "Motor Threshold Breached", "condition": "$variable.motorThresholdBreached > 5", "actions": [ { "sns": { "targetArn": "arn:aws:sns:us-east-1:123456789012:MotorSNSTopic" } } ] } ] } } ], "initialStateName": "Running" }, "key": "motorid", "roleArn": "arn:aws:iam::123456789012:role/columboSNSRole" }

更新现有检测器型号。file:updateMotorDetectorModel.json

{ "detectorModelName": "motorDetectorModel", "detectorModelDefinition": { "states": [ { "stateName": "Running", "onEnter": { "events": [ { "eventName": "init", "condition": "true", "actions": [ { "setVariable": { "variableName": "motorThresholdBreached", "value": "0" } } ] } ] }, "onInput": { "events": [ { "eventName": "Overheated And Overpressurized", "condition": "$input.PressureInput.pressure > 70 && $input.TemperatureInput.temperature > 30", "actions": [ { "setVariable": { "variableName": "motorThresholdBreached", "value": "$variable.motorThresholdBreached + 1" } } ] }, { "eventName": "Motor Threshold Breached", "condition": "$variable.motorThresholdBreached > 5", "actions": [ { "sns": { "targetArn": "arn:aws:sns:us-east-1:123456789012:MotorSNSTopic" } } ] } ] } } ], "initialStateName": "Running" }, "roleArn": "arn:aws:iam::123456789012:role/columboSNSRole" }

Inputs

file:pressureInput.json

{ "inputName": "PressureInput", "inputDescription": "this is a pressure input description", "inputDefinition": { "attributes": [ {"jsonPath": "pressure"} ] } }

file:temperatureInput.json

{ "inputName": "TemperatureInput", "inputDescription": "this is temperature input description", "inputDefinition": { "attributes": [ {"jsonPath": "temperature"} ] } }

Messages

file:highPressureMessage.json

{ "messages": [ { "messageId": "1", "inputName": "PressureInput", "payload": "{\"craneid\": \"100009\", \"pressure\": 80, \"motorid\": \"200009\"}" } ] }

file:highTemperatureMessage.json

{ "messages": [ { "messageId": "2", "inputName": "TemperatureInput", "payload": "{\"craneid\": \"100009\", \"temperature\": 40, \"motorid\": \"200009\"}" } ] }

file:lowPressureMessage.json

{ "messages": [ { "messageId": "1", "inputName": "PressureInput", "payload": "{\"craneid\": \"100009\", \"pressure\": 20, \"motorid\": \"200009\"}" } ] }

file:lowTemperatureMessage.json

{ "messages": [ { "messageId": "2", "inputName": "TemperatureInput", "payload": "{\"craneid\": \"100009\", \"temperature\": 20, \"motorid\": \"200009\"}" } ] }