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