Hello,
I'm in need to have a system composed by an ESP32 that wakes up from deepsleep and reports via WiFi (to influxdb particulary) the sensed data.
I'm not really sure why there is such a 3s hard constraints but i would like to understand the following:
1. Is the 3s hard constraints only during calibration?
2. My understanding is that if i skip one "nextCall" the algorithm will never calibrate (this is what is happening)
3. Between 3s and 300s there was 30s once, was it too hard to implement 😄 ?
4. My code is the exact same code of ESP32 deep sleep with the addition of static WiFi config + a single HTTP Post which during optimal operation takes 800ms-1s but if there is an interference or a collision or a delay in the "internet" part the output is the following:
08:45:12.907 > 000043687: Successfully set state from 41007
08:45:17.428 > 000048209: Deep sleep for 18446744073703422 ms. BSEC next call at 46688 ms.
08:45:17.440 > 000048209: GetTimestamp()) * 1000: 48209000, esp_timer_get_time(): 4609499
08:45:17.707 > 000048483: Deep sleep for 18446744073707405 ms. BSEC next call at 51220 ms.
08:45:17.716 > 000048483: GetTimestamp()) * 1000: 48483000, esp_timer_get_time(): 4883730
08:45:22.567 > 000053342: Deep sleep for 18446744073700687 ms. BSEC next call at 54220 ms.
08:45:22.575 > 000053343: GetTimestamp()) * 1000: 53343000, esp_timer_get_time(): 9742914
08:45:23.703 > 000054483: Deep sleep for 18446744073701405 ms. BSEC next call at 57220 ms.
08:45:23.714 > 000054483: GetTimestamp()) * 1000: 54483000, esp_timer_get_time(): 10883705
08:45:27.170 > 000057951: Deep sleep for 18446744073697468 ms. BSEC next call at 60220 ms.
08:45:27.183 > 000057952: GetTimestamp()) * 1000: 57952000, esp_timer_get_time(): 14352607
08:45:29.702 > 000060483: Deep sleep for 18446744073695405 ms. BSEC next call at 63220 ms.
Now it is clear that a "negative" or "overflowed" sleep time doesnt make sense so i was trying to avoid sleep and perform immediately another reading cycle via sensor.run(GetTimestamp()) (basically a second run of the loop function).
void loop()
{
if (sensor.run(GetTimestamp())) {
#ifdef DEBUG
LOG("Temperature raw %.2f compensated %.2f", sensor.rawTemperature, sensor.temperature);
LOG("Humidity raw %.2f compensated %.2f", sensor.rawHumidity, sensor.humidity);
LOG("Pressure %.2f kPa", sensor.pressure / 1000);
LOG("IAQ %.0f accuracy %d", sensor.iaq, sensor.iaqAccuracy);
LOG("Static IAQ %.0f accuracy %d", sensor.staticIaq, sensor.staticIaqAccuracy);
LOG("Gas resistance %.2f kOhm", sensor.gasResistance / 1000);
#endif
sensor_state_time = GetTimestamp();
sensor.getState(sensor_state);
// DumpState("getState", sensor_state);
// LOG("Saved state to RTC memory at %lld", sensor_state_time);
CheckSensor();
update = !update;
if (WiFi.status() == WL_CONNECTED) {
if (/*influx_client.validateConnection() && */ update) {
bme680.clearFields();
// time_t tnow = time(nullptr);
// bme680.setTime(tnow);
bme680.addField("Traw", sensor.rawTemperature);
bme680.addField("T", sensor.temperature);
bme680.addField("Hraw", sensor.rawHumidity);
bme680.addField("H", sensor.humidity);
bme680.addField("P", sensor.pressure / 1000);
bme680.addField("IAQ", sensor.iaq);
bme680.addField("IAQ_acc", sensor.iaqAccuracy);
bme680.addField("SIAQ", sensor.staticIaq);
bme680.addField("SIAQ_acc", sensor.staticIaqAccuracy);
bme680.addField("R_GAS", sensor.gasResistance / 1000);
influx_client.writePoint(bme680);
}
uint64_t time_us = ((sensor.nextCall - GetTimestamp()) * 1000) - esp_timer_get_time();
LOG("Deep sleep for %llu ms. BSEC next call at %llu ms.", time_us / 1000, sensor.nextCall);
LOG("GetTimestamp()) * 1000: %llu, esp_timer_get_time(): %llu", GetTimestamp() * 1000, esp_timer_get_time());
if (time_us < 3000000){
WiFi.disconnect(true);
esp_sleep_enable_timer_wakeup(time_us);
esp_deep_sleep_start();
}
}
}
What proper solution can i implement to avoid the accuracy to stay at "0" but that allows me to push the data without moving to the 300s configuration?
Regards,