Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    ESP32 Deepsleep + WiFi within 3s - Deal breaker

    ESP32 Deepsleep + WiFi within 3s - Deal breaker

    itsmaxdd
    Member

    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,

    1 REPLY 1

    BSTRobin
    Community Moderator
    Community Moderator

    Hi itsmaxdd,

    Different power modes to meet different application requirements.
    Low power (LP) mode that is designed for interactive applications where the air quality is tracked and
    observed at a higher update rate of 3 seconds with a current consumption of <1 mA.

    BSEC only needs to be called periodically, and there is no special requirement.
    How to implement this requirement on the host platform requires more consideration from the host platform.

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist