mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-22 02:32:23 +00:00
fix BSEC2 BME680 Sensor Readings
This commit is contained in:
@@ -6,21 +6,41 @@
|
||||
|
||||
BME680Sensor::BME680Sensor() : TelemetrySensor(meshtastic_TelemetrySensorType_BME680, "BME680") {}
|
||||
|
||||
int32_t BME680Sensor::runTrigger()
|
||||
{
|
||||
if (!bme680.run()) {
|
||||
checkStatus("runTrigger");
|
||||
}
|
||||
return 35;
|
||||
}
|
||||
|
||||
int32_t BME680Sensor::runOnce()
|
||||
{
|
||||
LOG_INFO("Init sensor: %s with the BSEC Library\n", sensorName);
|
||||
|
||||
if (!hasSensor()) {
|
||||
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||
}
|
||||
bme680.begin(nodeTelemetrySensorsMap[sensorType], Wire);
|
||||
if (!bme680.begin(nodeTelemetrySensorsMap[sensorType], Wire))
|
||||
checkStatus("begin");
|
||||
|
||||
if (bme680.status == BSEC_OK) {
|
||||
bme680.setConfig(Default_H2S_NonH2S_config);
|
||||
loadState();
|
||||
bme680.updateSubscription(sensorList, 13, BSEC_SAMPLE_RATE_LP);
|
||||
status = 1;
|
||||
if (!bme680.setConfig(bsec_config_iaq)) {
|
||||
checkStatus("setConfig");
|
||||
status = 0;
|
||||
}
|
||||
loadState();
|
||||
if (!bme680.updateSubscription(sensorList, ARRAY_LEN(sensorList), BSEC_SAMPLE_RATE_LP)) {
|
||||
checkStatus("updateSubscription");
|
||||
status = 0;
|
||||
}
|
||||
LOG_INFO("Init sensor: %s with the BSEC Library version %d.%d.%d.%d \n", sensorName, bme680.version.major,
|
||||
bme680.version.minor, bme680.version.major_bugfix, bme680.version.minor_bugfix);
|
||||
} else {
|
||||
status = 0;
|
||||
}
|
||||
if (status == 0)
|
||||
LOG_DEBUG("BME680Sensor::runOnce: bme680.status %d\n", bme680.status);
|
||||
|
||||
return initI2CSensor();
|
||||
}
|
||||
@@ -29,8 +49,8 @@ void BME680Sensor::setup() {}
|
||||
|
||||
bool BME680Sensor::getMetrics(meshtastic_Telemetry *measurement)
|
||||
{
|
||||
bme680.run();
|
||||
|
||||
if (bme680.getData(BSEC_OUTPUT_RAW_PRESSURE).signal == 0)
|
||||
return false;
|
||||
measurement->variant.environment_metrics.temperature = bme680.getData(BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_TEMPERATURE).signal;
|
||||
measurement->variant.environment_metrics.relative_humidity =
|
||||
bme680.getData(BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_HUMIDITY).signal;
|
||||
@@ -106,4 +126,17 @@ void BME680Sensor::updateState()
|
||||
#else
|
||||
LOG_ERROR("ERROR: Filesystem not implemented\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void BME680Sensor::checkStatus(String functionName)
|
||||
{
|
||||
if (bme680.status < BSEC_OK)
|
||||
LOG_ERROR("%s BSEC2 code: %s\n", functionName.c_str(), String(bme680.status).c_str());
|
||||
else if (bme680.status > BSEC_OK)
|
||||
LOG_WARN("%s BSEC2 code: %s\n", functionName.c_str(), String(bme680.status).c_str());
|
||||
|
||||
if (bme680.sensor.status < BME68X_OK)
|
||||
LOG_ERROR("%s BME68X code: %s\n", functionName.c_str(), String(bme680.sensor.status).c_str());
|
||||
else if (bme680.sensor.status > BME68X_OK)
|
||||
LOG_WARN("%s BME68X code: %s\n", functionName.c_str(), String(bme680.sensor.status).c_str());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user