diff --git a/platformio.ini b/platformio.ini index 02e9444..bf247d0 100644 --- a/platformio.ini +++ b/platformio.ini @@ -12,3 +12,8 @@ platform = espressif8266 board = esp07 framework = arduino + +lib_deps = + SPI + Wire + DHT sensor library \ No newline at end of file diff --git a/src/Temperature.cpp b/src/Temperature.cpp new file mode 100644 index 0000000..4146be8 --- /dev/null +++ b/src/Temperature.cpp @@ -0,0 +1,33 @@ +// +// Created by lukas on 22.08.20. +// + +#include "Temperature.h" + +void Temperature::init() { + dht.begin(); +} + +double Temperature::getTemp() { + sensors_event_t event; + dht.temperature().getEvent(&event); + if (isnan(event.temperature)) { + return -1; + } + else { + return event.temperature; + } +} + +double Temperature::getHum() { + sensors_event_t event; + dht.humidity().getEvent(&event); + if (isnan(event.relative_humidity)) { + return -1; + } + else { + + return event.relative_humidity; + + } +} diff --git a/src/Temperature.h b/src/Temperature.h new file mode 100644 index 0000000..dcc9cb0 --- /dev/null +++ b/src/Temperature.h @@ -0,0 +1,21 @@ +// +// Created by lukas on 22.08.20. +// + +#pragma once + +#include +#include +#include + +class Temperature { +public: + Temperature(): dht(4, DHT22){}; + + void init(); + double getTemp(); + double getHum(); + +private: + DHT_Unified dht; +}; diff --git a/src/main.cpp b/src/main.cpp index 3898a38..532b16c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,7 +4,7 @@ #include "WifiManager.h" -#define VERSION "v1.0" +#define VERSION "v1.1" bool allow; bool error = false;