Introducing Temboo Tokens

In this tutorial we introduce our Utilities > TokenStorage Choreos, which allow you to write commands, state information, or messages to a cloud-based key/value store. Since remote control is at the heart of a huge range of useful IoT applications, we're going to walk through using tokens to enable remote device control by providing a centralized datastore which devices can use to share information.

For a complete remote control solution, check out Cloud Controls.

We'll first show you how to store commands on Temboo, and then we'll show how you can read those commands back from your embedded hardware devices. Before you start, make sure that you have a Temboo account. If you don't have one yet, you can create one for free now.

Sending Commands

1Sending commands through Temboo, for your remote devices to read, is simple. First, go to the Utilities > TokenStorage > StoreToken Choreo.

2Next, enter a Name for your command token (e.g., "Light").

3Then, enter a Value for the default state of your token (e.g., "OFF").

4Run the Choreo, and your command will be stored on Temboo, ready for your devices to pick it up. All the code you need to store tokens, from the programming language of your choice, has also been automatically generated (scroll down to the CODE section of the Choreo page to check it out - more on that later).

Storing a token that represents the current state of a light controlled by an embedded device.

Reading commands from a device

5To read the value of a command token, go to the Utilities > TokenStorage > RetrieveToken Choreo.

6Enter the Name of your previously stored token (e.g., "Light"), and click Run.

You should see the value "OFF" in the Token output. This is the output that your device can read periodically to determine what state a pin should have. Now we'll look at how to read this value from an embedded device.

7At the top of the Choreo page you'll see the IoT Mode switch. If it's not on already, click to turn on IoT Mode. You'll see that a menu with hardware options has appeared.

8Select your board and how it's connected to the internet.

9Configure your output trigger so that if the Token output equals "ON", your device will write HIGH to a specified pin to turn on a light, motor, or other controller.

10Scroll down to the CODE section of the page and you'll see the automatically generated code that you need to read commands and alter a pin value on your board. If you need help getting started working with Temboo on an embedded device, you can find all of our tutorials here.

11To turn the light off when the Token output equals "OFF", you could adjust the code by adding else to the generated if statement. The code below is for Arduino/Texas Instruments boards, but you can use this approach for any Temboo-supported device.

  digitalWrite(outputPin, LOW);

12Now, save and upload the code to your board to begin retrieving your token value from the datastore. You can adjust the frequency with which you check for new commands based on the needs of your application.

What's Next?

Now that you can store and retrieve commands, you're ready to start controlling your devices remotely. You can return to the Utilities > TokenStorage > StoreToken Choreo that you tested earlier, and provide "ON" for the Value input. The next time your device reads the state of your stored token, the specified pin will be set HIGH.

To build out a real-world example, you could try running the StoreToken Choreo from our Android, iOS, or web framework SDKs. You could even build an attractive user interface to control your remote devices.

Now that you know how to use the TokenStorage Utility, you can build an endless range of IoT applications based around the concept of remote control.

Need help?

We're always happy to help. Just email us at support@temboo.com, and we'll answer your questions.