BME680 bugfixes

This commit is contained in:
Klaus K Wilting committed 2018-12-31 15:46:52 +01:00
1 parent 7040408513
commit 998e122f3a
5 files changed
+29 -24

No files matched your search

+18 -11
View File
@@ -23,12 +23,14 @@ bsec_virtual_sensor_t sensorList[10] = {
BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_HUMIDITY,
};
uint8_t bsecState[BSEC_MAX_STATE_BLOB_SIZE] = {0};
uint8_t bsecstate_buffer[BSEC_MAX_STATE_BLOB_SIZE] = {0};
uint16_t stateUpdateCounter = 0;
// initialize BME680 sensor
int bme_init(void) {
// return = 0 -> error / return = 1 -> success
// block i2c bus access
if (xSemaphoreTake(I2Caccess, (DISPLAYREFRESH_MS / portTICK_PERIOD_MS)) ==
pdTRUE) {
@@ -46,7 +48,7 @@ int bme_init(void) {
ESP_LOGI(TAG, "BME680 sensor found and initialized");
else {
ESP_LOGE(TAG, "BME680 sensor not found");
return 1;
goto error;
}
loadState();
@@ -58,16 +60,21 @@ int bme_init(void) {
ESP_LOGI(TAG, "BSEC subscription succesful");
else {
ESP_LOGE(TAG, "BSEC subscription error");
return 1;
goto error;
}
xSemaphoreGive(I2Caccess); // release i2c bus access
} else {
ESP_LOGE(TAG, "I2c bus busy - BME680 initialization error");
return 1;
goto error;
}
xSemaphoreGive(I2Caccess); // release i2c bus access
return 1;
error:
xSemaphoreGive(I2Caccess); // release i2c bus access
return 0;
} // bme_init()
// Helper function definitions
@@ -128,8 +135,8 @@ void loadState(void) {
if (cfg.bsecstate[BSEC_MAX_STATE_BLOB_SIZE + 1] == BSEC_MAX_STATE_BLOB_SIZE) {
// Existing state in NVS stored
ESP_LOGI(TAG, "restoring BSEC state from NVRAM");
memcpy(bsecState, cfg.bsecstate, BSEC_MAX_STATE_BLOB_SIZE);
iaqSensor.setState(bsecState);
memcpy(bsecstate_buffer, cfg.bsecstate, BSEC_MAX_STATE_BLOB_SIZE);
iaqSensor.setState(bsecstate_buffer);
checkIaqSensorStatus();
} else // no state stored
ESP_LOGI(TAG,
@@ -154,9 +161,9 @@ void updateState(void) {
}
if (update) {
memcpy(bsecState, cfg.bsecstate, BSEC_MAX_STATE_BLOB_SIZE);
memcpy(bsecstate_buffer, cfg.bsecstate, BSEC_MAX_STATE_BLOB_SIZE);
cfg.bsecstate[BSEC_MAX_STATE_BLOB_SIZE + 1] = BSEC_MAX_STATE_BLOB_SIZE;
iaqSensor.getState(bsecState);
iaqSensor.getState(bsecstate_buffer);
checkIaqSensorStatus();
ESP_LOGI(TAG, "saving BSEC state to NVRAM");
saveConfig();
+4 -6
View File
@@ -80,11 +80,11 @@ void saveConfig() {
int16_t flash16 = 0;
size_t required_size;
char storedversion[10];
char bsecstate[BSEC_MAX_STATE_BLOB_SIZE + 1];
char bsecstate_buffer[BSEC_MAX_STATE_BLOB_SIZE + 1];
if (nvs_get_str(my_handle, "bsecstate", bsecstate, &required_size) !=
if (nvs_get_str(my_handle, "bsecstate", bsecstate_buffer, &required_size) !=
ESP_OK ||
strcmp(bsecstate, cfg.bsecstate) != 0)
strcmp(bsecstate_buffer, cfg.bsecstate) != 0)
nvs_set_str(my_handle, "bsecstate", cfg.bsecstate);
if (nvs_get_str(my_handle, "version", storedversion, &required_size) !=
@@ -212,12 +212,10 @@ void loadConfig() {
// populate pre set defaults with current values from NVRAM
char bsecstate[BSEC_MAX_STATE_BLOB_SIZE + 1];
if (nvs_get_str(my_handle, "bsecstate", NULL, &required_size) == ESP_OK) {
nvs_get_str(my_handle, "bsecstate", cfg.bsecstate, &required_size);
ESP_LOGI(TAG, "bsecstate = %d",
cfg.bsecstate[BSEC_MAX_STATE_BLOB_SIZE + 1]);
(int)(cfg.bsecstate[BSEC_MAX_STATE_BLOB_SIZE + 1]));
}
if (nvs_get_i8(my_handle, "lorasf", &flash8) == ESP_OK) {
-1
View File
@@ -72,7 +72,6 @@
// Settings for BME680 environmental sensor (if present)
#define BME_TEMP_OFFSET 5.0f // Offset sensor on chip temp <-> ambient temp [default = 5°C]
#define BSEC_MAX_STATE_BLOB_SIZE 134 // size of Bosch BME680 state data blob
#define STATE_SAVE_PERIOD UINT32_C(360 * 60 * 1000) // update every 360 minutes = 4 times a day
// OTA settings