I have been working on a project involving an ESP32-S3 with a deepsleep routine, where it wakes up every minute to perform sensor readings.
I am using the BME680 sensor along with the BSEC2 library for Arduino.
I have been utilizing BSEC_SAMPLE_RATE_ULP and was able to obtain IAQ data when using delay instead of entering deepsleep mode.
I understand that the BSEC2 library requires the following fot the algo to work:
1. A function like bsecMillis() to provide the elapsed time since system start for algorithm calculations.
2. State recovery after deepsleep.
I have implemented both requirements accordingly.
For bsecMillis(), I have created a custom run() function to take the device’s elapsed time since boot and pass it in, replacing bsecMillis():
bool Bsec2::run(uint64_t currTimeMs)
{
uint8_t nFieldsLeft = 0;
bme68xData data;
int64_t currTimeNs = currTimeMs * INT64_C(1000000);
opMode = bmeConf.op_mode;
other processing....
And i am passing the elapsed time of the system since boot as a argument.
void bme680Read(uint64_t elapsedTimeMs)
{
if (!envSensor.run(elapsedTimeMs))
{
checkBsecStatus(envSensor);
}
}For state management, I am saving the sensor state to RTC memory (`RTC_DATA_ATTR`) before entering deepsleep and restoring it upon wake-up:
RTC_DATA_ATTR uint8_t rtcBsecState[BSEC_MAX_STATE_BLOB_SIZE];void saveBsecState()
{
if (envSensor.setState(rtcBsecState)) {
Serial.println("BSEC state saved to RTC memory");
} else {
Serial.println("Failed to save BSEC state");
}
}
void loadBsecState()
{
if (envSensor.getState(rtcBsecState)) {
Serial.println("BSEC state loaded from RTC memory");
} else {
Serial.println("Failed to load BSEC state");
}
}Despite these implementations, I am not receiving any callbacks even after allowing the sensor to run for hours. When I remove deepsleep, callbacks occur every three minutes as expected.
I am calling envSensor.run() at each wake-up (interval of one minute).
Does anyone have example code for effective deepsleep integration or any suggestions on what might be missing or misconfigured in my implementation?