diff --git a/src/main.cpp b/src/main.cpp index 4eea5be..6572a2c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,6 +22,7 @@ #include #include "Adafruit_BME280.h" #include "Adafruit_BME680.h" +#include "bme680.h" #include "Adafruit_VEML6075.h" #include @@ -184,6 +185,67 @@ void getSensorMeasurements() { } +void setSensorsPowerOn() { + if (bme680_active) { + /* + gas_sensor.power_mode = BME680_FORCED_MODE; + bme680_set_sensor_mode(&gas_sensor); + bme680.setTemperatureOversampling(BME680_OS_8X); + bme680.setHumidityOversampling(BME680_OS_2X); + bme680.setPressureOversampling(BME680_OS_4X); + bme680.setIIRFilterSize(BME680_FILTER_SIZE_3); + */ + bme680.setGasHeater(320, 150); // 320*C for 150 ms + bme680.beginReading(); + } + if (bme280_active) { + bme280.setSampling(Adafruit_BME280::MODE_NORMAL, + Adafruit_BME280::SAMPLING_X8, // temperature + Adafruit_BME280::SAMPLING_X4, // pressure + Adafruit_BME280::SAMPLING_X2, // humidity + Adafruit_BME280::FILTER_X4, + Adafruit_BME280::STANDBY_MS_0_5 ); + } + if (light_active) { + static constexpr byte BH1750_I2CADDR = 0x23; + Wire.beginTransmission(BH1750_I2CADDR); + Wire.write(BH1750_POWER_ON); + byte ack = Wire.endTransmission(); + + } + if (uv_active) { + uv.shutdown(false); + } +} + + +void setSensorsPowerSave() { + if (bme680_active) { + bme680.setGasHeater(0, 0); // 320*C for 150 ms + /* + gas_sensor.power_mode = BME680_SLEEP_MODE; + bme680_set_sensor_mode(&gas_sensor); + */ + } + if (bme280_active) { + bme280.setSampling(Adafruit_BME280::MODE_SLEEP, + Adafruit_BME280::SAMPLING_X1, // temperature + Adafruit_BME280::SAMPLING_X1, // pressure + Adafruit_BME280::SAMPLING_X1, // humidity + Adafruit_BME280::FILTER_OFF ); + } + if (light_active) { + static constexpr byte BH1750_I2CADDR = 0x23; + Wire.beginTransmission(BH1750_I2CADDR); + Wire.write(BH1750_POWER_DOWN); + byte ack = Wire.endTransmission(); + } + if (uv_active) { + uv.shutdown(true); + } +} + + void receiveMqtt(const char* topic, const char* data) { sensor_readings_t* sensor = NULL; @@ -570,6 +632,7 @@ void setup() if (lightMeter.begin()) { light_active = true; + lightMeter.setMTreg((byte) BH1750_DEFAULT_MTREG); } else { Serial.println("Failed to communicate with BH1750 sensor, check wiring?"); }