From 406ef9d8b1c66b33def2241f2c062c1fb1c55bff Mon Sep 17 00:00:00 2001
From: DTTerastar
Date: Sun, 10 Jul 2022 23:28:22 -0400
Subject: [PATCH] Fix BME280
---
src/BME280Sensor.cpp | 9 +++++----
src/I2C.cpp | 5 +++--
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/src/BME280Sensor.cpp b/src/BME280Sensor.cpp
index 52a7e10..b5f44e5 100644
--- a/src/BME280Sensor.cpp
+++ b/src/BME280Sensor.cpp
@@ -68,12 +68,13 @@ namespace BME280
if (!I2C_Bus_1_Enabled && !I2C_Bus_2_Enabled) return;
if (!initialized) return;
- float temperature = BME280.readTemperature();
- float humidity = BME280.readHumidity();
- float pressure = BME280.readPressure() / 100.0F;
-
if (millis() - bme280PreviousMillis >= sensorInterval) {
+ BME280.takeForcedMeasurement();
+ float temperature = BME280.readTemperature();
+ float humidity = BME280.readHumidity();
+ float pressure = BME280.readPressure() / 100.0F;
+
mqttClient.publish((roomsTopic + "/bme280_temperature").c_str(), 0, 1, String(temperature).c_str());
mqttClient.publish((roomsTopic + "/bme280_humidity").c_str(), 0, 1, String(humidity).c_str());
mqttClient.publish((roomsTopic + "/bme280_pressure").c_str(), 0, 1, String(pressure).c_str());
diff --git a/src/I2C.cpp b/src/I2C.cpp
index af87a6d..ef9258d 100644
--- a/src/I2C.cpp
+++ b/src/I2C.cpp
@@ -19,6 +19,7 @@ namespace I2C
WiFiSettings.heading("I2C Settings ℹ️", false);
WiFiSettings.html("h4", "Bus 1:");
+
I2C_Bus_1_SDA = WiFiSettings.integer("I2C_Bus_1_SDA", 0, 39, DEFAULT_I2C_BUS_1_SDA, "SDA pin (-1 to disable)");
I2C_Bus_1_SCL = WiFiSettings.integer("I2C_Bus_1_SCL", 0, 39, DEFAULT_I2C_BUS_1_SCL, "SCL pin (-1 to disable)");
@@ -39,13 +40,13 @@ namespace I2C
if (I2C_Bus_1_SDA != -1 && I2C_Bus_1_SDA != -1) {
Wire.begin(I2C_Bus_1_SDA, I2C_Bus_1_SCL);
I2C_Bus_1_Enabled = true;
- Serial.println("\nInitialized I2C Bus 1");
+ Serial.println("Initialized I2C Bus 1 (SDA: " + String(I2C_Bus_1_SDA) + ", SCL: " + String(I2C_Bus_1_SCL) + ")");
}
if (I2C_Bus_2_SDA != -1 && I2C_Bus_2_SDA != -1) {
Wire1.begin(I2C_Bus_2_SDA, I2C_Bus_2_SCL);
I2C_Bus_2_Enabled = true;
- Serial.println("\nInitialized I2C Bus 2");
+ Serial.println("Initialized I2C Bus 2 (SDA: " + String(I2C_Bus_2_SDA) + ", SCL: " + String(I2C_Bus_2_SCL) + ")");
}
}