# Influxdb configuration

This section will display a brief description of how influxdb was configured in terms of database (Buckets) and task creation.

## Buckets

The main idea is to have two types of Buckets (i.e. data containers), one that records all temporal data in real time and one that records historical data

* **Temporal Bucket**: In this project was created a temporal bucket denominated **TAU_1YEAR_TEST**; this bucket records all the real time data with an accuracy of 3 seconds. The bucket is considered temporal because it has a retention policy of one year, which means that delete data over a period of more than one year.

* **Historical Bucket**: In order not to lose the data, influxdb offers the possibility to periodically send data from the time Bucket to the historical one, in this case without retention policy and with an accuracy of 1 hour.

### Bucket configuration

1. **Create Bucket**: Data/Buckets/Create Bucket

![Create Bucket](../img/influx_1.png)

2. **TAU_1YEAR_TEST**: Define name / delete data older than 1 year / create

![TAU_1YEAR](../img/influx_2.png)

3. **TAU_HIST_TEST**: Define name / delete data never / create

![TAU_HIST](../img/influx_3.png)

### Data reception from NodeRed

The communication between NodeRed and Influxdb is achieved through the interaction of the VM server with the raspberry pi.

**On the influxdb side** it is necessary to know:

1. **Organization**: organization/ about/ copy organization ID

![org](../img/influx_6.png)

2. **Bucket name**: Data/ Bucket / copy buckets name

![B_name](../img/influx_7.png)

3. **API token**: In this case is the admin token that has read/write authorization over buckets 

Data/ API Tokens / select dt_admin's token

![token](../img/influx_8.png)

**On the nodered side:**

In the nodered flows it is necessary to set up the influxdb blocks assigning organization, token, bucket, measure name and influxdb server.

1. Set organization, Bucket and measure name

![node_red1](../img/nodered_1.png)

2. Set server and token

![node_red2](../img/nodered_2.png)


## Tasks

An InfluxDB task is a scheduled Flux script that takes a stream of input data, modifies or analyzes it in some way, then writes the modified data back to InfluxDB.

In this case tasks are used to do the downsampling method and transfer data from real time bucket into historical one.

The flux codes are into:

* [Flux tasks](/Influxdb/Tasks/).

This codes have the functionality to send every hour the mean, max and min data of every power measure of M1 and M2 and save them into **TAU_HIST_TEST**
