Hi Community!
I have been working on a project involving the ESP32-S3 , which incorporates a deepsleep routine where it wakes up every minute to perform sensor readings.
The sensor in use is the BME680, utilizing the BSEC2 library for Arduino.
I am currently using BSEC_SAMPLE_RATE_ULP and was able to obtain IAQ data when using delays instead of entering deepsleep.
I understand that the BSEC2 library requires the following to be able to update the algo during deepsleep:
bsecMillis() for algo calculation
State recover after deepsleep
And hence i've already implemented both.
For bsecMillis(), I have developed a custom run() function that accepts the device's elapsed time since boot and replaces bsecMillis() as follows:
bool Bsec2::run(uint64_t currTimeMs)
{
uint8_t nFieldsLeft = 0;
bme68xData data;
int64_t currTimeNs = currTimeMs * INT64_C(1000000);
opMode = bmeConf.op_mode;
.........
void bme680Read(uint64_t elapsedTimeMs)
{
if (!envSensor.run(elapsedTimeMs))
{
checkBsecStatus(envSensor);
}
}For state management, I store the BSEC state into RTC memory (`RTC_DATA_ATTR`) before the device enters deepsleep and restore it upon boot:
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 still not receiving any callback events after hours of sensor operation.
When I disable deepsleep, I get callbacks approximately every 3 minutes, which aligns with expectations.
I call envSensor.run() each time the device wakes up (every 1 minute).
Does anyone have example code for effectively managing deepsleep with this setup?
Or insights into potential issues with the above implementation that could prevent callback events from occurring?
Any help or advise willl be much appreciated, thanks!