This setup will show you how to remotely control a digital load of a Raspberry PI using Tago. For this example, we will be using a LED as our ouput digital load.


Connect the LED through a 330Ω resistor to the Raspberry PI GPIO pin (connect to the pin number 18), the figure below shows how the electric connection is made.

Adding the Device

Log in your account, click on Devices (side bar), then click on ‘Add Device’ top right button. The Raspeberry PI board will be the device to be added, we will give it the name ‘dev01’. Therefore, enter with the name ‘dev01’ and click on ‘Save’. For each device, you have to define a bucket to store its data. You can let Tago to create a new bucket with the same name as the device. All devices should use a valid token when accessing Tago. This token is automatically generated when a new device is created. Go to the ‘General information’ section of the device, click on ‘QR Code’ or ‘Tokens’ and copy the token to be added into the Raspberry PI code later.

Building the Dashboard

Let’s build a simple dashboard with only one widget that will control the digital load (LED). Click Dashboards on the left side bar, then + top right, type the name of your dashboard, and click on Save. To add one widget, click on Add Widget or + top right button, and select the type: Input. Then Saveto get your widget.

Start the configuration of this widget by adding the title to be displayed. Type a variable name that will be sent to the device as switch_control, click on Select as new option below the name. Select your bucket [dev01], your device [dev01], select switch (true/false) and enter with a label to be showed close to the switch (i.e LED). Then, click on ‘Create’, and your widget is ready!

As soon as your device starts to send data, the most recent value will be showed on this display.

Creating Action

Now, let’s create an action to send data to our device every time we change the status of our switch. First, add an action to be executed:

In the field ‘Action to be taken’ select ‘Send data to device’, add a name to the action:

Now, let’s set the trigger condition. Under Trigger, enter with the variable that we created before switch_control, and Set Trigger condition to ‘Any’ - it means that any time a value for that variable arrives from the switch on the dashboard, the data will be sent to the Raspberry Pi board. As the system has no data for this variable yet, you will need to add it manually just to prepare it for visualization (it will not create a variable in the bucket). Type the name, select the variable. Then, select the bucket [dev01] and the device [dev01] for the variable.

We will not define a condition for ‘Reset Trigger’ because we want the action to trigger for every time a data arrives from the dashboard. You need to change the status of ‘Define Reset Trigger condition?’ to NO. Just save it now, and your action should look like this:

Your setup at Tago is ready! Now, you just need to code your Raspberry Pi to receive the data from Tago.

Sending data from the Raspberry

The code developed for this example was done in Python . But, you can also code in other languages, such as C, C# or Node.js. Using Raspbian distribution installed in the Raspberry PI, and Python 2.7, we wrote and tested the code below. You should have no problem with a different linux distribution or Python versions.

Before running the code, you will need to install Tago library for Python. In your terminal type the follow command: $ sudo pip install –U tago

If you don’t have pip installed, just install it by typing the following command in your terminal: $ sudo apt-get install python-pip

Python Code

Create a file .py with the code below. Make sure you replace the token with that one created for your device. When you use Tago’s lib, as you are doing now, you don’t need to go in details of the HTTP command. In this example, you are using the capability that pushes notifications to the Raspberry Pi device! With this capability you don’t need add a code to continuously request data from Tago (polling), instead the Raspberry Pi will be simply in the listening mode. That is a very fast and clean way of control devices remotely.

import RPi.GPIO as GPIO
from tago import Tago
my_device = Tago(MY_DEVICE_TOKEN).device

def func_callback_data(data):
Logic_Port = data['value']


As we know that you will want to apply this in your own application later, here goes some tips for your code:

1. import the Tago lib for Python. from tago import Tago2. replace MY_DEVICE_TOKEN with the token created for your deviceMY_DEVICE_TOKEN = ### INSER THE TOKEN FOR YOUR DEVICE HERE ###3. Use the ‘listening’ method to run the callback function generated by action4. If you have more than one action set, you may want to check which was the variable that arrived in the board before doing anything with it (filter)

Again, we have libs for several languages to simplify your code, check out ours SDKs and try other methods, like to send data from your board to Tago.

Running the application

Look at your dashboard at Tago, and run the code in your Raspberry PI. Go to your dashboard and turn your button ‘on’ the LED will turn on, now you can turn on and off a digital load across the planet using the power of Tago. If you have any issue or question about this application, access our Community . You can also try the modify the tutorial done for the BeagleBlackBone board to your Raspberry, by just by changing the GPIO library and the methods. Right, we know... you can do much more with the Raspberry and Tago! But at least, we hope you got the idea about how to set the ecosystem around Tago and your device. Take a look at the concepts , our API’s and SDK’s to bring the full potential of Tago to your system!