2023-01-18 14:51:48 -06:00
|
|
|
#include "BME280Sensor.h"
|
2023-01-18 08:56:47 -06:00
|
|
|
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
2022-02-26 20:52:22 -08:00
|
|
|
#include "TelemetrySensor.h"
|
2023-01-18 14:51:48 -06:00
|
|
|
#include "configuration.h"
|
2022-01-31 20:24:32 -06:00
|
|
|
#include <Adafruit_BME280.h>
|
2022-06-10 12:04:04 -05:00
|
|
|
#include <typeinfo>
|
2022-01-31 20:24:32 -06:00
|
|
|
|
2023-01-21 18:22:19 +01:00
|
|
|
BME280Sensor::BME280Sensor() : TelemetrySensor(meshtastic_TelemetrySensorType_BME280, "BME280") {}
|
2022-01-31 20:24:32 -06:00
|
|
|
|
2023-01-18 14:51:48 -06:00
|
|
|
int32_t BME280Sensor::runOnce()
|
|
|
|
|
{
|
2022-12-30 10:27:07 -06:00
|
|
|
LOG_INFO("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;
|
|
|
|
|
}
|
2023-10-15 02:33:45 +02:00
|
|
|
status = bme280.begin(nodeTelemetrySensorsMap[sensorType].first, nodeTelemetrySensorsMap[sensorType].second);
|
2023-01-18 14:51:48 -06:00
|
|
|
|
|
|
|
|
bme280.setSampling(Adafruit_BME280::MODE_FORCED,
|
|
|
|
|
Adafruit_BME280::SAMPLING_X1, // Temp. oversampling
|
|
|
|
|
Adafruit_BME280::SAMPLING_X1, // Pressure oversampling
|
|
|
|
|
Adafruit_BME280::SAMPLING_X1, // Humidity oversampling
|
|
|
|
|
Adafruit_BME280::FILTER_OFF, Adafruit_BME280::STANDBY_MS_1000);
|
|
|
|
|
|
2022-06-10 12:04:04 -05:00
|
|
|
return initI2CSensor();
|
2022-01-31 20:24:32 -06:00
|
|
|
}
|
|
|
|
|
|
2023-01-18 14:51:48 -06:00
|
|
|
void BME280Sensor::setup() {}
|
2022-06-10 12:04:04 -05:00
|
|
|
|
2023-01-21 18:22:19 +01:00
|
|
|
bool BME280Sensor::getMetrics(meshtastic_Telemetry *measurement)
|
2023-01-18 14:51:48 -06:00
|
|
|
{
|
2022-12-29 20:41:37 -06:00
|
|
|
LOG_DEBUG("BME280Sensor::getMetrics\n");
|
2022-11-05 20:12:41 +01:00
|
|
|
bme280.takeForcedMeasurement();
|
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;
|
2023-01-18 14:51:48 -06:00
|
|
|
}
|