Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 
    SOLVED

    BME680 stops measuring after 1 hour and is stuck in a sleep loop, also IAQ resets using STM32

    BME680 stops measuring after 1 hour and is stuck in a sleep loop, also IAQ resets using STM32

    Crackl1ng
    Member

    Hello Bosch-Community,

     

    I'm using the reference-code with bme680_task.c which was recommended here for my STM32L4P. After a little more than one hour my BME680 stops blinking, which indicates that it stopped measuring. Analyzing the code, he's stuck in a HAL_Delay. I was wondering if

    int64_t time_stamp = 0;
    [...]
    sleep((uint32_t)time_stamp_interval_ms);

    should actually be uint64_t? So far it didn't resolve my issues yet.

    Also my IAQ_Accurarcy resets after each transmission via LoRaWAN, though every variable is declared as static and is not reset. Could it be, that  they are also timestamp issues here? It's hard to resolve the issues on it's own when the functions needed are hidden in another libary.

    Thank you in advance.

    Sincerely

     

    Crackl1ng

    3 REPLIES 3

    BSTRobin
    Community Moderator
    Community Moderator

    Hello Crackl1ng,

    HAL_Delay was a delay funtion. You could change you code to this and try it again.

    int64_t get_timestamp_us()
    {
    int64_t system_current_time = 0;
    // ...
    // Please insert system specific function to retrieve a timestamp (in microseconds)
    // ...
    uint32_t tick;
    tick = HAL_GetTick();
    system_current_time = 1000*(int64_t)tick;
    return system_current_time;
    }

    Hello BSTRobin,

    thank you for your reply. The changes you suggested seem to work, as the sensor is already running for several hours. However it still resets the iaq_acc values everytime I start a LoRaWAN transmission. All values are defined as static, therefore it should not reset after performing a LoRaWAN 

    Here is the code I use:

     

    //Main loop for BME680 measurements     
    if ((ret.bme680_status == 0) && (ret.bsec_status == 0))
    
    {
    
      //      PDEBUG("intialize BSEC library successful\r\n");
      /* Call to endless loop function which reads and processes data based on sensor settings */
      /* State is saved every 10.000 samples, which means every 10.000 * 3 secs = 500 minutes  */
      while (1)
    
      {
    
        bsec_iot_loop(sleep, get_timestamp_us, output_ready, state_save,
          10000);
    
        HAL_GPIO_TogglePin(LED_0_GPIO_Port, LED_0_Pin);
    
        if (lora_timer > tx_intervall_LoRa * 1000)
    
        {
    
          start_lora(my_data, data_len);
    
          lora_timer = 0;
    
        }
    
      }

     

    Meanwhile I changed the bsec_iot_loop to 

     

    void bsec_iot_loop(sleep_fct sleep, get_timestamp_us_fct get_timestamp_us, output_ready_fct output_ready,
                        state_save_fct state_save, uint32_t save_intvl)
    {
        /* Timestamp variables */
        int64_t static time_stamp = 0;
        int64_t static time_stamp_interval_ms = 0;
        
        /* Allocate enough memory for up to BSEC_MAX_PHYSICAL_SENSOR physical inputs*/
        bsec_input_t static bsec_inputs[BSEC_MAX_PHYSICAL_SENSOR];
        
        /* Number of inputs to BSEC */
        uint8_t static num_bsec_inputs = 0;
        
        /* BSEC sensor settings struct */
        bsec_bme_settings_t static sensor_settings;
        
        /* Save state variables */
        uint8_t static bsec_state[BSEC_MAX_STATE_BLOB_SIZE];
        uint8_t static work_buffer[BSEC_MAX_WORKBUFFER_SIZE];
        uint32_t static bsec_state_len = 0;
        uint32_t static n_samples = 0;
        
        bsec_library_return_t static bsec_status = BSEC_OK;
    
    //    while (1)
    //    {
            /* get the timestamp in nanoseconds before calling bsec_sensor_control() */
            time_stamp = get_timestamp_us() * 1000;
            
            /* Retrieve sensor settings to be used in this time instant by calling bsec_sensor_control */
            bsec_sensor_control(time_stamp, &sensor_settings);
            
            /* Trigger a measurement if necessary */
            bme680_bsec_trigger_measurement(&sensor_settings, sleep);
            
            /* Read data from last measurement */
            num_bsec_inputs = 0;
            bme680_bsec_read_data(time_stamp, bsec_inputs, &num_bsec_inputs, sensor_settings.process_data);
            
            /* Time to invoke BSEC to perform the actual processing */
            bme680_bsec_process_data(bsec_inputs, num_bsec_inputs, output_ready);
            
            /* Increment sample counter */
            n_samples++;
            
            /* Retrieve and store state if the passed save_intvl */
            if (n_samples >= save_intvl)
            {
                bsec_status = bsec_get_state(0, bsec_state, sizeof(bsec_state), work_buffer, sizeof(work_buffer), &bsec_state_len);
                if (bsec_status == BSEC_OK)
                {
                    state_save(bsec_state, bsec_state_len);
                }
                n_samples = 0;
            }
            
            
            /* Compute how long we can sleep until we need to call bsec_sensor_control() next */
            /* Time_stamp is converted from microseconds to nanoseconds first and then the difference to milliseconds */
            time_stamp_interval_ms = (sensor_settings.next_call - get_timestamp_us() * 1000) / 1000000;
            if (time_stamp_interval_ms > 0)
            {
                sleep((uint32_t)time_stamp_interval_ms);
            }
       // }
    }

     

     

     

    so it will eventually leave the original loop to check, if it's ready to transmit data via LoRa. After every transmission, the stat_iaq resets and I cannot figure out why.

     

    Thank you in advance.

    BSTRobin
    Community Moderator
    Community Moderator

    Hello Crackl1ng,

    Could you only run original example code and see the output data from BSEC?

    void output_ready(int64_t timestamp, float iaq, uint8_t iaq_accuracy, float temperature, float humidity,
    float pressure, float raw_temperature, float raw_humidity, float gas, bsec_library_return_t bsec_status,
    float static_iaq, float co2_equivalent, float breath_voc_equivalent)
    {
    PDEBUG("timestamp=%lld, iaq=%f, iaq_accuracy=%d, temperature=%f, humity=%f, pressure=%f, \
    raw_temperature=%f, raw_humity=%f, gas=%f, bsec_status=%d, static_iaq=%f, co2_equivalent=%f, \
    breath_voc_equivalent=%f\r\n", timestamp, iaq, iaq_accuracy, temperature, humidity, pressure, \
    raw_temperature, raw_humidity, gas, bsec_status, static_iaq, co2_equivalent, breath_voc_equivalent);
    }

    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