kopia lustrzana https://github.com/meshtastic/firmware
use BSEC2 for ESP32-C3
rodzic
7c9d0a022a
commit
10f41e376c
|
@ -25,6 +25,7 @@ build_flags =
|
|||
-DCONFIG_NIMBLE_CPP_LOG_LEVEL=2
|
||||
-DCONFIG_BT_NIMBLE_MAX_CCCDS=20
|
||||
-DESP_OPENSSL_SUPPRESS_LEGACY_WARNING
|
||||
-DUSE_BSEC2
|
||||
;-DDEBUG_HEAP
|
||||
|
||||
lib_deps =
|
||||
|
@ -35,9 +36,13 @@ lib_deps =
|
|||
h2zero/NimBLE-Arduino@^1.4.0
|
||||
https://github.com/lewisxhe/XPowersLib.git#84b7373faea3118b6c37954d52f98b8a337148d6
|
||||
https://github.com/meshtastic/ESP32_Codec2.git#633326c78ac251c059ab3a8c430fcdf25b41672f
|
||||
lib_ignore =
|
||||
boschsensortec/BSEC2 Software Library@^1.3.2200
|
||||
boschsensortec/BME68x Sensor Library@^1.1.40407
|
||||
|
||||
lib_ignore =
|
||||
segger_rtt
|
||||
ESP32 BLE Arduino
|
||||
BSEC Software Library
|
||||
|
||||
; customize the partition table
|
||||
; http://docs.platformio.org/en/latest/platforms/espressif32.html#partition-tables
|
||||
|
|
|
@ -13,8 +13,12 @@ int32_t BME680Sensor::runOnce()
|
|||
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||
}
|
||||
bme680.begin(nodeTelemetrySensorsMap[sensorType], Wire);
|
||||
#ifdef USE_BSEC2
|
||||
if (bme680.status == BSEC_OK) {
|
||||
#else
|
||||
if (bme680.bsecStatus == BSEC_OK) {
|
||||
bme680.setConfig(bsec_config_iaq);
|
||||
#endif
|
||||
bme680.setConfig(Default_H2S_NonH2S_config);
|
||||
loadState();
|
||||
bme680.updateSubscription(sensorList, 13, BSEC_SAMPLE_RATE_LP);
|
||||
status = 1;
|
||||
|
@ -22,6 +26,7 @@ int32_t BME680Sensor::runOnce()
|
|||
status = 0;
|
||||
}
|
||||
|
||||
|
||||
return initI2CSensor();
|
||||
}
|
||||
|
||||
|
@ -30,10 +35,17 @@ void BME680Sensor::setup() {}
|
|||
bool BME680Sensor::getMetrics(meshtastic_Telemetry *measurement)
|
||||
{
|
||||
bme680.run();
|
||||
#ifdef USE_BSEC2
|
||||
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;
|
||||
measurement->variant.environment_metrics.barometric_pressure = bme680.getData(BSEC_OUTPUT_RAW_PRESSURE).signal / 100.0F;
|
||||
measurement->variant.environment_metrics.gas_resistance = bme680.getData(BSEC_OUTPUT_RAW_GAS).signal / 1000.0;
|
||||
#else
|
||||
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.gasResistance / 1000.0;
|
||||
#endif
|
||||
// Check if we need to save state to filesystem (every STATE_SAVE_PERIOD ms)
|
||||
updateState();
|
||||
return true;
|
||||
|
@ -62,12 +74,17 @@ void BME680Sensor::updateState()
|
|||
bool update = false;
|
||||
if (stateUpdateCounter == 0) {
|
||||
/* First state update when IAQ accuracy is >= 3 */
|
||||
if (bme680.iaqAccuracy >= 3) {
|
||||
LOG_DEBUG("%s state update IAQ accuracy %u >= 3\n", sensorName, bme680.iaqAccuracy);
|
||||
#ifdef USE_BSEC2
|
||||
accuracy = bme680.getData(BSEC_OUTPUT_IAQ).accuracy;
|
||||
#else
|
||||
accuracy = bme680.iaqAccuracy;
|
||||
#endif
|
||||
if (accuracy >= 3) {
|
||||
LOG_DEBUG("%s state update IAQ accuracy %u >= 3\n", sensorName, accuracy);
|
||||
update = true;
|
||||
stateUpdateCounter++;
|
||||
} else {
|
||||
LOG_DEBUG("%s not updated, IAQ accuracy is %u >= 3\n", sensorName, bme680.iaqAccuracy);
|
||||
LOG_DEBUG("%s not updated, IAQ accuracy is %u >= 3\n", sensorName, accuracy);
|
||||
}
|
||||
} else {
|
||||
/* Update every STATE_SAVE_PERIOD minutes */
|
||||
|
|
|
@ -1,22 +1,35 @@
|
|||
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
||||
#include "TelemetrySensor.h"
|
||||
#ifdef USE_BSEC2
|
||||
#include <bsec2.h>
|
||||
#else
|
||||
#include <bsec.h>
|
||||
#endif // USE_BSEC2
|
||||
|
||||
#define STATE_SAVE_PERIOD UINT32_C(360 * 60 * 1000) // That's 6 hours worth of millis()
|
||||
|
||||
const uint8_t bsec_config_iaq[] = {
|
||||
#ifdef USE_BSEC2
|
||||
#include "config/Default_H2S_NonH2S/Default_H2S_NonH2S.h"
|
||||
#else
|
||||
const uint8_t Default_H2S_NonH2S_config[] = {
|
||||
#include <config/generic_33v_3s_4d/bsec_iaq.txt>
|
||||
};
|
||||
#endif // USE_BSEC2
|
||||
|
||||
class BME680Sensor : virtual public TelemetrySensor
|
||||
{
|
||||
private:
|
||||
#ifdef USE_BSEC2
|
||||
Bsec2 bme680;
|
||||
#else
|
||||
Bsec bme680;
|
||||
#endif // USE_BSEC2
|
||||
|
||||
protected:
|
||||
virtual void setup() override;
|
||||
const char *bsecConfigFileName = "/prefs/bsec.dat";
|
||||
uint8_t bsecState[BSEC_MAX_STATE_BLOB_SIZE] = {0};
|
||||
uint8_t accuracy = 0;
|
||||
uint16_t stateUpdateCounter = 0;
|
||||
bsec_virtual_sensor_t sensorList[13] = {BSEC_OUTPUT_IAQ,
|
||||
BSEC_OUTPUT_STATIC_IAQ,
|
||||
|
|
|
@ -5,10 +5,4 @@ board_level = extra
|
|||
build_flags = ${esp32c3_base.build_flags}
|
||||
-D PRIVATE_HW
|
||||
-I variants/ai-c3
|
||||
; as long as BSEC2 Software Library is not supported remove Sensors from build
|
||||
build_src_filter = ${esp32c3_base.build_src_filter}
|
||||
-<modules/Telemetry/EnvironmentTelemetry.cpp>
|
||||
-<modules/Telemetry/AirQualityTelemetry.cpp>
|
||||
-<modules/Telemetry/Sensor>
|
||||
lib_ignore = ${esp32c3_base.lib_ignore}
|
||||
BSEC Software Library
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue