BME fix
This commit is contained in:
parent
8663640070
commit
e8c903d20c
|
|
@ -41,6 +41,8 @@ int lastStationModeState = 1;
|
||||||
bool WiFiAutoAPStarted = false;
|
bool WiFiAutoAPStarted = false;
|
||||||
long WiFiAutoAPTime = false;
|
long WiFiAutoAPTime = false;
|
||||||
|
|
||||||
|
uint32_t bmeLastReading = -60000;
|
||||||
|
|
||||||
String batteryVoltage;
|
String batteryVoltage;
|
||||||
|
|
||||||
std::vector<String> lastHeardStation;
|
std::vector<String> lastHeardStation;
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,9 @@
|
||||||
|
|
||||||
extern Configuration Config;
|
extern Configuration Config;
|
||||||
extern String fifthLine;
|
extern String fifthLine;
|
||||||
|
extern uint32_t bmeLastReading;
|
||||||
|
|
||||||
|
float newHum, newTemp, newPress, newGas;
|
||||||
|
|
||||||
|
|
||||||
namespace BME_Utils {
|
namespace BME_Utils {
|
||||||
|
|
@ -33,12 +36,27 @@ namespace BME_Utils {
|
||||||
while (1); // sacar esto para que quede pegado si no encuentra BME280
|
while (1); // sacar esto para que quede pegado si no encuentra BME280
|
||||||
} else {
|
} else {
|
||||||
#ifdef BME280Sensor
|
#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!");
|
Serial.println("init : BME280 Module ... done!");
|
||||||
#endif
|
#endif
|
||||||
#ifdef BMP280Sensor
|
#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!");
|
Serial.println("init : BMP280 Module ... done!");
|
||||||
#endif
|
#endif
|
||||||
#ifdef BME680Sensor
|
#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!");
|
Serial.println("init : BME680 Module ... done!");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
@ -113,22 +131,33 @@ namespace BME_Utils {
|
||||||
|
|
||||||
String readDataSensor() {
|
String readDataSensor() {
|
||||||
String wx, tempStr, humStr, presStr;
|
String wx, tempStr, humStr, presStr;
|
||||||
float newHum;
|
|
||||||
|
|
||||||
float newTemp = bme.readTemperature();
|
uint32_t lastReading = millis() - bmeLastReading;
|
||||||
#if defined(BME280Sensor) || defined(BME680Sensor)
|
if (lastReading > 60*1000) {
|
||||||
|
#if defined(BME280Sensor) || defined(BMP280Sensor)
|
||||||
|
bme.takeForcedMeasurement();
|
||||||
|
newTemp = bme.readTemperature();
|
||||||
|
newPress = (bme.readPressure() / 100.0F);
|
||||||
|
#ifdef BME280Sensor
|
||||||
newHum = bme.readHumidity();
|
newHum = bme.readHumidity();
|
||||||
#endif
|
#endif
|
||||||
#ifdef BMP280Sensor
|
#ifdef BMP280Sensor
|
||||||
newHum = 0;
|
newHum = 0;
|
||||||
#endif
|
#endif
|
||||||
float newPress = (bme.readPressure() / 100.0F);
|
|
||||||
|
|
||||||
#ifdef BME680Sensor
|
|
||||||
float newGas = bme.gas_resistance / 1000.0; // in Kilo ohms
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//bme.readAltitude(SEALEVELPRESSURE_HPA) // this is for approximate Altitude Calculation.
|
#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)) {
|
if (isnan(newTemp) || isnan(newHum) || isnan(newPress)) {
|
||||||
Serial.println("BME/BMP Module data failed");
|
Serial.println("BME/BMP Module data failed");
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,9 @@
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <Adafruit_Sensor.h>
|
#include <Adafruit_Sensor.h>
|
||||||
|
|
||||||
#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 BMP280Sensor // and delete "//" from the one you want to use.
|
||||||
//#define BME680Sensor
|
#define BME680Sensor
|
||||||
|
|
||||||
#ifdef BME280Sensor
|
#ifdef BME280Sensor
|
||||||
#include <Adafruit_BME280.h>
|
#include <Adafruit_BME280.h>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue