mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-18 19:12:09 +00:00
fix #2586 (lower IAQ quality for saving to 2 and rework save logic)
This commit is contained in:
parent
cfd98b2c91
commit
2d81c97b98
@ -86,17 +86,17 @@ void BME680Sensor::updateState()
|
|||||||
if (stateUpdateCounter == 0) {
|
if (stateUpdateCounter == 0) {
|
||||||
/* First state update when IAQ accuracy is >= 3 */
|
/* First state update when IAQ accuracy is >= 3 */
|
||||||
accuracy = bme680.getData(BSEC_OUTPUT_IAQ).accuracy;
|
accuracy = bme680.getData(BSEC_OUTPUT_IAQ).accuracy;
|
||||||
if (accuracy >= 3) {
|
if (accuracy >= 2) {
|
||||||
LOG_DEBUG("%s state update IAQ accuracy %u >= 3\n", sensorName, accuracy);
|
LOG_DEBUG("%s state update IAQ accuracy %u >= 2\n", sensorName, accuracy);
|
||||||
update = true;
|
update = true;
|
||||||
stateUpdateCounter++;
|
stateUpdateCounter++;
|
||||||
} else {
|
} else {
|
||||||
LOG_DEBUG("%s not updated, IAQ accuracy is %u >= 3\n", sensorName, accuracy);
|
LOG_DEBUG("%s not updated, IAQ accuracy is %u < 2\n", sensorName, accuracy);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Update every STATE_SAVE_PERIOD minutes */
|
/* Update every STATE_SAVE_PERIOD minutes */
|
||||||
if ((stateUpdateCounter * STATE_SAVE_PERIOD) < millis()) {
|
if ((stateUpdateCounter * STATE_SAVE_PERIOD) < millis()) {
|
||||||
LOG_DEBUG("%s state update every %d minutes\n", sensorName, STATE_SAVE_PERIOD);
|
LOG_DEBUG("%s state update every %d minutes\n", sensorName, STATE_SAVE_PERIOD / 60000);
|
||||||
update = true;
|
update = true;
|
||||||
stateUpdateCounter++;
|
stateUpdateCounter++;
|
||||||
}
|
}
|
||||||
@ -104,22 +104,15 @@ void BME680Sensor::updateState()
|
|||||||
|
|
||||||
if (update) {
|
if (update) {
|
||||||
bme680.getState(bsecState);
|
bme680.getState(bsecState);
|
||||||
std::string filenameTmp = bsecConfigFileName;
|
if (FSCom.exists(bsecConfigFileName) && !FSCom.remove(bsecConfigFileName)) {
|
||||||
filenameTmp += ".tmp";
|
LOG_WARN("Can't remove old state file\n");
|
||||||
|
}
|
||||||
auto file = FSCom.open(bsecConfigFileName, FILE_O_WRITE);
|
auto file = FSCom.open(bsecConfigFileName, FILE_O_WRITE);
|
||||||
if (file) {
|
if (file) {
|
||||||
LOG_INFO("%s state write to %s.\n", sensorName, bsecConfigFileName);
|
LOG_INFO("%s state write to %s.\n", sensorName, bsecConfigFileName);
|
||||||
file.write((uint8_t *)&bsecState, BSEC_MAX_STATE_BLOB_SIZE);
|
file.write((uint8_t *)&bsecState, BSEC_MAX_STATE_BLOB_SIZE);
|
||||||
file.flush();
|
file.flush();
|
||||||
file.close();
|
file.close();
|
||||||
// brief window of risk here ;-)
|
|
||||||
if (FSCom.exists(bsecConfigFileName) && !FSCom.remove(bsecConfigFileName)) {
|
|
||||||
LOG_WARN("Can't remove old state file\n");
|
|
||||||
}
|
|
||||||
if (!renameFile(filenameTmp.c_str(), bsecConfigFileName)) {
|
|
||||||
LOG_ERROR("Error: can't rename new state file\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO("Can't write %s state (File: %s).\n", sensorName, bsecConfigFileName);
|
LOG_INFO("Can't write %s state (File: %s).\n", sensorName, bsecConfigFileName);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user