kopia lustrzana https://github.com/meshtastic/firmware
add debug/info print
rodzic
ac40f77694
commit
1621fbb5ab
|
@ -8,7 +8,7 @@ BME680Sensor::BME680Sensor() : TelemetrySensor(meshtastic_TelemetrySensorType_BM
|
|||
|
||||
int32_t BME680Sensor::runOnce()
|
||||
{
|
||||
LOG_INFO("Init sensor: %s\n", sensorName);
|
||||
LOG_INFO("Init sensor: %s with the BSEC Library\n", sensorName);
|
||||
if (!hasSensor()) {
|
||||
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||
}
|
||||
|
@ -34,23 +34,25 @@ bool BME680Sensor::getMetrics(meshtastic_Telemetry *measurement)
|
|||
measurement->variant.environment_metrics.relative_humidity = bme680.humidity;
|
||||
measurement->variant.environment_metrics.barometric_pressure = bme680.pressure / 100.0F;
|
||||
measurement->variant.environment_metrics.gas_resistance = bme680.gasResistance / 1000.0;
|
||||
updateState();
|
||||
|
||||
// Check if we need to save state to filesystem (every STATE_SAVE_PERIOD ms)
|
||||
|
||||
updateState();
|
||||
return true;
|
||||
}
|
||||
|
||||
void BME680Sensor::loadState()
|
||||
{
|
||||
#ifdef FSCom
|
||||
if (File file = FSCom.open(bsecConfigFileName, FILE_O_READ)) {
|
||||
auto file = FSCom.open(bsecConfigFileName, FILE_O_READ);
|
||||
if (file) {
|
||||
file.read((uint8_t *)&bsecState, BSEC_MAX_STATE_BLOB_SIZE);
|
||||
file.close();
|
||||
bme680.setState(bsecState);
|
||||
LOG_INFO("%s state read from %s.\n", sensorName, bsecConfigFileName);
|
||||
} else {
|
||||
FSCom.remove(bsecConfigFileName);
|
||||
LOG_INFO("No %s state found (File: %s).\n", sensorName, bsecConfigFileName);
|
||||
}
|
||||
#else
|
||||
LOG_ERROR("ERROR: Filesystem not implemented\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -61,12 +63,16 @@ void BME680Sensor::updateState()
|
|||
if (stateUpdateCounter == 0) {
|
||||
/* First state update when IAQ accuracy is >= 3 */
|
||||
if (bme680.iaqAccuracy >= 3) {
|
||||
LOG_DEBUG("%s state update IAQ accuracy %u >= 3\n", sensorName, bme680.iaqAccuracy);
|
||||
update = true;
|
||||
stateUpdateCounter++;
|
||||
} else {
|
||||
LOG_DEBUG("%s not updated, IAQ accuracy is %u >= 3\n", sensorName, bme680.iaqAccuracy);
|
||||
}
|
||||
} else {
|
||||
/* Update every STATE_SAVE_PERIOD minutes */
|
||||
if ((stateUpdateCounter * STATE_SAVE_PERIOD) < millis()) {
|
||||
LOG_DEBUG("%s state update every %d minutes\n", sensorName, STATE_SAVE_PERIOD);
|
||||
update = true;
|
||||
stateUpdateCounter++;
|
||||
}
|
||||
|
@ -74,11 +80,25 @@ void BME680Sensor::updateState()
|
|||
|
||||
if (update) {
|
||||
bme680.getState(bsecState);
|
||||
if (File file = FSCom.open(bsecConfigFileName, FILE_O_WRITE)) {
|
||||
std::string filenameTmp = bsecConfigFileName;
|
||||
filenameTmp += ".tmp";
|
||||
auto file = FSCom.open(bsecConfigFileName, FILE_O_WRITE);
|
||||
if (file) {
|
||||
LOG_INFO("%s state write to %s.\n", sensorName, bsecConfigFileName);
|
||||
file.write((uint8_t *)&bsecState, BSEC_MAX_STATE_BLOB_SIZE);
|
||||
file.flush();
|
||||
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 {
|
||||
LOG_INFO("Can't write %s state (File: %s).\n", sensorName, bsecConfigFileName);
|
||||
}
|
||||
}
|
||||
#else
|
||||
LOG_ERROR("ERROR: Filesystem not implemented\n");
|
||||
#endif
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
#include "TelemetrySensor.h"
|
||||
#include <bsec.h>
|
||||
|
||||
#define STATE_SAVE_PERIOD UINT32_C(360 * 60 * 1000)
|
||||
#define STATE_SAVE_PERIOD UINT32_C(360 * 60 * 1000) // That's 6 hours worth of millis()
|
||||
|
||||
const uint8_t bsec_config_iaq[] = {
|
||||
#include <config/generic_33v_3s_4d/bsec_iaq.txt>
|
||||
|
|
Ładowanie…
Reference in New Issue