From e8c903d20c8ea887a4f4c6c4a3eab38341e43cf2 Mon Sep 17 00:00:00 2001 From: richonguzman Date: Wed, 6 Mar 2024 09:01:17 -0300 Subject: [PATCH] BME fix --- src/LoRa_APRS_iGate.cpp | 2 ++ src/bme_utils.cpp | 65 +++++++++++++++++++++++++++++------------ src/bme_utils.h | 4 +-- 3 files changed, 51 insertions(+), 20 deletions(-) diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index f0738b7..b1730a4 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -41,6 +41,8 @@ int lastStationModeState = 1; bool WiFiAutoAPStarted = false; long WiFiAutoAPTime = false; +uint32_t bmeLastReading = -60000; + String batteryVoltage; std::vector lastHeardStation; diff --git a/src/bme_utils.cpp b/src/bme_utils.cpp index 6547c08..b606103 100644 --- a/src/bme_utils.cpp +++ b/src/bme_utils.cpp @@ -7,8 +7,11 @@ #define HEIGHT_CORRECTION 0 // in meters #define CORRECTION_FACTOR (8.2296) // for meters -extern Configuration Config; -extern String fifthLine; +extern Configuration Config; +extern String fifthLine; +extern uint32_t bmeLastReading; + +float newHum, newTemp, newPress, newGas; namespace BME_Utils { @@ -33,14 +36,29 @@ namespace BME_Utils { while (1); // sacar esto para que quede pegado si no encuentra BME280 } else { #ifdef BME280Sensor + bme.setSampling(Adafruit_BME280::MODE_FORCED, + Adafruit_BME280::SAMPLING_X1, + Adafruit_BME280::SAMPLING_X1, + Adafruit_BME280::SAMPLING_X1, + Adafruit_BME280::FILTER_OFF + ); Serial.println("init : BME280 Module ... done!"); #endif #ifdef BMP280Sensor + bme.setSampling(Adafruit_BMP280::MODE_FORCED, + Adafruit_BMP280::SAMPLING_X1, + Adafruit_BMP280::SAMPLING_X1, + Adafruit_BMP280::FILTER_OFF + ); Serial.println("init : BMP280 Module ... done!"); #endif #ifdef BME680Sensor + bme.setTemperatureOversampling(BME680_OS_1X); + bme.setHumidityOversampling(BME680_OS_1X); + bme.setPressureOversampling(BME680_OS_1X); + bme.setIIRFilterSize(BME680_FILTER_SIZE_0); Serial.println("init : BME680 Module ... done!"); - #endif + #endif } } else { Serial.println("(BME/BMP sensor not 'active' in 'igate_conf.json')"); @@ -113,22 +131,33 @@ namespace BME_Utils { String readDataSensor() { String wx, tempStr, humStr, presStr; - float newHum; - - float newTemp = bme.readTemperature(); - #if defined(BME280Sensor) || defined(BME680Sensor) - newHum = bme.readHumidity(); - #endif - #ifdef BMP280Sensor - newHum = 0; - #endif - float newPress = (bme.readPressure() / 100.0F); - #ifdef BME680Sensor - float newGas = bme.gas_resistance / 1000.0; // in Kilo ohms - #endif - - //bme.readAltitude(SEALEVELPRESSURE_HPA) // this is for approximate Altitude Calculation. + uint32_t lastReading = millis() - bmeLastReading; + if (lastReading > 60*1000) { + #if defined(BME280Sensor) || defined(BMP280Sensor) + bme.takeForcedMeasurement(); + newTemp = bme.readTemperature(); + newPress = (bme.readPressure() / 100.0F); + #ifdef BME280Sensor + newHum = bme.readHumidity(); + #endif + #ifdef BMP280Sensor + newHum = 0; + #endif + #endif + + #ifdef BME680Sensor + bme.performReading(); + delay(50); + if (bme.endReading()) { + newTemp = bme.temperature; + newPress = (bme.pressure / 100.0F); + newHum = bme.humidity; + newGas = bme.gas_resistance / 1000.0; // in Kilo ohms + } + #endif + bmeLastReading = millis(); + } if (isnan(newTemp) || isnan(newHum) || isnan(newPress)) { Serial.println("BME/BMP Module data failed"); diff --git a/src/bme_utils.h b/src/bme_utils.h index 3d7a40c..22257a5 100644 --- a/src/bme_utils.h +++ b/src/bme_utils.h @@ -4,9 +4,9 @@ #include #include -#define BME280Sensor // its set by default but you should comment it with "//" +//#define BME280Sensor // its set by default but you should comment it with "//" //#define BMP280Sensor // and delete "//" from the one you want to use. -//#define BME680Sensor +#define BME680Sensor #ifdef BME280Sensor #include