ThingSpeak

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

React App

React works with ThingHTTP, ThingTweet, and MATLAB® Analysis apps to perform actions when channel data meets a certain condition. For example, you can have a mobile app report your latitude and longitude to a ThingSpeak™ channel. When your position is within a certain distance of your house, have ThingHTTP turn on your living room lights.

    Note:   If you use the React app with the Test Frequency set to On Data Insertion when using Bulk-Update a Channel Feed, your React is triggered once per bulk-update request when Condition matches ConditionType, even if the Condition is matched more than once. Since the data is collected over a period of time and updated as a batch, it is possible that the Condition is not matched at the present but was matched sometime in the past.

    If you set your React to run on a specific Test Frequency with a specific Condition Type, be cautious of how your React may be triggered. The data is now collected over time and updated as a batch, and the Condition Type that triggers the React may vary within a single batch of data.

React App Introduction

The React app triggers MATLAB Analysis, ThingHTTP, or ThingTweet apps when your ThingSpeak channel meets a specified condition. For example, you can turn your thermostat on or off based on your location using a geo location condition in the React app.

Define Reactions to Channel Data

  1. Select Apps > React.

  2. Click Create New React.

  3. Select:

    • React Condition Type

    • Test Frequency

    • Action

    • Options

  4. Click Create React.

Condition Types

ThingSpeak channels support numeric sensor data, text, strings, status updates, and geo location information. Use these condition types to specify conditions that trigger reactions based on your channel data.

String

This condition tests a text string with ASCII characters in a ThingSpeak channel field. For example, "If Channel 1, Field 1, is equal to blue, then set my light to blue."

Check the data with these constraints when testing for strings:

  • contains

  • starts with

  • ends with

  • is equal to

  • is not equal to

Status

This condition tests a ThingSpeak status in a channel. The status field is similar to the text in a tweet. You can search the status for a word, and send a ThingHTTP request when the test condition is met.

Check the data with these constraints when testing for ThingSpeak channel status:

  • contains

  • starts with

  • ends with

  • is equal to

  • is not equal to

Numeric

If you have sensor data or numeric data in the fields of a ThingSpeak channel, use the numeric condition. For example, if your power use is over 300 watts, use a numeric condition to post this tweet using the ThingTweet app:

"I am using too much power"

Additionally, you can send a control command to another service or device that accepts HTTP requests using ThingHTTP.

Check the data with these constraints when testing for numbers in a ThingSpeak channel field:

  • is greater than

  • is greater than or equal to

  • is less than

  • is less than or equal to

  • is equal to

  • is not equal to

Geo Location

This condition checks the location data in a ThingSpeak channel. For example, if you have mobile app reporting your latitude and longitude to a ThingSpeak channel, you can turn on your living room lights when your position is within a certain distance of your house.

Check the data with these constraints when testing for location information on a ThingSpeak channel:

  • is within

  • is farther than

No Data Check

This condition checks whether the ThingSpeak channel is receiving data at the specified interval. If no data updates occur within the specified time range, the action selected in your React app is triggered. For example, if a power outage interrupts your device and your channel is not updating, you can trigger an action. Specify the amount of time that your channel does not receive new data before triggering the action.

Test Frequency

Select the frequency at which you can test for the specified condition.

  • On Data Insertion: Test each time data is inserted. You cannot have more than one React configured with On Data Insertion for the exact same conditions.

  • Every 10 minutes: Test every 10 minutes, on the clock. For example, a React created at 10:08 a.m. triggers at 10:10, and every 10 minutes after that.

  • Every 30 minutes: Test every 30 minutes, on the clock.

  • Every 60 minutes: Test every hour, on the clock.

Action

You can trigger a MATLAB Analysis, ThingHTTP, or send a Tweet using the ThingTweet app.

Replacements

  • If you specify %%trigger%% in your ThingHTTP body or ThingTweet message, %%trigger%% is replaced with the value that triggered your React action. For example, if your ThingTweet message is, It is way too hot in here at %%trigger%% C, the message becomes It is way too hot in here at 40 C, where 40 is the value that triggered the React app.

  • If you specify %%channel_id%% in your ThingHTTP body or ThingTweet message, %%channel_id%% is replaced with the channel id that triggered your React action. For example, if your ThingTweet message is, The channel that tweets is %%channel_id%% , the message becomes The channel that tweets is 12, when 12 is the channel id that triggered your React.

  • If you specify %%channel_CHANNEL_ID_field_FIELD_NUMBER%% in your ThingHTTP body or ThingTweet message, %%channel_CHANNEL_ID_field_FIELD_NUMBER%% is replaced by the last value of the specified channel and field. For example, if your ThingTweet message is, The latest value is %%channel_12_field_1%% , the message becomes The latest value is 2.5, when 2.5 is the last value of the field 1 of channel 12.

  • If you specify %%datetime%% in your ThingHTTP body or ThingTweet message, %%datetime%% is replaced with the actual date and time that the React was triggered. For example, if your ThingTweet message is, The date and time the event occurred is %%datetime%% , the message becomes The date and time the event occurred is 2014-09-24 5:32 p.m, when 2014-09-24 5:32 p.m is the date and time in your time zone that the React app was triggered.

Options

  • Run action only the first time the condition is met: Trigger the action if the condition was previously false and is currently true.

  • Run action each time condition is met: Trigger the action every time that the condition is true.

React App with MATLAB Analysis Code Errors

When you have MATLAB Analysis code that uses a React, React stops running if there are a number of consecutive errors in the MATLAB Analysis code. You can choose to receive an alert via email by checking the box Notify me via email if this MATLAB Analysis fails when triggered by TimeControl or React in the MATLAB Analysis app.

Was this topic helpful?