Merge remote-tracking branch 'upstream/main' into more-usermod-fixes

This commit is contained in:
Will Miles 2025-03-29 11:12:31 -04:00
commit 354a0aef52
3 changed files with 1158 additions and 1134 deletions

View File

@ -2,20 +2,17 @@
* @file usermod_BMW68X.cpp
* @author Gabriel A. Sieben (GeoGab)
* @brief Usermod for WLED to implement the BME680/BME688 sensor
* @version 1.0.0
* @date 19 Feb 2024
* @version 1.0.2
* @date 28 March 2025
*/
#warning ********************Included USERMOD_BME68X ********************
#define UMOD_DEVICE "ESP32" // NOTE - Set your hardware here
#define HARDWARE_VERSION "1.0" // NOTE - Set your hardware version here
#define UMOD_BME680X_SW_VERSION "1.0.1" // NOTE - Version of the User Mod
#define UMOD_BME680X_SW_VERSION "1.0.2" // NOTE - Version of the User Mod
#define CALIB_FILE_NAME "/BME680X-Calib.hex" // NOTE - Calibration file name
#define UMOD_NAME "BME680X" // NOTE - User module name
#define UMOD_DEBUG_NAME "UM-BME680X: " // NOTE - Debug print module name addon
/* Debug Print Text Coloring */
#define ESC "\033"
#define ESC_CSI ESC "["
#define ESC_STYLE_RESET ESC_CSI "0m"
@ -33,10 +30,10 @@
/* Debug Print Special Text */
#define INFO_COLUMN ESC_CURSOR_COLUMN(60)
#define OK_MSG INFO_COLUMN "[" ESC_FGCOLOR_GREEN "OK" ESC_STYLE_RESET "]"
#define FAIL_MSG INFO_COLUMN "[" ESC_FGCOLOR_RED "FAIL" ESC_STYLE_RESET "]"
#define WARN_MSG INFO_COLUMN "[" ESC_FGCOLOR_YELLOW "WARN" ESC_STYLE_RESET "]"
#define DONE_MSG INFO_COLUMN "[" ESC_FGCOLOR_CYAN "DONE" ESC_STYLE_RESET "]"
#define GOGAB_OK INFO_COLUMN "[" ESC_FGCOLOR_GREEN "OK" ESC_STYLE_RESET "]"
#define GOGAB_FAIL INFO_COLUMN "[" ESC_FGCOLOR_RED "FAIL" ESC_STYLE_RESET "]"
#define GOGAB_WARN INFO_COLUMN "[" ESC_FGCOLOR_YELLOW "WARN" ESC_STYLE_RESET "]"
#define GOGAB_DONE INFO_COLUMN "[" ESC_FGCOLOR_CYAN "DONE" ESC_STYLE_RESET "]"
#include "bsec.h" // Bosch sensor library
#include "wled.h"
@ -328,7 +325,7 @@ void UsermodBME68X::setup() {
/* Check, if i2c is activated */
if (i2c_scl < 0 || i2c_sda < 0) {
settings.enabled = false; // Disable usermod once i2c is not running
DEBUG_PRINTLN(F(UMOD_DEBUG_NAME "I2C is not activated. Please activate I2C first." FAIL_MSG));
DEBUG_PRINTLN(F(UMOD_DEBUG_NAME "I2C is not activated. Please activate I2C first." GOGAB_FAIL));
return;
}
@ -352,7 +349,7 @@ void UsermodBME68X::setup() {
loadState(); // Load the old calibration data
checkIaqSensorStatus(); // Check the sensor status
// HomeAssistantDiscovery();
DEBUG_PRINTLN(F(INFO_COLUMN DONE_MSG));
DEBUG_PRINTLN(F(INFO_COLUMN GOGAB_DONE));
}
/**
@ -564,7 +561,7 @@ void UsermodBME68X::HomeAssistantDiscovery() {
MQTT_PublishHASensor(_nameStabStatus, "", _unitNone, settings.publishSensorState - 1, 1);
MQTT_PublishHASensor(_nameRunInStatus, "", _unitNone, settings.publishSensorState - 1, 1);
DEBUG_PRINTLN(UMOD_DEBUG_NAME DONE_MSG);
DEBUG_PRINTLN(UMOD_DEBUG_NAME GOGAB_DONE);
}
/**
@ -750,7 +747,7 @@ void UsermodBME68X::addToConfig(JsonObject& root) {
sensors_json[FPSTR(_nameVoc)] = settings.decimals.Voc;
sensors_json[FPSTR(_nameGasPer)] = settings.decimals.gasPerc;
DEBUG_PRINTLN(F(OK_MSG));
DEBUG_PRINTLN(F(GOGAB_OK));
}
/**
@ -831,7 +828,7 @@ bool UsermodBME68X::readFromConfig(JsonObject& root) {
configComplete &= getJsonValue(top["Sensors"][FPSTR(_nameVoc)], settings.decimals.Voc, 0 );
configComplete &= getJsonValue(top["Sensors"][FPSTR(_nameGasPer)], settings.decimals.gasPerc, 0 );
DEBUG_PRINTLN(F(OK_MSG));
DEBUG_PRINTLN(F(GOGAB_OK));
/* Set the selected temperature unit */
if (settings.tempScale) {
@ -845,10 +842,10 @@ bool UsermodBME68X::readFromConfig(JsonObject& root) {
DEBUG_PRINT(F(UMOD_DEBUG_NAME "Deleting Calibration File"));
flags.DeleteCaibration = false;
if (WLED_FS.remove(CALIB_FILE_NAME)) {
DEBUG_PRINTLN(F(OK_MSG));
DEBUG_PRINTLN(F(GOGAB_OK));
}
else {
DEBUG_PRINTLN(F(FAIL_MSG));
DEBUG_PRINTLN(F(GOGAB_FAIL));
}
}
@ -1026,11 +1023,11 @@ void UsermodBME68X::checkIaqSensorStatus() {
flags.InitSuccessful = false;
if (iaqSensor.bsecStatus < BSEC_OK) {
InfoPageStatusLine += " Error Code : " + String(iaqSensor.bsecStatus);
DEBUG_PRINTLN(FAIL_MSG);
DEBUG_PRINTLN(GOGAB_FAIL);
}
else {
InfoPageStatusLine += " Warning Code : " + String(iaqSensor.bsecStatus);
DEBUG_PRINTLN(WARN_MSG);
DEBUG_PRINTLN(GOGAB_WARN);
}
}
else {
@ -1041,16 +1038,16 @@ void UsermodBME68X::checkIaqSensorStatus() {
flags.InitSuccessful = false;
if (iaqSensor.bme68xStatus < BME68X_OK) {
InfoPageStatusLine += "error code: " + String(iaqSensor.bme68xStatus);
DEBUG_PRINTLN(FAIL_MSG);
DEBUG_PRINTLN(GOGAB_FAIL);
}
else {
InfoPageStatusLine += "warning code: " + String(iaqSensor.bme68xStatus);
DEBUG_PRINTLN(WARN_MSG);
DEBUG_PRINTLN(GOGAB_WARN);
}
}
else {
InfoPageStatusLine += F("OK");
DEBUG_PRINTLN(OK_MSG);
DEBUG_PRINTLN(GOGAB_OK);
}
}
}
@ -1063,12 +1060,12 @@ void UsermodBME68X::loadState() {
DEBUG_PRINT(F(UMOD_DEBUG_NAME "Read the calibration file: "));
File file = WLED_FS.open(CALIB_FILE_NAME, FILE_READ);
if (!file) {
DEBUG_PRINTLN(FAIL_MSG);
DEBUG_PRINTLN(GOGAB_FAIL);
}
else {
file.read(bsecState, BSEC_MAX_STATE_BLOB_SIZE);
file.close();
DEBUG_PRINTLN(OK_MSG);
DEBUG_PRINTLN(GOGAB_OK);
iaqSensor.setState(bsecState);
}
}
@ -1084,14 +1081,14 @@ void UsermodBME68X::saveState() {
DEBUG_PRINT(F(UMOD_DEBUG_NAME "Write the calibration file "));
File file = WLED_FS.open(CALIB_FILE_NAME, FILE_WRITE);
if (!file) {
DEBUG_PRINTLN(FAIL_MSG);
DEBUG_PRINTLN(GOGAB_FAIL);
}
else {
iaqSensor.getState(bsecState);
file.write(bsecState, BSEC_MAX_STATE_BLOB_SIZE);
file.close();
stateUpdateCounter++;
DEBUG_PRINTF("(saved %d times)" OK_MSG "\n", stateUpdateCounter);
DEBUG_PRINTF("(saved %d times)" GOGAB_OK "\n", stateUpdateCounter);
flags.SaveState = false; // Clear save state flag
char contbuffer[30];

View File

@ -1,53 +1,58 @@
# Usermod BME68X
This usermod was developed for a BME680/BME68X sensor. The BME68X is not compatible with the BME280/BMP280 chip. It has its own library. The original 'BSEC Software Library' from Bosch was used to develop the code. The measured values are displayed on the WLED info page.
<p align="center"><img src="pics/pic1.png" style="width:60%;"></p>
In addition, the values are published on MQTT if this is active. The topic used for this is: 'wled/[MQTT Client ID]'. The Client ID is set in the WLED MQTT settings.
<p align="center"><img src="pics/pic2.png"></p>
If you use HomeAssistance discovery, the device tree for HomeAssistance is created. This is published under the topic 'homeassistant/sensor/[MQTT Client ID]' via MQTT.
<p align="center"><img src="pics/pic3.png"></p>
A device with the following sensors appears in HomeAssistant. Please note that MQTT must be activated in HomeAssistant.
<p align="center"><img src="pics/pic4.png" style="width:60%;"></p>
## Features
Raw sensor types
Sensor Accuracy Scale Range
--------------------------------------------------------------------------------------------------
-----------------------------
Temperature +/- 1.0 °C/°F -40 to 85 °C
Humidity +/- 3 % 0 to 100 %
Pressure +/- 1 hPa 300 to 1100 hPa
Gas Resistance Ohm
The BSEC Library calculates the following values via the gas resistance
Sensor Accuracy Scale Range
--------------------------------------------------------------------------------------------------
-----------------------------
IAQ value between 0 and 500
Static IAQ same as IAQ but for permanently installed devices
CO2 PPM
VOC PPM
Gas-Percentage %
In addition the usermod calculates
Sensor Accuracy Scale Range
--------------------------------------------------------------------------------------------------
-----------------------------
Absolute humidity g/m³
Dew point °C/°F
### IAQ (Indoor Air Quality)
The IAQ is divided into the following value groups.
<p align="center"><img src="pics/pic5.png"></p>
For more detailed information, please consult the enclosed Bosch product description (BME680.pdf).
## Calibration of the device
The gas sensor of the BME68X must be calibrated. This differs from the BME280, which does not require any calibration.
@ -67,10 +72,10 @@ The IAQ index is therefore only meaningful if IAQ Accuracy = 3. In addition to t
Reasonably reliable values are therefore only achieved when accuracy displays the value 3.
## Settings
The settings of the usermods are set in the usermod section of wled.
<p align="center"><img src="pics/pic6.png"></p>
The possible settings are
@ -88,6 +93,7 @@ The possible settings are
- **Del Calibration Hist:** If a check mark is set here, the calibration file saved in the file system is deleted when the settings are saved.
### Sensors
Applies to all sensors. The number of decimal places is set here. If the sensor is set to -1, it will no longer be published. In addition, the IAQ values can be activated here in verbal form.
It is recommended to use the Static IAQ for the IAQ values. This is recommended by Bosch for statically placed devices.
@ -99,6 +105,7 @@ Data is published over MQTT - make sure you've enabled the MQTT sync interface.
In addition to outputting via MQTT, you can read the values from the Info Screen on the dashboard page of the device's web interface.
Methods also exist to read the read/calculated values from other WLED modules through code.
- getTemperature(); The scale °C/°F is depended to the settings
- getHumidity();
- getPressure();
@ -118,15 +125,36 @@ Methods also exist to read the read/calculated values from other WLED modules th
- getStabStatus();
- getRunInStatus();
## Compilation
To enable, compile with `BME68X` in `custom_usermods` (e.g. in `platformio_override.ini`)
Example:
```[env:esp32_mySpecial]
extends = env:esp32dev
custom_usermods = ${env:esp32dev.custom_usermods} BME68X
```
## Revision History
### Version 1.0.0
- First version of the BME68X_v user module
### Version 1.0.1
- Rebased to WELD Version 0.15
- Reworked some default settings
- A problem with the default settings has been fixed
### Version 1.0.2
* Rebased to WELD Version 0.16
* Fixed: Solved compilation problems related to some macro naming interferences.
## Known problems
- MQTT goes online at device start. Shortly afterwards it goes offline and takes quite a while until it goes online again. The problem does not come from this user module, but from the WLED core.
- If you save the settings often, WLED can get stuck.
- If many LEDS are connected to WLED, reading the sensor can cause a small but noticeable hang. The "Pause While WLED Active" option was introduced as a workaround.

View File

@ -1,6 +1,5 @@
{
"name": "BME68X_v2",
"build": { "libArchive": false},
"name": "BME68X",
"dependencies": {
"boschsensortec/BSEC Software Library":"^1.8.1492"
}