BME680 fixes
This commit is contained in:
parent
bc4be830eb
commit
25a97fbbcc
@ -8,8 +8,6 @@ static const char TAG[] = "main";
|
|||||||
bmeStatus_t bme_status;
|
bmeStatus_t bme_status;
|
||||||
TaskHandle_t BmeTask;
|
TaskHandle_t BmeTask;
|
||||||
|
|
||||||
Bsec iaqSensor;
|
|
||||||
|
|
||||||
bsec_virtual_sensor_t sensorList[10] = {
|
bsec_virtual_sensor_t sensorList[10] = {
|
||||||
BSEC_OUTPUT_RAW_TEMPERATURE,
|
BSEC_OUTPUT_RAW_TEMPERATURE,
|
||||||
BSEC_OUTPUT_RAW_PRESSURE,
|
BSEC_OUTPUT_RAW_PRESSURE,
|
||||||
@ -23,8 +21,11 @@ bsec_virtual_sensor_t sensorList[10] = {
|
|||||||
BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_HUMIDITY,
|
BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_HUMIDITY,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
uint8_t bsecstate_buffer[BSEC_MAX_STATE_BLOB_SIZE] = {0};
|
||||||
uint16_t stateUpdateCounter = 0;
|
uint16_t stateUpdateCounter = 0;
|
||||||
|
|
||||||
|
Bsec iaqSensor;
|
||||||
|
|
||||||
// initialize BME680 sensor
|
// initialize BME680 sensor
|
||||||
int bme_init(void) {
|
int bme_init(void) {
|
||||||
|
|
||||||
@ -105,12 +106,11 @@ void bme_loop(void *pvParameters) {
|
|||||||
configASSERT(((uint32_t)pvParameters) == 1); // FreeRTOS check
|
configASSERT(((uint32_t)pvParameters) == 1); // FreeRTOS check
|
||||||
|
|
||||||
#ifdef HAS_BME
|
#ifdef HAS_BME
|
||||||
while (checkIaqSensorStatus()) {
|
|
||||||
|
|
||||||
// block i2c bus access
|
// block i2c bus access
|
||||||
if (xSemaphoreTake(I2Caccess, (DISPLAYREFRESH_MS / portTICK_PERIOD_MS)) ==
|
while (xSemaphoreTake(I2Caccess, portMAX_DELAY) == pdTRUE) {
|
||||||
pdTRUE) {
|
|
||||||
if (iaqSensor.run()) { // If new data is available
|
if (iaqSensor.run()) { // If new data is available
|
||||||
|
iaqSensor.run();
|
||||||
bme_status.raw_temperature = iaqSensor.rawTemperature;
|
bme_status.raw_temperature = iaqSensor.rawTemperature;
|
||||||
bme_status.raw_humidity = iaqSensor.rawHumidity;
|
bme_status.raw_humidity = iaqSensor.rawHumidity;
|
||||||
bme_status.temperature = iaqSensor.temperature;
|
bme_status.temperature = iaqSensor.temperature;
|
||||||
@ -120,10 +120,11 @@ void bme_loop(void *pvParameters) {
|
|||||||
bme_status.iaq = iaqSensor.iaqEstimate;
|
bme_status.iaq = iaqSensor.iaqEstimate;
|
||||||
bme_status.iaq_accuracy = iaqSensor.iaqAccuracy;
|
bme_status.iaq_accuracy = iaqSensor.iaqAccuracy;
|
||||||
bme_status.gas = iaqSensor.gasResistance;
|
bme_status.gas = iaqSensor.gasResistance;
|
||||||
|
updateState();
|
||||||
}
|
}
|
||||||
xSemaphoreGive(I2Caccess); // release i2c bus access
|
xSemaphoreGive(I2Caccess); // release i2c bus access
|
||||||
}
|
|
||||||
}
|
} // while
|
||||||
#endif
|
#endif
|
||||||
ESP_LOGE(TAG, "BME task ended");
|
ESP_LOGE(TAG, "BME task ended");
|
||||||
vTaskDelete(BmeTask); // should never be reached
|
vTaskDelete(BmeTask); // should never be reached
|
||||||
@ -131,7 +132,6 @@ void bme_loop(void *pvParameters) {
|
|||||||
} // bme_loop()
|
} // bme_loop()
|
||||||
|
|
||||||
void loadState(void) {
|
void loadState(void) {
|
||||||
uint8_t bsecstate_buffer[BSEC_MAX_STATE_BLOB_SIZE] = {0};
|
|
||||||
if (cfg.bsecstate[BSEC_MAX_STATE_BLOB_SIZE] == BSEC_MAX_STATE_BLOB_SIZE) {
|
if (cfg.bsecstate[BSEC_MAX_STATE_BLOB_SIZE] == BSEC_MAX_STATE_BLOB_SIZE) {
|
||||||
// Existing state in NVS stored
|
// Existing state in NVS stored
|
||||||
ESP_LOGI(TAG, "restoring BSEC state from NVRAM");
|
ESP_LOGI(TAG, "restoring BSEC state from NVRAM");
|
||||||
@ -145,11 +145,10 @@ void loadState(void) {
|
|||||||
|
|
||||||
void updateState(void) {
|
void updateState(void) {
|
||||||
bool update = false;
|
bool update = false;
|
||||||
uint8_t bsecstate_buffer[BSEC_MAX_STATE_BLOB_SIZE] = {0};
|
|
||||||
|
|
||||||
if (stateUpdateCounter == 0) {
|
if (stateUpdateCounter == 0) {
|
||||||
// first state update when IAQ accuracy is >= 3
|
// first state update when IAQ accuracy is >= 1
|
||||||
if (iaqSensor.iaqAccuracy >= 3) {
|
if (iaqSensor.iaqAccuracy >= 1) {
|
||||||
update = true;
|
update = true;
|
||||||
stateUpdateCounter++;
|
stateUpdateCounter++;
|
||||||
}
|
}
|
||||||
|
@ -33,20 +33,25 @@ void doHousekeeping() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// task storage debugging //
|
// task storage debugging //
|
||||||
ESP_LOGD(TAG, "Wifiloop %d bytes left",
|
ESP_LOGD(TAG, "Wifiloop %d bytes left | Taskstate = %d",
|
||||||
uxTaskGetStackHighWaterMark(wifiSwitchTask));
|
uxTaskGetStackHighWaterMark(wifiSwitchTask),
|
||||||
ESP_LOGD(TAG, "IRQhandler %d bytes left",
|
eTaskGetState(wifiSwitchTask));
|
||||||
uxTaskGetStackHighWaterMark(irqHandlerTask));
|
ESP_LOGD(TAG, "IRQhandler %d bytes left | Taskstate = %d",
|
||||||
|
uxTaskGetStackHighWaterMark(irqHandlerTask),
|
||||||
|
eTaskGetState(irqHandlerTask));
|
||||||
#ifdef HAS_GPS
|
#ifdef HAS_GPS
|
||||||
ESP_LOGD(TAG, "Gpsloop %d bytes left", uxTaskGetStackHighWaterMark(GpsTask));
|
ESP_LOGD(TAG, "Gpsloop %d bytes left | Taskstate = %d",
|
||||||
|
uxTaskGetStackHighWaterMark(GpsTask), eTaskGetState(GpsTask));
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAS_BME
|
#ifdef HAS_BME
|
||||||
ESP_LOGD(TAG, "Bmeloop %d bytes left", uxTaskGetStackHighWaterMark(BmeTask));
|
ESP_LOGD(TAG, "Bmeloop %d bytes left | Taskstate = %d",
|
||||||
|
uxTaskGetStackHighWaterMark(BmeTask), eTaskGetState(BmeTask));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (HAS_LED != NOT_A_PIN) || defined(HAS_RGB_LED)
|
#if (HAS_LED != NOT_A_PIN) || defined(HAS_RGB_LED)
|
||||||
ESP_LOGD(TAG, "LEDloop %d bytes left",
|
ESP_LOGD(TAG, "LEDloop %d bytes left | Taskstate = %d",
|
||||||
uxTaskGetStackHighWaterMark(ledLoopTask));
|
uxTaskGetStackHighWaterMark(ledLoopTask),
|
||||||
|
eTaskGetState(ledLoopTask));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// read battery voltage into global variable
|
// read battery voltage into global variable
|
||||||
@ -55,10 +60,10 @@ void doHousekeeping() {
|
|||||||
ESP_LOGI(TAG, "Voltage: %dmV", batt_voltage);
|
ESP_LOGI(TAG, "Voltage: %dmV", batt_voltage);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// display BME sensor data if present
|
// display BME sensor data
|
||||||
#ifdef HAS_BME
|
#ifdef HAS_BME
|
||||||
ESP_LOGI(TAG, "BME680 Temp: %.2f°C | IAQ: %.2f | IAQacc: %d", bme_status.temperature, bme_status.iaq, bme_status.iaq_accuracy);
|
ESP_LOGI(TAG, "BME680 Temp: %.2f°C | IAQ: %.2f | IAQacc: %d",
|
||||||
updateState();
|
bme_status.temperature, bme_status.iaq, bme_status.iaq_accuracy);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// check free heap memory
|
// check free heap memory
|
||||||
@ -66,7 +71,7 @@ void doHousekeeping() {
|
|||||||
ESP_LOGI(TAG,
|
ESP_LOGI(TAG,
|
||||||
"Memory full, counter cleared (heap low water mark = %d Bytes / "
|
"Memory full, counter cleared (heap low water mark = %d Bytes / "
|
||||||
"free heap = %d bytes)",
|
"free heap = %d bytes)",
|
||||||
ESP.getMinFreeHeap() , ESP.getFreeHeap());
|
ESP.getMinFreeHeap(), ESP.getFreeHeap());
|
||||||
SendPayload(COUNTERPORT); // send data before clearing counters
|
SendPayload(COUNTERPORT); // send data before clearing counters
|
||||||
reset_counters(); // clear macs container and reset all counters
|
reset_counters(); // clear macs container and reset all counters
|
||||||
get_salt(); // get new salt for salting hashes
|
get_salt(); // get new salt for salting hashes
|
||||||
|
@ -353,9 +353,8 @@ void setup() {
|
|||||||
ESP_LOGI(TAG, "Starting BMEloop...");
|
ESP_LOGI(TAG, "Starting BMEloop...");
|
||||||
xTaskCreatePinnedToCore(bme_loop, // task function
|
xTaskCreatePinnedToCore(bme_loop, // task function
|
||||||
"bmeloop", // name of task
|
"bmeloop", // name of task
|
||||||
4096, // stack size of task
|
2048, // stack size of task
|
||||||
(void *)1, // parameter of the task
|
(void *)1, // parameter of the task
|
||||||
//0, // priority of the task
|
|
||||||
1, // priority of the task
|
1, // priority of the task
|
||||||
&BmeTask, // task handle
|
&BmeTask, // task handle
|
||||||
1); // CPU core
|
1); // CPU core
|
||||||
|
@ -74,7 +74,7 @@ void switchWifiChannel(void *parameter) {
|
|||||||
channel =
|
channel =
|
||||||
(channel % WIFI_CHANNEL_MAX) + 1; // rotate channel 1..WIFI_CHANNEL_MAX
|
(channel % WIFI_CHANNEL_MAX) + 1; // rotate channel 1..WIFI_CHANNEL_MAX
|
||||||
esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE);
|
esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE);
|
||||||
ESP_LOGD(TAG, "Wifi set channel %d", channel);
|
//ESP_LOGD(TAG, "Wifi set channel %d", channel);
|
||||||
}
|
}
|
||||||
vTaskDelete(NULL); // shoud never be reached
|
vTaskDelete(NULL); // shoud never be reached
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user