主要内容

本页采用了机器翻译。点击此处可查看最新英文版本。

React App

React 与 ThingHTTP 和 MATLAB® Analysis App 配合使用,当通道数据满足特定条件时执行操作。例如,您可以让移动 App 将您的纬度和经度报告给 ThingSpeak™ 通道。当您的位置距离您的房子一定距离以内时,让 ThingHTTP 打开您客厅的灯。

注意

如果您在使用 Bulk-Write JSON Data 时使用 React App 并将 Test Frequency 设置为 On Data Insertion,则每次批量更新请求时都会触发一次 React。当 Condition 与 ConditionType 匹配时就会触发,即使 Condition 匹配多次。

如果您将 React 设置为在特定 Test Frequency 和特定 Condition Type 上运行,请谨慎注意 React 的触发方式。现在数据是随着时间的推移而收集并批量更新的,并且触发 React 的 Condition Type 可以在单个数据批次内变化。

定义对通道数据的反应

  1. 选择 Apps > React。

  2. 点击 New React。

  3. 选择:

    • Condition Type

    • Test Frequency

    • Action

    • Options

  4. 点击 Save React。

条件类型

ThingSpeak 通道支持数字传感器数据、文本、字符串、状态更新和地理位置信息。使用这些条件类型来指定根据您的通道数据触发反应的条件。

字符串

此条件测试 ThingSpeak 通道字段中包含 ASCII 字符的文本字符串。例如,"If Channel 1, Field 1, is equal to blue, then set my light to blue"。

测试字符串时,请使用以下约束检查数据:

  • 包含

  • 始于

  • 终于

  • 等于

  • 不等于

状态

此条件测试通道中的 ThingSpeak 状态。您可以搜索某个单词的状态,并在满足测试条件时发送 ThingHTTP 请求。

测试 ThingSpeak 通道状态时,请使用以下约束检查数据:

  • 包含

  • 始于

  • 终于

  • 等于

  • 不等于

数值

如果 ThingSpeak 通道的字段中有传感器数据或数值数据,请使用数字条件。您可以使用 ThingHTTP 向另一个接受 HTTP 请求的服务或设备发送控制命令。

在测试 ThingSpeak 通道字段中的数字时,请使用以下约束检查数据:

  • 大于

  • 大于或等于

  • 小于

  • 小于或等于

  • 等于

  • 不等于

地理位置

此条件检查 ThingSpeak 通道中的位置数据。例如,如果您的移动 App 将您的纬度和经度报告给 ThingSpeak 通道,则当您的位置距离您的房子一定距离以内时,您就可以打开客厅的灯。

在 ThingSpeak 通道上测试位置信息时,请使用以下约束检查数据:

  • 在之内

  • 远于

无数据检查

此条件检查 ThingSpeak 通道是否以指定的间隔接收数据。如果在指定的时间范围内没有发生数据更新,则会触发 React App 中选择的操作。例如,如果停电导致您的设备中断并且您的通道没有更新,您可以触发操作。指定您的通道在触发操作之前未接收新数据的时间量。

测试频率

选择可以测试指定条件的频率。

  • On Data Insertion:每次插入数据时进行测试。对于完全相同的条件,您不能使用 On Data Insertion 配置多个 React。

  • Every 10 minutes:每 10 分钟测试一次,按时进行。例如,上午 10:08 创建的 React 将在上午 10:18、上午 10:28 以及之后每 10 分钟触发。

  • Every 30 minutes:每 30 分钟测试一次,按时进行。

  • Every 60 minutes:每小时测试一次,按时进行。

操作

您可以触发 MATLAB Analysis 或 ThingHTTP 操作。

更换密钥

您可以使用替换密钥将数据传递到您的 App。下表总结了您可以使用的标准和自定义替换键。有些键特定于特定类型的请求,如最后一列所示。

键描述示例使用场合
%%YOUR_CUSTOM_LABEL%%ThingHTTP 会用触发请求中带有标签 "YOUR_CUSTOM_LABEL" 的数据来替换该自定义替换值。field1=%%YOUR_CUSTOM_LABEL%%
POST 数据:YOUR_CUSTOM_LABEL=1234。
RESULT:field1=1234。
任何请求
%%channel_CHANNEL_ID_
field_FIELD_NUMBER%%
指定通道和字段的最后一个值。对与 ThingHTTP 请求不属于同一用户的私有通道的替换请求将返回空白值。The latest value is %%channel_12_field_1%%。
结果:The latest value is 2.5。
任何请求
%%datetime%%TimeControl 或 React 运行的完整日期和时间。The date and time the event occurred is %%datetime%%。
结果:The date and time the event occurred is 2014-09-24 5:32 p.m。
TimeControl 或 React
%%day%%TimeControl 运行时的星期几的名称。The day the event occurred is %%day%%。
结果:The day the event occurred is Wednesday。
TimeControl
%%day_index%% 从星期日开始的工作日的从零开始的索引。The number of days used this week is %%day_index%%。
结果:The number of days used this week is 3。
TimeControl
%%hour%%TimeControl 运行的当天小时数。The hour that the event occurred is %%hour%%。
结果:The hour that the event occurred is 5。
TimeControl
%%minute%%TimeControl 运行时的小时数。The minute the event occurred is %%minute%%。
结果:The minute the event occurred is 30。
TimeControl
%%trigger%%触发 React 的值。It is way too hot in here at %%trigger%% C.
结果:It is way too hot in here at 40 C。
React
%%channel_id%%触发 React 的通道 ID。The channel that triggers is %%channel_id%%。
结果:The channel that triggers is 1256。
React

选项

  • Run action only the first time the condition is met:如果条件先前为假而当前为真,则触发操作。

  • Run action each time condition is met:每次条件为真时触发操作。

React App 中使用 MATLAB 分析代码错误

当您拥有使用 React 的 MATLAB 分析代码时,如果 MATLAB 分析代码中出现多个连续错误,React 将停止运行。您可以通过选中 MATLAB 分析应用程序中的 Notify me via email if this MATLAB Analysis fails when triggered by TimeControl or React 框来选择通过电子邮件接收警报。