Browse Source

powersave

powersave
Hendrik Langer 5 years ago
parent
commit
4b5a5c8828
  1. 63
      src/main.cpp

63
src/main.cpp

@ -22,6 +22,7 @@
#include <Adafruit_Sensor.h>
#include "Adafruit_BME280.h"
#include "Adafruit_BME680.h"
#include "bme680.h"
#include "Adafruit_VEML6075.h"
#include <BH1750.h>
@ -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?");
}

Loading…
Cancel
Save