Compare commits
No commits in common. "da31e2d40aad6c38f200fbfff560941ea450d6cb" and "19e81885a97da9b438bcf286d0eb7e8fa89be577" have entirely different histories.
da31e2d40a
...
19e81885a9
@ -3,10 +3,7 @@ data_dir = ${PROJECT_DIR}/data/${PIOENV}
|
||||
|
||||
[common]
|
||||
framework = arduino
|
||||
lib_deps = SPI
|
||||
https://github.com/adafruit/Adafruit_BusIO
|
||||
https://github.com/milesburton/Arduino-Temperature-Control-Library
|
||||
https://github.com/adafruit/DHT-sensor-library
|
||||
lib_deps = https://github.com/milesburton/Arduino-Temperature-Control-Library
|
||||
https://github.com/adafruit/Adafruit_TSL2561
|
||||
https://github.com/knolleary/pubsubclient
|
||||
https://github.com/adafruit/Adafruit_BME680
|
||||
@ -37,10 +34,10 @@ lib_deps = ${common.lib_deps}
|
||||
build_flags = ${common.build_flags} -DNODE_GREENHOUSE -DHOSTNAME=\"Greenhouse\"
|
||||
board_build.filesystem = ${common.board_build.filesystem}
|
||||
monitor_speed = ${common.monitor_speed}
|
||||
;upload_protocol = ${common.upload_protocol}
|
||||
;upload_port = 10.0.0.160
|
||||
upload_port = ${common.upload_port}
|
||||
upload_speed = ${common.upload_speed}
|
||||
upload_protocol = ${common.upload_protocol}
|
||||
upload_port = 10.0.0.160
|
||||
;upload_port = ${common.upload_port}
|
||||
;upload_speed = ${common.upload_speed}
|
||||
|
||||
[env:Fermenter]
|
||||
platform = ${esp12e.platform}
|
||||
|
||||
@ -1,19 +1,24 @@
|
||||
#ifdef NODE_GREENHOUSE
|
||||
|
||||
#include "patrix/bme680.h"
|
||||
#include "patrix/tsl2561.h"
|
||||
#include "patrix/DHT22.h"
|
||||
|
||||
TSL2561 greenhouseTSL("greenhouse");
|
||||
TSL2561 gardenTSL("garden");
|
||||
|
||||
DHT22Sensor greenhouseDHT22("greenhouse", D5);
|
||||
BME680 gardenBME("garden");
|
||||
|
||||
BME680 greenhouseBME("greenhouse");
|
||||
|
||||
void patrixSetup() {
|
||||
greenhouseTSL.setup();
|
||||
gardenTSL.setup();
|
||||
gardenBME.setup();
|
||||
greenhouseBME.setup();
|
||||
}
|
||||
|
||||
void patrixLoop() {
|
||||
greenhouseTSL.loop();
|
||||
greenhouseDHT22.loop();
|
||||
gardenTSL.loop();
|
||||
gardenBME.loop();
|
||||
greenhouseBME.loop();
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -1,72 +0,0 @@
|
||||
#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,7 +2,6 @@
|
||||
#define TSL2561_H
|
||||
|
||||
#include "Adafruit_TSL2561_U.h"
|
||||
#include "mqtt.h"
|
||||
|
||||
class TSL2561 {
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user