How to use a MQTT library for Arduino to send streams to Carriots

0. Introduction

This easy tutorial familiarizes you with an Arduino MQTT library.
Using this library you can send a JSON to Carriots by simply calling a predetermined method
In this tutorial you will learn how to:

  • Structure the data you want to send to be compatible with the Carriots API
  • Send the data to Carriots using the publish method



  • 1 x Arduino Uno
  • 1 x Ethernet Shield. You can also use a WiFi or GRPS Shield

Music to listen: Fraggle Rock Opening

1. Carriots Project and Device Registration


If youre 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.


2. How to use libraries in Arduino

Arduino libraries allow the sketches to have extra funcionality. Arduino has many libraries that are already established and come with the IDE. However, it's also possible to write your own libraries or use libraries written by others. Each library has a header file which describes each method and a source file, which elaborates the code. To read more about Arduino libraries or writing a library see Arduino-Libraries.

In this tutorial we will use a MQTT library to send streams to Carriots.

To use the library, first download it here. Once you have downloaded the library you must decompress it and then copy it into the arduino/libraries file. Now you should be able to use the library in any sketch you create.


3. Code implemented on Arduino to test the library

The method used to connect to Carriots MQTT is the method "connect". It has 3 parameters that you need to define in order to send a stream correctly.
The first parameter is your USAERNAME.
The second parameter is the APIKEY.
The thid parameter is the password, NONE for Carriots MQTT. (It's mandatory, can not be left empty)

The method used to publish streams to Carriots MQTT is the method "publish". It has 2 parameters that you need to define in order to send a stream correctly.
The first parameter is the toppic, it consists of your apikey/MODE (Mode can be "streams" or "status")
The second parameter is the stream itself.
This is the Arduino code to test the publish method. Note that some values should be replaced by your own values.

In this tutorial we check for the connection status each "loop" and start a connection loop if conection went lost.
Once connection has been stablished we send the stream.


4. Checking Data is collected in Carriots

If you get here, your device must be sending streams to Carriots

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


5. From here on: Enhancing the project

Now you know how to use the an Arduino device to send data to Carriots with MQTT. But you can enhance this project in many ways:

  • Try to send dynamic data using the MQTT library