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
- Select the Apps tab and then under Actions TalkBack
- Click NewTalkBack
- 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.
- Select the Apps tab and then under Analytics Plugins
- Click New
- Select Custom and then Click Create
- Give the Plugin a name
- Paste the code below into the HTML edit box
- 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
- 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.
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.
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
- Select the Apps tab and then under Actions ThingHTTP
- Give it a name e.g. MyRequest
- Set URL: https://api.thingspeak.com
- Host: api.thingspeak.com
- Body: /talkbacks/TALKBACK_ID/commands.json?apikey=TALKBACK_APIKEY&command_string=TURN_ON&position=1
- You will need to edit this with your Talkback ID and API Key
- Click Save ThingHTTP
Now setup the React
- Select the Apps tab and then under Actions React
- Click New React
- Create a numeric react that fire a ThingHTTP event when the temperature is greater than 27 degrees
- 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