Compare commits
2 Commits
19e81885a9
...
da31e2d40a
| Author | SHA1 | Date | |
|---|---|---|---|
| da31e2d40a | |||
| 422378c0cb |
@ -3,7 +3,10 @@ data_dir = ${PROJECT_DIR}/data/${PIOENV}
|
|||||||
|
|
||||||
[common]
|
[common]
|
||||||
framework = arduino
|
framework = arduino
|
||||||
lib_deps = https://github.com/milesburton/Arduino-Temperature-Control-Library
|
lib_deps = SPI
|
||||||
|
https://github.com/adafruit/Adafruit_BusIO
|
||||||
|
https://github.com/milesburton/Arduino-Temperature-Control-Library
|
||||||
|
https://github.com/adafruit/DHT-sensor-library
|
||||||
https://github.com/adafruit/Adafruit_TSL2561
|
https://github.com/adafruit/Adafruit_TSL2561
|
||||||
https://github.com/knolleary/pubsubclient
|
https://github.com/knolleary/pubsubclient
|
||||||
https://github.com/adafruit/Adafruit_BME680
|
https://github.com/adafruit/Adafruit_BME680
|
||||||
@ -34,10 +37,10 @@ lib_deps = ${common.lib_deps}
|
|||||||
build_flags = ${common.build_flags} -DNODE_GREENHOUSE -DHOSTNAME=\"Greenhouse\"
|
build_flags = ${common.build_flags} -DNODE_GREENHOUSE -DHOSTNAME=\"Greenhouse\"
|
||||||
board_build.filesystem = ${common.board_build.filesystem}
|
board_build.filesystem = ${common.board_build.filesystem}
|
||||||
monitor_speed = ${common.monitor_speed}
|
monitor_speed = ${common.monitor_speed}
|
||||||
upload_protocol = ${common.upload_protocol}
|
;upload_protocol = ${common.upload_protocol}
|
||||||
upload_port = 10.0.0.160
|
;upload_port = 10.0.0.160
|
||||||
;upload_port = ${common.upload_port}
|
upload_port = ${common.upload_port}
|
||||||
;upload_speed = ${common.upload_speed}
|
upload_speed = ${common.upload_speed}
|
||||||
|
|
||||||
[env:Fermenter]
|
[env:Fermenter]
|
||||||
platform = ${esp12e.platform}
|
platform = ${esp12e.platform}
|
||||||
|
|||||||
@ -1,24 +1,19 @@
|
|||||||
#ifdef NODE_GREENHOUSE
|
#ifdef NODE_GREENHOUSE
|
||||||
|
|
||||||
#include "patrix/bme680.h"
|
|
||||||
#include "patrix/tsl2561.h"
|
#include "patrix/tsl2561.h"
|
||||||
|
#include "patrix/DHT22.h"
|
||||||
|
|
||||||
TSL2561 gardenTSL("garden");
|
TSL2561 greenhouseTSL("greenhouse");
|
||||||
|
|
||||||
BME680 gardenBME("garden");
|
DHT22Sensor greenhouseDHT22("greenhouse", D5);
|
||||||
|
|
||||||
BME680 greenhouseBME("greenhouse");
|
|
||||||
|
|
||||||
void patrixSetup() {
|
void patrixSetup() {
|
||||||
gardenTSL.setup();
|
greenhouseTSL.setup();
|
||||||
gardenBME.setup();
|
|
||||||
greenhouseBME.setup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void patrixLoop() {
|
void patrixLoop() {
|
||||||
gardenTSL.loop();
|
greenhouseTSL.loop();
|
||||||
gardenBME.loop();
|
greenhouseDHT22.loop();
|
||||||
greenhouseBME.loop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
72
src/patrix/DHT22.h
Normal file
72
src/patrix/DHT22.h
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
#ifndef DHT22_H
|
||||||
|
#define DHT22_H
|
||||||
|
|
||||||
|
#include "mqtt.h"
|
||||||
|
#include "DHT_U.h"
|
||||||
|
|
||||||
|
class DHT22Sensor {
|
||||||
|
|
||||||
|
int pin;
|
||||||
|
|
||||||
|
DHT_Unified dht;
|
||||||
|
|
||||||
|
unsigned long last = 0UL;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
const String name;
|
||||||
|
|
||||||
|
unsigned long intervalMs;
|
||||||
|
|
||||||
|
explicit DHT22Sensor(String name, const int pin, const unsigned long interval_ms = 5000) : pin(pin), dht(pin, DHT22), name(std::move(name)), intervalMs(interval_ms) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
dht.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
const auto now = max(1UL, millis());
|
||||||
|
float temperature = NAN;
|
||||||
|
if (last == 0 || now - last >= intervalMs) {
|
||||||
|
sensors_event_t event;
|
||||||
|
|
||||||
|
dht.temperature().getEvent(&event);
|
||||||
|
if (isnan(event.temperature)) {
|
||||||
|
Log.error("Error reading temperature!");
|
||||||
|
} else {
|
||||||
|
temperature = event.temperature;
|
||||||
|
mqttPublishValue(name + "/temperature", temperature, "TEMPERATURE_C");
|
||||||
|
}
|
||||||
|
|
||||||
|
dht.humidity().getEvent(&event);
|
||||||
|
if (isnan(event.relative_humidity)) {
|
||||||
|
Log.error("Error reading humidity!");
|
||||||
|
} else {
|
||||||
|
mqttPublishValue(name + "/humidity/relative", event.relative_humidity, "HUMIDITY_RELATIVE_PERCENT");
|
||||||
|
if (!isnan(temperature)) {
|
||||||
|
double absHumid = calculateHumidityAbsolute(event.temperature, event.relative_humidity);
|
||||||
|
mqttPublishValue(name + "/humidity/absolute", absHumid, "HUMIDITY_ABSOLUTE_GM3");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
last = now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static double calculateHumidityAbsolute(const double temperature, const double humidityRelative) {
|
||||||
|
constexpr auto A = 6.112;
|
||||||
|
constexpr auto m = 17.67;
|
||||||
|
constexpr auto Tn = 243.5;
|
||||||
|
constexpr auto Mw = 18.01534;
|
||||||
|
constexpr auto R = 8.314462618;
|
||||||
|
const auto Tk = temperature + 273.15;
|
||||||
|
const auto P_sat = A * exp((m * temperature) / (temperature + Tn));
|
||||||
|
const auto P_act = P_sat * (humidityRelative / 100.0);
|
||||||
|
return (P_act * Mw) / (R * Tk);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@ -2,6 +2,7 @@
|
|||||||
#define TSL2561_H
|
#define TSL2561_H
|
||||||
|
|
||||||
#include "Adafruit_TSL2561_U.h"
|
#include "Adafruit_TSL2561_U.h"
|
||||||
|
#include "mqtt.h"
|
||||||
|
|
||||||
class TSL2561 {
|
class TSL2561 {
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user