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 "BME680Sensor.h"
|
|
|
|
|
#include <Adafruit_BME680.h>
|
|
|
|
|
|
2022-06-10 12:04:04 -05:00
|
|
|
BME680Sensor::BME680Sensor() :
|
|
|
|
|
TelemetrySensor(TelemetrySensorType_BME680, "BME680")
|
2022-06-05 09:50:06 -05:00
|
|
|
{
|
2022-01-31 20:24:32 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t BME680Sensor::runOnce() {
|
2022-12-29 20:41:37 -06:00
|
|
|
LOG_DEBUG("Init sensor: %s\n", sensorName);
|
2022-06-10 12:04:04 -05:00
|
|
|
if (!hasSensor()) {
|
2022-06-05 09:50:06 -05:00
|
|
|
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
|
|
|
|
}
|
2022-11-06 10:52:54 +01:00
|
|
|
status = bme680.begin(nodeTelemetrySensorsMap[sensorType]);
|
2022-11-06 10:37:14 +01:00
|
|
|
|
|
|
|
|
return initI2CSensor();
|
2022-01-31 20:24:32 -06:00
|
|
|
}
|
|
|
|
|
|
2022-11-06 10:37:14 +01:00
|
|
|
void BME680Sensor::setup() { }
|
|
|
|
|
|
2022-06-10 12:04:04 -05:00
|
|
|
bool BME680Sensor::getMetrics(Telemetry *measurement) {
|
2022-11-06 10:37:14 +01:00
|
|
|
bme680.performReading();
|
|
|
|
|
measurement->variant.environment_metrics.temperature = bme680.temperature;
|
|
|
|
|
measurement->variant.environment_metrics.relative_humidity = bme680.humidity;
|
|
|
|
|
measurement->variant.environment_metrics.barometric_pressure = bme680.pressure / 100.0F;
|
|
|
|
|
measurement->variant.environment_metrics.gas_resistance = bme680.gas_resistance / 1000.0;
|
2022-01-31 20:24:32 -06:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|