如何在断开状态上的Azure IoT设备上创建警报
我有许多Azure IoT中央设备,其中2个设备经常断开连接,但是有人可以告诉我,如果将EVENT_STATUS断开超过5分钟,是否有办法创建真正的警报。
谢谢
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我有许多Azure IoT中央设备,其中2个设备经常断开连接,但是有人可以告诉我,如果将EVENT_STATUS断开超过5分钟,是否有办法创建真正的警报。
谢谢
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
在物联网中,中央规则只能应用于其关联模板和其报告属性的设备上的遥测值。设备连接/断开事件可通过数据导出获得,但是规则逻辑需要在Azure函数或逻辑应用程序,API等中运行该应用程序外部。
除非您具有心跳遥测作为布尔或数字,否则您无法从设备中进行heartemetry。使用内置规则功能推断断开事件的时间汇总计数。一种骇客和非理想的方法是计数在时间聚集窗口中出现的度量的次数,说明5分钟,如果其小于1,则将其推断为断开的设备。如果该度量标准的遥测频率高于聚合窗口,则这将行不通。
例如,如果在聚合窗口中的设备中一次接收湿度测量,则可以通过计算在5分钟时间聚集窗口中收到多少次来推断断开的设备。
In IoT Central rules can be applied only to Telemetry values on devices targeted by their associated template and optionally by their reported properties. The device connection/disconnection events are available via data export but then the rule logic needs to run external to the app in Azure function or logic app, api, etc.
Unless you have heartbeat telemetry coming as a boolean or numeric from the device you cannot time aggregate count to infer disconnection event using the built-in rules functionality. A hacky and non-ideal approach is to count number of times a metric appeared in the time aggregation window say 5 minutes and if its less than 1 infer that as a disconnected device. This will not work if telemetry frequency for that metric is higher than aggregation window.
As an example, if humidity measurement is received at-least once by the device in the aggregation window then it can be used to infer a disconnected device by counting how many times it was received in the 5min time aggregation window.
以下屏幕片段是使用设备连接功能中使用设备连接事件的示例( @umblyjay的答案),以适用于您的设备连接watchDog:
如上图所示,概念非常简单,当设备断开连接时,将带有时间表(5分钟)的看门狗消息(例如CloudEvents消息)发送到看门狗队列。在这种情况下,当设备在看门狗时间内重新连接时,该消息将从看门狗队列中删除,否则将在其TTL过期时将消息转发到警报队列。
请注意,设备连接事件是有限制的,请参见更多详细信息此处。
1A。目标 - webhook:
1B。数据转换:
另外,我建议添加一个目标目标,例如带有CloudEvents Input Schema的Azure事件Grid自定义主题的端点,请参见以下屏幕snippet:
将上述httptrigger azure函数移动到AEG订阅者正在为您的解决方案提供一个pub/substimity,用于分发设备连接事件(例如过滤),等等。
The following screen snippet is an example of using the Device Connectivity Events in the Data Export feature (mentioned by @humblejay's answer) for your device connectivity watchdog:
As the above picture shows, the concept is very simple, when the device is disconnected, the watchdog message (such as the CloudEvents message) with the TimeToLive (5 minutes) is sent to the watchdog queue. In the case, when the device is reconnected within the watchdog time, the message is deleted from the watchdog queue, otherwise the message is forwarded to the Alert queue when its TTL is expired.
Note, that the device connectivity events is generated with some limitations, see more details here.
1a. Destination - Webhook:
1b. Data Transform:
Also, I do recommend to add one more destination target, such as the endpoint of the Azure Event Grid custom topic with a CloudEvents input schema, see the following screen snippet:
Moving the above HttpTrigger Azure Function to the AEG subscriber is giving for your solution a Pub/Sub flexibility for distributing the device connectivity events such as a filtering, etc.