2022-02-26 20:52:22 -08:00
|
|
|
#include "../mesh/generated/telemetry.pb.h"
|
2022-01-31 20:24:32 -06:00
|
|
|
#include "configuration.h"
|
2022-02-26 20:52:22 -08:00
|
|
|
#include "TelemetrySensor.h"
|
2022-01-31 20:24:32 -06:00
|
|
|
#include "BME280Sensor.h"
|
|
|
|
|
#include <Adafruit_BME280.h>
|
|
|
|
|
|
2022-06-05 09:50:06 -05:00
|
|
|
BME280Sensor::BME280Sensor() : TelemetrySensor {}
|
|
|
|
|
{
|
2022-01-31 20:24:32 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t BME280Sensor::runOnce() {
|
|
|
|
|
unsigned bme280Status;
|
2022-06-05 09:50:06 -05:00
|
|
|
DEBUG_MSG("Init sensor: TelemetrySensorType_BME280\n");
|
|
|
|
|
if (!hasSensor(TelemetrySensorType_BME280)) {
|
|
|
|
|
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
|
|
|
|
}
|
|
|
|
|
bme280Status = bme280.begin(nodeTelemetrySensorsMap[TelemetrySensorType_BME280]);
|
2022-01-31 20:24:32 -06:00
|
|
|
if (!bme280Status) {
|
2022-06-05 09:50:06 -05:00
|
|
|
DEBUG_MSG("Could not connect to any detected BME-280 sensor.\nRemoving from nodeTelemetrySensorsMap.\n");
|
|
|
|
|
nodeTelemetrySensorsMap[TelemetrySensorType_BME280] = 0;
|
2022-01-31 20:24:32 -06:00
|
|
|
} else {
|
2022-06-05 09:50:06 -05:00
|
|
|
DEBUG_MSG("Opened BME280 on default i2c bus\n");
|
2022-01-31 20:24:32 -06:00
|
|
|
}
|
2022-06-05 09:50:06 -05:00
|
|
|
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
2022-01-31 20:24:32 -06:00
|
|
|
}
|
|
|
|
|
|
2022-02-26 20:52:22 -08:00
|
|
|
bool BME280Sensor::getMeasurement(Telemetry *measurement) {
|
2022-06-05 09:50:06 -05:00
|
|
|
DEBUG_MSG("BME280Sensor::getMeasurement\n");
|
2022-03-27 14:55:35 +00:00
|
|
|
measurement->variant.environment_metrics.temperature = bme280.readTemperature();
|
|
|
|
|
measurement->variant.environment_metrics.relative_humidity = bme280.readHumidity();
|
|
|
|
|
measurement->variant.environment_metrics.barometric_pressure = bme280.readPressure() / 100.0F;
|
2022-01-31 20:24:32 -06:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|