# Lab 5 - IoT - data to Telegram Bot
###### tags: `LAB`
:::info
**All the code necessary for this Lab session is available in [Poliformat/RSE: Recursos/Laboratorio/código practicas laboratorio](https://poliformat.upv.es/x/1J91ll)**, or here: https://bit.ly/codigoRSE2021
You can execute the code either in your computer or online:
In your computer:
* You need to have python3 installed, and
* `$ sudo pip3 install paho-mqtt`
Online:
* create an account in https://repl.it
* and create a new python file:

Click here for ["the documentation of the MQTT Paho API"](https://www.eclipse.org/paho/clients/python/docs/)
:::
In this Lab you'll have to do something similar to the previous one, but this time the data from the TTN have to be accessed using a Telegram bot. The final result should be somehting like this:

What you have to do first is create your own Bot. To generate an Access Token, you have to talk to the BotFather following a few simple steps as described here: https://core.telegram.org/bots#6-botfather
Basically, you need a Telegram account and the Telegram app installed in your smartphone or computer.
The "dialogue" will be something like this:

To program the Bot you can use, as a skeleton, the file `lab5.py`.
You can execute your Bot either in your computer or in repl.it and test it using a smartphone with Telegram.
This package is necessary to program the Bot:
```
https://github.com/python-telegram-bot/python-telegram-bot
```
If you are using your computer, than you'll have to install it using:
```
$ pip install python-telegram-bot
```
or, if you are using `repl.it`, you have to istall it from the Packages menu:

and typing in the search field `python-telegram-bot` and then on the **+** button
You should eventually get to something like this:

Fill in the places in `lab5.py` where the text `___FILL_IN_HERE___` is found with the proper values.
:::danger
1. Comprueba que el Bot funciona.
Recuerda que los parametros necesarios para leer datos desde TTN son:
```
Broker: eu1.cloud.thethings.network
Username: lopys2ttn@ttn
Password: NNSXS.A55Z2P4YCHH2RQ7ONQVXFCX2IPMPJQLXAPKQSWQ.A5AB4GALMW623GZMJEWNIVRQSMRMZF4CHDBTTEQYRAOFKBH35G2A
Topic: v3/+/devices/#
```
Entrega alguna captura de pantalla de su uso. Algo asi:

:::
:::danger
2. Modifica el Bot para que pueda devolver el valor de temperatura, humedad y luminosidad en función de la petición.
Tienes que obtener algo asi:

Entrega el fichero python.
:::