Sending Commands to Device

This page shows how we can use the ThingSpeak Talkback App to queue up commands that the “connected thing” or device, in this case the TI CC3200 can query.

The Talkback App acts as a mailbox that you can post commands to and pick them up.

Setting up the Talkback App

From your ThinkSpeak Dashboard

  1. Select the Apps tab and then under Actions TalkBack
  2. Click NewTalkBack
  3. Give it name and click Save

You can add a command from here a well with the Add a new command button. The command simply requires a string that your device interprets. e.g TURN_ON

Typically you would like to add the command from an external source such as an App to do this we use the Add TalkBack Command from the TalkBack API. The TalkBack API commands are visible in the RHS panel after you first create a TalkBack.

Creating a simple page with Buttons to add commands

We are going to use the Plugins App to create a Simple web page with buttons that add commands to the TalkBack App.

  1. Select the Apps tab and then under Analytics Plugins
  2. Click New
  3. Select Custom and then Click Create
  4. Give the Plugin a name
  5. Paste the code below into the HTML edit box
  6. You will need to edit the TalkBack ID and the API Key in the script function to match those display on your TalkBack. These can be found if you go to Apps>TalkBack and click Edit TalkBack then scroll down to and click Save TalkBack to see the TalkBack settings
  7. Click Save

To view the page you have created click on the plugins folder in the current location and you will be taken to a page that shows all your plugins. Click View on the plugin you just created to launch the page.


<!DOCTYPE html>
<html style="height: 100%;">
<head>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

<style type="text/css">
 body { background-color: white; }
</style>


 <script type="text/javascript">
 function lightOn(){
 $.post('https://api.thingspeak.com/talkbacks/TALKBACKID/commands.json?apikey=API_KEY&command_string=TURN_ON&position=1');
 }

</script>

</head>
<body>
<button onclick="lightOn()">Light On</button>
</body>
</html>

To add addition buttons and commands you simply need to provide additional functions in the Script section with the appropriate command_string.

E.g. duplicate the lightOn function and rename it lightOff() and update the command_string=TURN_OFF

Duplicate the <button onclick …> in the <body> tag and edit the function name to match your new function.

Device code

The Energia code that runs on the TI CC3200 for this example is available on GitHub

You will need to edit the following parameters in the code


// Wireless network parameters
char ssid[] = "XXXXXXXXX"; // Your wireless network name also called SSID
char password[] = "XXXXXXXX"; // Your wireless network password

// ThingSpeak parameters
char talkBackAPIKey[] = "XXXXXXXXXX"; // TalkBack API Key
char talkBackID[] = "XXXX"; // TalkBack ID

React to event

We are going to use the ThingSpeak React Action to get our system to automatically react to a condition and post a command.

First we need to create a ThinkHTTP to post the command

  1. Select the Apps tab and then under Actions ThingHTTP
  2. Give it a name e.g. MyRequest
  3. Set URL: https://api.thingspeak.com
  4. Host: api.thingspeak.com
  5. Body: /talkbacks/TALKBACK_ID/commands.json?apikey=TALKBACK_APIKEY&command_string=TURN_ON&position=1
  6. You will need to edit this with your Talkback ID and API Key
  7. Click Save ThingHTTP

Now setup the React

  1. Select the Apps tab and then under Actions React
  2. Click New React
  3. Create a numeric react that fire a ThingHTTP event when the temperature is greater than 27 degrees
  4. Select Your ThinkHTTP request e.g.MyRequest under the then perform ThingHTTP drop down

The system should now turn on the Red LED when the temperature exceeds 27 degrees