<file_sep>import React, {useState, useEffect} from 'react';

import base64 from 'react-native-base64';

import {
  Container,
  TitleSlider,
  Slider,
  Variaveis,
  ValueSliderText,
  Picker,
  UploadButton,
  UploadButtonText,
  ScrollView,
  Cultivo,
  CultivoRow,
  ContainerButons,
  IconStyled,
  TextInput,
} from './styles';

function Home({navigation}) {
  const [temperatura, setTemperatura] = useState(0);
  const [umidadeAr, setUmidadeAr] = useState(0);
  const [umidadeSolo, setUmidadeSolo] = useState(0);
  const [temperaturaText, setTemperaturaText] = useState('');
  const [umidadeArText, setUmidadeArText] = useState('');
  const [umidadeSoloText, setUmidadeSoloText] = useState('');
  const [cultivo, setCultivo] = useState('166585');
  const [characteristic] = useState(navigation.getParam('characteristic'));
  const [periodo, setPeriodo] = useState('60');

  useEffect(() => {
    const [temp, humAr, humSolo] = [
      parseInt(cultivo.slice(0, 2), 10),
      parseInt(cultivo.slice(2, 4), 10),
      parseInt(cultivo.slice(4, 6), 10),
    ];
    console.tron.log(navigation);

    setTemperatura(temp);
    setUmidadeAr(humAr);
    setUmidadeSolo(humSolo);
    setTemperaturaText(temp);
    setUmidadeArText(humAr);
    setUmidadeSoloText(humSolo);
  }, [cultivo, navigation]);

  const upload = async () => {
    const response =
      temperatura +
      ',' +
      umidadeAr +
      ',' +
      umidadeSolo +
      ',' +
      (periodo.toString() * 60 * 1000).toString();
    const res = await characteristic.writeWithoutResponse(
      base64.encode(response),
    );
    console.tron.log(res);
  };

  const handleNavigateRealTime = () => {
    navigation.navigate('RealTime', {characteristic: characteristic});
  };

  const handleNavigateBD = () => {
    navigation.navigate('Graph');
  };

  return (
    <ScrollView>
      <Container>
        <Cultivo>
          <CultivoRow>
            <TitleSlider>Cultivo</TitleSlider>
            <Picker
              selectedValue={cultivo}
              onValueChange={val => setCultivo(val)}>
              <Picker.Item label="Custom" value="505050" />
              <Picker.Item label="Alcaçuz" value="166585" />
              <Picker.Item label="Alface" value="168070" />
              <Picker.Item label="Alfazema" value="206570" />
              <Picker.Item label="Babosa" value="266060" />
              <Picker.Item label="Boldo-do-chile" value="246080" />
              <Picker.Item label="Calêndula" value="106055" />
              <Picker.Item label="Hortelã" value="187045" />
              <Picker.Item label="Malva" value="326050" />
            </Picker>
          </CultivoRow>
          <CultivoRow>
            <TitleSlider>Intervalo Coleta dados</TitleSlider>
            <CultivoRow>
              <TextInput
                keyboardType="number-pad"
                value={periodo}
                onChangeText={value => setPeriodo(value)}
              />
              <TitleSlider>minutos</TitleSlider>
            </CultivoRow>
          </CultivoRow>
        </Cultivo>
        <Variaveis>
          <TitleSlider>Temperatura</TitleSlider>
          <Slider
            value={temperatura}
            step={1}
            minimumValue={0}
            maximumValue={100}
            minimumTrackTintColor="#35b7fc"
            maximumTrackTintColor="#fc6860"
            thumbTintColor="#00ba09"
            onValueChange={val => setTemperaturaText(val)}
            onSlidingComplete={val => setTemperatura(val)}
          />
          <ValueSliderText>{`${temperaturaText}°C`}</ValueSliderText>
        </Variaveis>
        <Variaveis>
          <TitleSlider>Umidade do Ar</TitleSlider>
          <Slider
            value={umidadeAr}
            step={1}
            minimumValue={0}
            maximumValue={100}
            minimumTrackTintColor="#35b7fc"
            maximumTrackTintColor="#fc6860"
            thumbTintColor="#00ba09"
            onValueChange={val => setUmidadeArText(val)}
            onSlidingComplete={val => setUmidadeAr(val)}
          />
          <ValueSliderText>{`${umidadeArText}%`}</ValueSliderText>
        </Variaveis>
        <Variaveis>
          <TitleSlider>Umidade do Solo</TitleSlider>
          <Slider
            value={umidadeSolo}
            step={1}
            minimumValue={0}
            maximumValue={100}
            minimumTrackTintColor="#35b7fc"
            maximumTrackTintColor="#fc6860"
            thumbTintColor="#00ba09"
            onValueChange={val => setUmidadeSoloText(val)}
            onSlidingComplete={val => setUmidadeSolo(val)}
          />
          <ValueSliderText>{`${umidadeSoloText}%`}</ValueSliderText>
        </Variaveis>
        <ContainerButons>
          <ScrollView horizontal>
            <UploadButton onPress={() => upload()}>
              <UploadButtonText>Upload</UploadButtonText>
              <IconStyled name="cached" size={30} color="#FFF" />
            </UploadButton>
            <UploadButton onPress={() => handleNavigateRealTime()}>
              <UploadButtonText>Real Time</UploadButtonText>
              <IconStyled name="timeline" size={30} color="#FFF" />
            </UploadButton>
            <UploadButton onPress={() => handleNavigateBD()}>
              <UploadButtonText>Grafico</UploadButtonText>
              <IconStyled name="save" size={20} color="#FFF" />
            </UploadButton>
          </ScrollView>
        </ContainerButons>
      </Container>
    </ScrollView>
  );
}

Home.navigationOptions = props => ({
  title: props.navigation.getParam('device'),
});

export default Home;
<file_sep># greenhouse-system
A project to manager greenhouse with comunication between Arduino and React-native using Green House System with hm-10

<a>https://www.linkedin.com/pulse/sistema-de-automo%C3%A7%C3%A3o-estufa-com-react-native-josef-stein-butzke/</a>

<h1>App Mobile</h1>
<div>
  <img src="https://github.com/JosefButzke/greenhouse-system/blob/master/greenhouse-manager-ble-react-native/IMAGES/8.gif" width="250" alt=""/>
</div>

<h1>Screen Connection</h1>
<div>
  <img src="https://github.com/JosefButzke/greenhouse-system/blob/master/greenhouse-manager-ble-react-native/IMAGES/1.jpg" width="250" alt=""/>
</div>

<h1>Screen Connection Device Found</h1>
<div>
  <img src="https://github.com/JosefButzke/greenhouse-system/blob/master/greenhouse-manager-ble-react-native/IMAGES/2.jpg" width="250" alt=""/>
</div>

<h1>Screen Home</h1>
<div>
  <img src="https://github.com/JosefButzke/greenhouse-system/blob/master/greenhouse-manager-ble-react-native/IMAGES/3.jpg" width="250" alt=""/>
</div>

<h1>Screen Home Select Open</h1>
<div>
  <img src="https://github.com/JosefButzke/greenhouse-system/blob/master/greenhouse-manager-ble-react-native/IMAGES/4.jpg" width="250" alt=""/>
</div>

<h1>Screen Real Time</h1>
<div>
  <img src="https://github.com/JosefButzke/greenhouse-system/blob/master/greenhouse-manager-ble-react-native/IMAGES/5.jpg" width="250" alt=""/>
</div>

<h1>Screen Graphs</h1>
<div>
  <img src="https://github.com/JosefButzke/greenhouse-system/blob/master/greenhouse-manager-ble-react-native/IMAGES/6.jpg" width="250" alt=""/>
</div>

<h1>Screen Graphs Scrolling Right</h1>
<div>
  <img src="https://github.com/JosefButzke/greenhouse-system/blob/master/greenhouse-manager-ble-react-native/IMAGES/7.jpg" width="250" alt=""/>
</div>
<file_sep>import styled from 'styled-components/native';
import {RectButton} from 'react-native-gesture-handler';
import Icon from 'react-native-vector-icons/MaterialIcons';

export const Container = styled.View`
  flex: 1;
  padding: 15px;
`;

export const Cultivo = styled.View`
  flex-direction: column;
  flex: 1;
  background: #eee;
`;

export const CultivoRow = styled.View`
  justify-content: space-between;
  flex-direction: row;
`;

export const Variaveis = styled.View`
  flex-direction: column;
  align-items: center;
  background: #eee;
  padding: 10px;
  margin-top: 10px;
`;

export const TitleSlider = styled.Text`
  font-size: 16px;
  color: black;
  padding: 10px;
  background: #eee;
`;

export const Slider = styled.Slider`
  width: 100%;
  height: auto;
`;

export const ValueSliderText = styled.Text`
  font-size: 16px;
  color: black;
`;

export const Picker = styled.Picker`
  width: 50%;
  color: #747474;
`;

export const UploadButton = styled(RectButton)`
  flex-direction: row;
  flex: 1;
  margin: 10px;
  margin-top: 30px;
  margin-bottom: 20px;
  border-radius: 4px;
  background: green;
  justify-content: space-around;
  align-items: center;
  align-self: center;
  height: 44px;
`;

export const UploadButtonText = styled.Text`
  font-size: 20px;
  color: white;
  padding: 5px;
`;

export const ScrollView = styled.ScrollView``;

export const AddButton = styled(RectButton)`
  flex-direction: row;
  width: 44px;
  height: 44px;
  border-radius: 4px;
  background: green;
  justify-content: space-around;
  align-items: center;
  align-self: center;
`;

export const TextInput = styled.TextInput`
  height: 40;
  width: 60;
  margin-bottom: 10px;
  border-radius: 4px;
  background: white;
`;

export const ContainerButons = styled.View`
  flex-direction: row;
`;

export const IconStyled = styled(Icon)`
  padding: 5px;
`;
<file_sep>import styled from 'styled-components/native';

import {RectButton} from 'react-native-gesture-handler';
import Icon from 'react-native-vector-icons/AntDesign';

export const Container = styled.View`
  flex: 1;
  padding: 5px;
`;

export const Ativador = styled.View`
  flex-direction: row;
  justify-content: space-around;
  background: white;
  padding: 15px;
`;

export const TitleSwitch = styled.Text`
  font-size: 24px;
  color: black;
`;

export const TitleList = styled.Text`
  align-self: center;
  padding-bottom: 10px;
  font-weight: bold;
  padding: 10px;
`;

export const Line = styled.View`
  background: red;
  border-bottom-width: 1;
  border-color: #e3e3e3;
`;

export const List = styled.FlatList``;

export const DeviceButton = styled(RectButton)`
  flex-direction: row;
  width: 40%;
  margin-top: 30px;
  border-radius: 4px;
  background: #00ba09;
  justify-content: space-around;
  align-items: center;
  align-self: center;
  height: 44px;
`;

export const DeviceButtonText = styled.Text`
  color: white;
`;

export const DeviceButtonSync = styled(RectButton)`
  width: 80px;
  height: 40px;
  border-radius: 4px;
  background: #15d146;
  align-items: center;
  justify-content: center;
`;

export const IconSync = styled(Icon)`
  color: white;
`;
<file_sep>const ChartConfig = {
  backgroundGradientFrom: '#1da334',
  backgroundGradientFromOpacity: 1,
  backgroundGradientTo: '#1da334',
  backgroundGradientToOpacity: 1,
  color: () => 'white',
  strokeWidth: 1,
};

export default ChartConfig;
<file_sep>import styled from 'styled-components/native';

export const Container = styled.View`
  display: flex;
  flex: 1;
  align-items: center;
  background-color: #1da334;
`;

export const ContainerLoading = styled.View`
  flex: 1;
  justify-content: center;
`;

export const Title = styled.Text`
  padding: 20px;
  font-size: 24px;
  color: white;
`;

export const Legend = styled.View`
  flex-direction: row;
  background-color: #eee;
  padding: 5px;
  margin: 30px;
  align-items: center;
  border-radius: 4px;
`;

export const LegendItem = styled.View`
  width: 10px;
  height: 10px;
  border-radius: 4px;
  background-color: ${props => props.inputColor};
`;

export const TitleLegend = styled.Text`
  padding: 10px;
  font-size: 10px;
`;

export const TitleNo = styled.Text`
  padding: 10px;
  font-size: 18px;
  color: #eee;
`;

export const Button = styled.Button`
  width: 10px;
  height: 20px;
`;
<file_sep># greenhouse-manager-ble-react-native

<div>
<h3>#Screen Connection with BLE</h3>
<img src="https://github.com/JosefButzke/greenhouse-manager-ble-react-native/blob/master/IMAGES/1.jpg" width="250"  />
</div>

<div>
<h3>#BLE found</h3>
<img src="https://github.com/JosefButzke/greenhouse-manager-ble-react-native/blob/master/IMAGES/2.jpg" width="250"  />
</div>

<div>
<h3>#Home</h3>
<img src="https://github.com/JosefButzke/greenhouse-manager-ble-react-native/blob/master/IMAGES/3.jpg" width="250"  />
</div>

<div>
<h3>#Home Select Open</h3>
<img src="https://github.com/JosefButzke/greenhouse-manager-ble-react-native/blob/master/IMAGES/4.jpg" width="250"  />
</div>

<div>
<h3>#Real Time Variables</h3>
<img src="https://github.com/JosefButzke/greenhouse-manager-ble-react-native/blob/master/IMAGES/5.jpg" width="250"  />
</div>

<div>
<h3>#Arduino with sensors and Relé</h3>
<img src="https://github.com/JosefButzke/greenhouse-manager-ble-react-native/blob/master/IMAGES/parteEletrica.jpg" width="500"  />
</div>

<div>
<h3>#Physical greenhouse to tests</h3>
<img src="https://github.com/JosefButzke/greenhouse-manager-ble-react-native/blob/master/IMAGES/protoEstufa.jpg" width="500"  />
</div>
<file_sep>import {createAppContainer} from 'react-navigation';
import {createStackNavigator} from 'react-navigation-stack';

import Conexao from './pages/Conexao';
import Home from './pages/Home';
import Graph from './pages/Graph';
import RealTime from './pages/RealTime';
import Dashboard from './pages/Dashboard';

const Routes = createAppContainer(
  createStackNavigator(
    {Conexao, Home, Graph, RealTime, Dashboard},
    {
      headerLayoutPreset: 'center',
      headerBackTitleVisible: false,
      defaultNavigationOptions: {
        headerStyle: {
          backgroundColor: 'green',
        },
        headerTintColor: '#FFF',
      },
    },
  ),
);

export default Routes;
<file_sep>import styled from 'styled-components/native';
import {TextInput} from 'react-native';
import {RectButton} from 'react-native-gesture-handler';

export const Container = styled.View`
  flex: 1;
  padding: 20px;
`;

export const UploadButton = styled(RectButton)`
  flex-direction: row;
  width: 140px;
  margin-top: 30px;
  margin-bottom: 20px;
  border-radius: 4px;
  background: green;
  justify-content: space-around;
  align-items: center;
  align-self: center;
  height: 44px;
`;

export const UploadButtonText = styled.Text`
  font-size: 20px;
  color: white;
  padding: 5px;
`;

export const InputText = styled(TextInput)`
  padding: 30px 10px;
  height: 10px;
  background: #eee;
`;

export const ResulText = styled.Text`
  color: #fff;
  font-weight: bold;
  background: #ddd;
  margin-top: 10px;
  font-size: 12px;
`;

export const List = styled.FlatList``;
<file_sep>#include <SoftwareSerial.h>
#include <DHT.h>
#include <Ultrasonic.h>
SoftwareSerial BTserial(2, 3); // RX | TX
// Connect the HC-05 TX to Arduino pin 2 RX.
// Connect the HC-05 RX to Arduino pin 3 TX through a voltage divider.

#define DHTPIN A0   // pino temp e hum
#define pinoSolo A1 // pino higrometro

#define DHTTYPE DHT22 // sensor DHT 22
DHT dht(DHTPIN, DHTTYPE);

#define pino_trigger 8
#define pino_echo 9
Ultrasonic ultrasonic(pino_trigger, pino_echo); // sensor ultrasonico

//DHT22 variaveis para envio ble
float temperatura;
float humidadeAr;

//LM393 valor captado
int humidadeSoloRaw;

//rele
int porta_rele_IN2 = 5;
int porta_rele_IN3 = 6;

//variaveis internas
String temperaturaSet = "25";
String humidadeArSet = "60";
String humidadeSoloSet = "60";

unsigned long period = 3600000; //intervalo de cada coleta de dados - 1hora
unsigned long time = 0;         // inicia tempo para calcular intervalo de 1 hora

void setup()
{
  pinMode(porta_rele_IN2, OUTPUT);    //rele
  digitalWrite(porta_rele_IN2, HIGH); //inicia desligado
  pinMode(porta_rele_IN3, OUTPUT);    //ventuinha

  Serial.begin(9600);
  Serial.println("Arduino is ready");

  //attachInterrupt(digitalPinToInterrupt(3), updateVariables, RISING);

  BTserial.begin(9600);
  dht.begin();
}

void loop()
{
  float hum = dht.readHumidity();
  float temp = dht.readTemperature();
  humidadeSoloRaw = analogRead(pinoSolo);
  int humidadeSolo = map(humidadeSoloRaw, 0, 1023, 100, 0);

  if (millis() > time + period)
  {
    float altura;
    long microsec = ultrasonic.timing();
    altura = ultrasonic.convert(microsec, Ultrasonic::CM);

    String response = String(temp) + ',' + String(hum) + ',' + String(humidadeSolo) + ',' + String(altura);

    if (altura > 4.0 && altura < 100.0)
      BTserial.print(response);
    time = millis();
  }

  if (humidadeSolo < humidadeSoloSet.toInt())
  {
    digitalWrite(porta_rele_IN2, LOW);
  }
  else
  {
    digitalWrite(porta_rele_IN2, HIGH);
  }

  if (temp > temperaturaSet.toFloat())
  {
    digitalWrite(porta_rele_IN3, LOW);
  }
  else
  {
    digitalWrite(porta_rele_IN3, HIGH);
  }

  if (BTserial.available())
  {
    String in = BTserial.readString();

    temperaturaSet = "";
    humidadeArSet = "";
    humidadeSoloSet = "";

    String per = "";

    temperaturaSet = temperaturaSet + char(in[0]) + char(in[1]);
    humidadeArSet = humidadeArSet + char(in[3]) + char(in[4]);
    humidadeSoloSet = humidadeSoloSet + char(in[6]) + char(in[7]);

    for (int i = 9; i < in.length(); i++)
    {
      per = per + char(in[i]);
    }

    period = atol(per.c_str());
    Serial.println(per);
  }
}
<file_sep>import React, {Component} from 'react';

import {
  Container,
  UploadButton,
  UploadButtonText,
  ResulText,
  List,
} from './styles';

import Database from '../../database/database';

const db = new Database();

export default class Dashboard extends Component {
  static navigationOptions = () => ({
    title: 'Dashboard',
  });

  state = {result: []};

  handleIndex = async () => {
    const response = await db.index();
    for (let i = 0; i < response.rows.length; ++i) {
      console.tron.log(response.rows.item(i));
      this.setState({result: [...this.state.result, response.rows.item(i)]});
      console.tron.log(this.state.result);
    }
  };

  handleStore = async () => {
    const response = await db.store(28.2, 70, 80, new Date().toISOString());
    this.setState({result: []});
    console.tron.log(response);
    // db.closeDatabase();
  };

  handleDeleteTable = async () => {
    const response = await db.deleteDataOfTable();
    this.setState({result: []});
    console.tron.log(response);
    // db.closeDatabase();
  };

  render() {
    const {result} = this.state;
    return (
      <Container>
        <UploadButton onPress={() => this.handleIndex()}>
          <UploadButtonText>Index</UploadButtonText>
        </UploadButton>
        <UploadButton onPress={() => this.handleStore()}>
          <UploadButtonText>Store</UploadButtonText>
        </UploadButton>
        <UploadButton onPress={() => this.handleDeleteTable()}>
          <UploadButtonText>Delete Table</UploadButtonText>
        </UploadButton>

        <List
          data={result}
          keyExtractor={device => String(device.id)}
          renderItem={({item}) => (
            <ResulText>
              {`${item.id} - ${item.date},${item.temperatura}°C, ${
                item.umidade_ar
              }%, ${item.umidade_solo}%`}
            </ResulText>
          )}
        />
      </Container>
    );
  }
}
<file_sep>import React, {useState, useEffect} from 'react';

import {LineChart} from 'react-native-chart-kit';

import {
  ScrollView,
  ToastAndroid,
  ActivityIndicator,
  Dimensions,
} from 'react-native';

import {
  Container,
  ContainerLoading,
  Legend,
  LegendItem,
  TitleLegend,
  TitleNo,
} from './styles';

import Database from '../../database/database';

const db = new Database();

import ChartConfig from '../../Config/ChartConfig';

export default function Graph() {
  const screenWidth = Dimensions.get('window').height;

  const [data, setData] = useState({
    labels: [''],
    datasets: [],
  });

  const [widthGraph, setWidthGraph] = useState(300);
  const [loading, setLoading] = useState(true);

  useEffect(() => {
    const loadData = async () => {
      const response = await db.index();
      var x = [];
      var y1 = [];
      var y2 = [];
      var y3 = [];
      var y4 = [];

      for (let i = 0; i < response.rows.length; ++i) {
        const item = response.rows.item(i);
        x.push(
          `${new Date(item.date).toLocaleDateString()} - ${new Date(
            item.date,
          ).toLocaleTimeString()}`,
        );
        y1.push(item.temperatura);
        y2.push(item.umidade_solo);
        y3.push(item.umidade_ar);
        y4.push(Math.abs(16 - item.altura));
      }

      setWidthGraph(response.rows.length * 50);
      setLoading(false);
      response.rows.length &&
        setData({
          labels: x,
          datasets: [
            {
              data: y1,
              color: (opacity = 1) => '#de371d',
            },
            {
              data: y2,
              color: (opacity = 1) => 'brown',
            },
            {
              data: y3,
              color: (opacity = 1) => '#20d0e3',
            },
            {
              data: y4,
              color: (opacity = 1) => 'orange',
            },
          ],
        });
    };
    loadData();
  }, []);

  return (
    <Container>
      {!loading ? (
        data.datasets.length > 0 ? (
          <>
            <Legend>
              <LegendItem inputColor="#20d0e3" />
              <TitleLegend>Umidade Ar</TitleLegend>
              <LegendItem inputColor="brown" />
              <TitleLegend>Umidade Solo</TitleLegend>
              <LegendItem inputColor="#de371d" />
              <TitleLegend>Temperatura</TitleLegend>
              <LegendItem inputColor="orange" />
              <TitleLegend>Altura</TitleLegend>
            </Legend>
            <ScrollView horizontal={true}>
              <LineChart
                withShadow={false}
                fromZero={true}
                data={data}
                verticalLabelRotation={25}
                height={screenWidth - 210}
                width={widthGraph}
                chartConfig={ChartConfig}
                bezier
                onDataPointClick={value => {
                  ToastAndroid.show(String(value.value), ToastAndroid.SHORT);
                }}
              />
            </ScrollView>
          </>
        ) : (
          <ContainerLoading>
            <TitleNo>Não existem dados</TitleNo>
          </ContainerLoading>
        )
      ) : (
        <ContainerLoading>
          <ActivityIndicator size={50} color="#00ff00" />
        </ContainerLoading>
      )}
    </Container>
  );
}

Graph.navigationOptions = () => ({
  title: 'Graph',
});
<file_sep>import SQLite from 'react-native-sqlite-storage';
SQLite.DEBUG(true);
SQLite.enablePromise(true);

export default class Database {
  initDB() {
    return SQLite.openDatabase({
      name: 'database',
      createFromLocation: '~/www/Database.db',
    });
  }

  index() {
    return new Promise(resolve => {
      this.initDB().then(db => {
        db.transaction(tx => {
          tx.executeSql(
            'SELECT * FROM variaveis ORDER by date DESC LIMIT 50',
            [],
            function(tx, results) {
              resolve(results);
            },
          );
        }).then(results => this.closeDatabase(db));
      });
    });
  }

  store(temperatura, umidade_ar, umidade_solo, altura) {
    return new Promise(resolve => {
      this.initDB().then(db => {
        db.transaction(tx => {
          tx.executeSql(
            'INSERT INTO variaveis(temperatura, umidade_ar, umidade_solo, altura, date) VALUES(?,?,?,?,?)',
            [
              temperatura,
              umidade_ar,
              umidade_solo,
              altura,
              new Date().toISOString(),
            ],
            function(tx, results) {
              resolve(results);
            },
          );
        }).then(results => this.closeDatabase(db));
      });
    });
  }

  deleteDataOfTable() {
    return new Promise(resolve => {
      this.initDB().then(db => {
        db.transaction(tx => {
          tx.executeSql('DELETE FROM variaveis', [], function(tx, results) {
            resolve(results);
          });
        }).then(results => this.closeDatabase(db));
      });
    });
  }

  closeDatabase(db) {
    if (db) {
      console.tron.log('Closing DB');
      db.close()
        .then(status => {
          console.tron.log('Database CLOSED');
        })
        .catch(error => {
          this.errorCB(error);
        });
    } else {
      console.tron.log('Database was not OPENED');
    }
  }
}
