How to connect a Raspberry Pi to Carriots Alert System for controlling access to your home or office.

0. Introduction

This easy tutorial helps you to build an Alert System for access your home or office.
To do this, we use a Raspberry Pi able to detect an RFID card.
In this project you will learn how to:

  • Connect a Raspberry Pi to Carriots to send data streams using Carriots HTTP REST API
  • Build an Alert App on Carriots by programming a Listener to send a SMS using the SDK



  • 1 x Raspberry Pi.
  • 1 x RFID MC522


1. Project Schema

This project is a quick way to create an alarm app and understand the basics of combining Raspberry Pi, RFID and Carriots.

Here is overall diagram of the project:

  • Schema

Raspbery Pi is programmed to send a data stream to Carriots stating the UID value at RFID.

All the data streams sent by Raspberry Pi are collected and stored in Carriots. Carriots is a huge database that collects all the information that your sensors send.

In addition to storing data, the true power of Carriots is to let you build Apps quickly with few lines of Groovy code. In this scenario we are going to build a very simple Alert App that sends an email to you approach a card to the RFID reader, stating whether id is correct or not.

With Carriots you can build very complex Apps to support all the logic of your product on the cloud and integrate it with other devices and IT systems. But for now let’s keep it simple.


2. Raspberry Pi and RFID. Connections description

The connections in Raspberry Pi with RFID are extremely simple. You can see in the diagram below.

  • Diagram
  • Real Display


3. Carriots Project and Device Registration


If you´re registered in Carriots, you have a default device already created for you.
Check your control panel and see what it looks like.
Basically you need the device id_developer that might be something like defaultDevice@myusername.
But if you want, you can create a new device and use it in this example.


Now, go to your control panel “My account menu” and check your Apikey.
Its a big alphanumeric token like:
You need this number to complete the example.


4. Data Transferred from Raspberry Pi to Carriots

From Raspberry Pi you have to build a HTTP request and send the data.

  • HTTP request
    POST /streams HTTP/1.1
    Accept: application/json
    User-Agent: RaspberryPi-Carriots
    Content-Type: application/json
    carriots.apikey: YOUR APIKEY HERE
    Connection: close
  • Data
    "data":{"uID":"YOUR DATA HERE"}


5. Code implemented on Raspberry Pi

This is the Pythons code to Raspberry Pi. Note that some values should be replaced by your own values.


6. Checking Data is collected in Carriots

If you get here, your device must be sending streams on approaching a card to the RFID reader.

Its time to test our control panel and check if we have new streams.
Go to “Data management” ? “Data streams” and you will see your data.

  • menu option
  • new data


7. Creating an Alert with Carriots Listeners

A listener in Carriots can be associated to any hierarchy entity, from Project to Device. If you associate a listener to a project, all devices below the services of that project will be affected. If you associate a listener to service, all devices below the groups of that services will be affected. And so on.

In this example, we create a listener associated with our device. This listener waits for an event to occur in the context of the device and then evaluate the content.

To create a listener go to the control panel, then to “Rules” → “Listeners” and click on the new button. Select "Device" as "entity type" and select your device on the "Id" field.

Fill the fields with the following values and save the new listener

  • Name: The name that you prefer
  • Description: The description that you prefer
  • Entity type: Device
  • Entity id: Your id device
  • Event to listen: data_persisted
  • If expression:"1102226035"
  • Then expression:
    import com.carriots.sdk.utils.Email;
    // Send an email to
    def email = new Email ();"YOUR EMAIL";
    email.subject="RFID OK";
    email.message="RFID card whose id is: " + + ", is correct";
  • Then rule: leave empty
  • Else expression:
    import com.carriots.sdk.utils.Email;
    // Send an email to
    def email = new Email ();"";
    email.subject="RFID Error";
    email.message="RFID card whose id is: " + + ", isn't correct";
  • Else rule: leave empty
  • Be sure to have your listener enabled if you want it to be executed

Its time to test our listener. Send a data stream to this device, check your control panel and your email!!!


8. From here on: Enhancing the project

Now you know how to connect a Raspberry Pi device to send data to Carriots and how to create a simple App with a single Listener and some SDK programing in Groovy. But you can enhance this project in many ways:

  • Try to add a motion sensor to the Raspberry Pi and send at least two values: RFID uID and motion status
  • Create your own control panel to check the status of the Raspberry Pi, by building an HTML page with a request to our API to ask for the status value of your device
  • Create another device that you can interact with (like a sound alarm) and build an app combining actions between the two devices through Carriots