# Lab 2 part A
In this lab you will experiment about how MQTT can be used to send data to a cloud based platform. This procedure allows you to store your data in a cloud based repository and to analyze your data with software tools made available by the used platform.
For these experiments we will use the [Ubidots](https://ubidots.com/) plaftorm.
## Using Ubidots
You will have to first create your free account in the Ubidots platform here: https://app.ubidots.com/accounts/signup/
Then you have to add a **Device**:

and then create a "Default" type variable:

You'll get something like this:

Now we will send data to our device using MQTT. Take a look first to the Ubidots MQTT API Reference: https://ubidots.com/docs/api/mqtt.html
## First step: sending data using `MQTTlens`
We will first use `MQTTlens` to send data to the ``variable`` of our Ubidots ``device``:
The name of the broker for educational users is "things.ubidots.com". To interact with it, you will need a TOKEN. The easiest way to get yours is clicking on “API Credentials” under your profile tab:

In my case I have:

To connect to the MQTT broker you'll have to use your ``Default Token`` as the MQTT username, and put ``None`` in the password field.

The **topic** you have to use is **`/v1.6/devices/{LABEL_DEVICE}/{LABEL_VARIABLE}`** where you have to replace the fields `{LABEL_DEVICE}` (e.g., kic-test-device) and `{LABEL_VARIABLE}` (e.g., data-val).
> be careful that the `{LABEL_DEVICE}` and `{LABEL_VARIABLE}` are those indicated as ``API label``. For example: 
The data must be represented using JSON. The simplest format is: `{"value":10}`
> the string ``value`` is fixed and defined by the Ubidots API
So, summing up, to send value 25 to variable `data-val` of device ``kic-test-device`` the topic must be:
```
/v1.6/devices/kic-test-device/data-val
```
and the message:
```
{"value":25}
````

You'll get:

So try to repeat all the previous steps with your own device and variable.