时间控制 App
TimeControl App 可与其他 ThingSpeak™ App 配合使用:MATLAB Analysis、ThingHTTP、ThingTweet 或 TalkBack 在特定时间或日期执行操作有规律的调度。您可以将 TimeControl 与:
ThingHTTP 与设备、网站或 Web 服务进行通信。
MATLAB® 对您的数据进行分析。
ThingTweet 通过 Twitter® 发送警报。
TalkBack 用于对设备的命令进行排队。
示例,您可以发出 ThingHTTP请求,通过 Twilio® 呼叫某人、控制设备或连接到接受 HTTP 请求的恒温器。
注意
每个用户的 TimeControl 数量限制为 12 个。
使用 TimeControl 安排操作
登录 ThingSpeak。
选择Apps > TimeControl。
点击 New TimeControl。
编辑时间控制设置:
Name:为此时间控件输入唯一的名称。
Time Zone:时区基于您的帐户设置。要更改您的个人资料时区,请点击“编辑”。
Frequency:选择 TimeControl 是运行一次还是定期运行。
注意
拥有免费许可证的用户必须至少每 60 天登录一次 ThingSpeak,以保持重复时间控制处于活动状态。
Recurrence:选择重复模式。
Week:每个指定的工作日。
Day:每天在指定时间。
Hour:以指定的每小时间隔。当重复周期设置为 Hour 时,您无法指定 TimeControl 的开始时间。
Minute:以指定的分钟间隔。当重复周期设置为 Minute 时,您无法指定 TimeControl 的开始时间。
Time:输入 TimeControl 运行的时间。对于 Hour 和 Minute 重复,ThingSpeak 自动安排您的 TimeControl。每次编辑时间控件时都会重新安排开始时间。保存 TimeControl 后,请务必检查开始时间和日期。
Fuzzy Time:选择 TimeControl 运行的计划时间周围的分钟数。对于 5 分钟的模糊时间,基本间隔必须至少为 12 分钟;对于 10 分钟的模糊时间,基本间隔必须至少为 30 分钟。
Action:选择满足指定参数时要触发的操作。
MATLAB Analysis:运行预定的代码。
ThingHTTP:连接到 Web 服务器并读取或写入数据。
ThingTweet:向指定的 Twitter 帐户发送推文。
TalkBack:将命令排队发送到您的设备。
执行时间控制
ThingSpeak 服务器根据您的时区在指定时间自动执行 TimeControl。确保您的时区在 ThingSpeak profile 中正确指定。请记住,触发写入同一通道的多个 TimeControl 仍必须遵守消息更新限制。
提示
TimeControl 以严格的 24 小时周期运行。修改您的 TimeControl 以考虑夏令时的变化。
更换密钥
您可以使用替换密钥将数据传递到您的 App 。下表总结了您可以使用的标准和自定义替换密钥。某些键特定于特定类型的请求,如最后一列所示。
键 | 描述 | 例子 | 使用场合 |
---|---|---|---|
%%YOUR_CUSTOM_LABEL%% | ThingHTTP 将此自定义替换值替换为触发请求中具有标签“YOUR_CUSTOM_LABEL”的数据。 | field1=%%YOUR_CUSTOM_LABEL%% 发布数据:YOUR_CUSTOM_LABEL=1234 .结果: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 %%日期时间%% .结果:The date and time the event occurred is 2014-09-24 5:32 pm . | 时间控制或反应 |
%%day%% | TimeControl 运行时的工作日名称。 | The day the event occurred is %%day%% .结果:The day the event occurred is 星期三。 | 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 %%小时%% .结果:The hour that the event occurred is 5 . | TimeControl |
%%minute%% | TimeControl 运行时的分钟。 | The minute the event occurred is %%分钟%% .结果: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 。 | 反应 |
%%channel_id%% | 触发React的通道ID。 | The channel that tweets is %%channel_id%% .结果:The channel that tweets is 1256 。 | 反应 |
使用 ThingHTTP 更新通道状态
此示例显示如何更新 ThingSpeak通道“field1”。TimeControl 触发 ThingHTTP请求,以在指定时间使用状态消息和时间戳更新通道数据。
创建 ThingHTTP 请求
在 ThingHTTP 中,输入名称 ThingSpeak Channel Updater 以及以下参数:
URL:
https://api.thingspeak.com/update
Method:POST
Body:
api_key=THINGSPEAK_WRITE_KEY&field1=TimeControl%20test&status=Executed at %%time%%.
创建时间控件
为 TimeControl 命名并输入以下参数:
选中 One Time 复选框。
选择当前日期。
选择不久的将来的一个小时和分钟。
选择 ThingHTTP 作为您的操作。
在 then perform ThingHTTP 字段中,选择您创建的 ThingHTTP 以触发此 TimeControl。
保存时间控件。
在指定的小时和分钟,验证您的通道是否自动更新。
具有 MATLAB 分析代码错误的 TimeControl App
触发 MATLAB 的 TimeControls 有错误的分析代码在触发多个连续错误后停止运行。您可以通过选中 MATLAB 分析 App 中的框 Notify me via email if this MATLAB Analysis fails when triggered by TimeControl or React 来选择通过电子邮件接收警报。