Add BMP280 support, compiler directive support for oversampling (#1344)

This commit is contained in:
melyux authored and GitHub committed 2022-12-05 09:51:45 -06:00
1 parent b9e6c4faba
commit b2666dcc83
5 files changed
+77 -54

No files matched your search

+25 -23
View File
@@ -1,29 +1,29 @@
/*
OpenMQTTGateway Addon - ESP8266 or Arduino program for home automation
/*
OpenMQTTGateway Addon - ESP8266 or Arduino program for home automation
Act as a wifi or ethernet gateway between your 433mhz/infrared IR signal and a MQTT broker
Act as a wifi or ethernet gateway between your 433mhz/infrared IR signal and a MQTT broker
Send and receiving command by MQTT
This is the Climate Addon:
- Measures Temperature, Humidity and Pressure
- Generates Values for: Temperature in degrees C and F, Humidity in %, Pressure in Pa, Altitude in Meter and Feet
- Required Hardware Module: Bosch BME280
- Required Hardware Module: Bosch BME280/BMP280
- Required Library: SparkFun BME280 Library v1.1.0 by Marshall Taylor
Connection Schemata:
--------------------
bme280 ------> Arduino Uno ----------> ESP8266
==============================================
Vcc ---------> 5V -------------------> Vu (5V)
GND ---------> GND ------------------> GND
SCL ---------> Pin A5 ---------------> D1
SDA ---------> Pin A4 ---------------> D2
BME280/BMP280 ------> Arduino Uno ----------> ESP8266
=====================================================
Vcc ----------------> 5V/3.3V ----------> 5V/3.3V (5V or 3.3V depends on the BME280/BMP280 board variant)
GND ----------------> GND ----------> GND
SCL ----------------> Pin A5 ----------> D1
SDA ----------------> Pin A4 ----------> D2
Copyright: (c) Hans-Juergen Dinges
This file is part of OpenMQTTGateway.
OpenMQTTGateway is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
@@ -58,7 +58,7 @@ void setupZsensorBME280() {
mySensor.settings.commInterface = I2C_MODE;
mySensor.settings.I2CAddress = BME280_i2c_addr;
Log.notice(F("Setup BME280 on adress: %X" CR), BME280_i2c_addr);
Log.notice(F("Setup BME280/BMP280 on address: %X" CR), BME280_i2c_addr);
//***Operation settings*****************************//
// runMode Setting - Values:
@@ -93,33 +93,35 @@ void setupZsensorBME280() {
// ------------------------
// 0, skipped
// 1 through 5, oversampling *1, *2, *4, *8, *16 respectively
mySensor.settings.tempOverSample = 1;
mySensor.settings.tempOverSample = BME280TemperatureOversample;
// pressOverSample - Values:
// -------------------------
// 0, skipped
// 1 through 5, oversampling *1, *2, *4, *8, *16 respectively
mySensor.settings.pressOverSample = 1;
mySensor.settings.pressOverSample = BME280PressureOversample;
// humidOverSample - Values:
// -------------------------
// 0, skipped
// 1 through 5, oversampling *1, *2, *4, *8, *16 respectively
mySensor.settings.humidOverSample = 1;
mySensor.settings.humidOverSample = BME280HumidityOversample;
// tempCorrection - Correction in celcius of temperature reported by bme280 sensor. Both Celcius and Farenheit temperatures are adjusted.
// tempCorrection - Correction in celcius of temperature reported by BME280/BMP280 sensor. Both Celcius and Farenheit temperatures are adjusted.
// -------------------------
// Value is a float
// ie Compiler Directive '-DBME280Correction=-3.4'
mySensor.settings.tempCorrection = BME280Correction;
delay(10); // Gives the Sensor enough time to turn on (The BME280 requires 2ms to start up)
delay(10); // Gives the Sensor enough time to turn on (The BME280/BMP280 requires 2ms to start up)
int ret = mySensor.begin();
if (ret == 0x60) {
Log.notice(F("Bosch BME280 successfully initialized: %X" CR), ret);
} else if (ret == 0x58) {
Log.notice(F("Bosch BMP280 successfully initialized: %X" CR), ret);
} else {
Log.notice(F("Bosch BME280 failed: %X" CR), ret);
Log.notice(F("Bosch BME280/BMP280 failed: %X" CR), ret);
}
}
@@ -142,9 +144,9 @@ void MeasureTempHumAndPressure() {
// Check if reads failed and exit early (to try again).
if (isnan(BmeTempC) || isnan(BmeTempF) || isnan(BmeHum) || isnan(BmePa) || isnan(BmeAltiM) || isnan(BmeAltiFt)) {
Log.error(F("Failed to read from BME280!" CR));
Log.error(F("Failed to read from BME280/BMP280!" CR));
} else {
Log.trace(F("Creating BME280 buffer" CR));
Log.trace(F("Creating BME280/BMP280 buffer" CR));
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
JsonObject BME280data = jsonBuffer.to<JsonObject>();
// Generate Temperature in degrees C