Bosch Sensortec Community

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

    BME680 : Using BSEC in backend

    BME680 : Using BSEC in backend

    erkgoge
    New Poster

    Hello,

    Is there any way we can run BSEC library outside of the microcontroller ?

     

    Details :

    I want to use BSEC library to get VOC readings from BME680.

    But maximum flash memory size is 192KB (STM32L073RZ), and when using BSEC the binaries are 271KB.

    Can I let's say make simple gas measurements on MCU, then convert the data in the cloud using BSEC ?

    4 REPLIES 4

    handytech
    Community Moderator
    Community Moderator

    Yes, this is possible, with a few limitations. For instance, the sensor should run with a fixed configuration, according to the desired operating mode (ULP or LP). Therefore the ULP+ feature isn't supported anymore.

    An Arduino library is included in BSEC's package to show how the sensor should be configured, with the following snippet extracted from bme680_data.h:

    /* Macro definitions */
    #define BSEC_HUMIDITY_OVERSAMPLING       UINT8_C(1)            /*!< Humidity oversampling rate */
    #define BSEC_TEMPERATURE_OVERSAMPLING    UINT8_C(2)            /*!< Temperature oversampling rate */
    #define BSEC_PRESSURE_OVERSAMPLING       UINT8_C(5)            /*!< Pressure oversampling rate */
    #define BSEC_HEATER_TEMP_LP              UINT16_C(320)         /*!< Low Power mode heater temperature */
    #define BSEC_HEATING_DURATION_LP         UINT16_C(197)         /*!< Low Power mode heating duration */
    #define BSEC_HEATER_TEMP_ULP             UINT16_C(400)         /*!< Ultra Low Power mode heater temperature */
    #define BSEC_HEATING_DURATION_ULP        UINT16_C(1943)        /*!< Ultra Low Power mode heating duration */
    

    Attached is an example project that is based on the original bsec_integration.c sample code,  but was edited to use a csv file containing raw sensor data as input, and generating another csv file with BSEC's outputs. It includes:

    • bme680_remote_BSEC_run.c, bsec_integration_backend.c and bsec_integration_backend.h, the sample code,
    • datalog.csv, an example of raw sensor log from a BME680 (including the necessary timestamp, raw temperature/pressure/humidity/gas resistance) in a .csv file in a format expected by the sample code above,
    • bsec_output.csv, an example of output generated by the sample code above when datalog.csv was used as input file.

    To run the example above, you will need to add the library headers (bsec_interface.h and bsec_datatypes.h) from your BSEC package, as well as the pre-compiled library for your platform (BSEC v1.4.7.3 was used in this project, therefore it is recommended to use at least this version).

    To generate bsec_output.csv, BSECLibrary64.dll was used, and compiled in a COINES environment in Windows 10's CMD:

    C:\Users\username\Documents\BME680_remote_BSEC_run>bme680_remote_BSEC_run.exe -i datalog.csv -o bsec_output.csv
    input file: datalog.csv
    output file: bsec_output.csv
    BSEC initilization complete, now running BSEC...
    BSEC processing complete!
    

     

    Thank you very much for your helpful answer.

    Hi, 

    thank you for this sample. I managed to compile it and test it in our backend environment.

    I have a problem that I don't fully undestand. How many measure do I need to write in the input file and how much time I need to cover with the datalog?

    In our case we have a BME680 that send one single measure (temp, rH, pressure, gasRes) every 10-15 mins.

    How many measures do I need to calculate IAQ with BSEC? How can I perform an IAQ calculation without sending a large amount of data from the sensor (like in this sample)?

    I've noted that the first 100 rows are always "25" with zero accuracy, how can I manage this in backend?

    Thank you in advance

     

     

    Hi @HES_Engineering,

    Running BSEC in the backend here only means that BSEC can run in any device and not specifically the MCU directly connected to the BME680 for instance. Therefore even when BSEC is running in the backend, you will still need to operate the BME680 with the same settings (T/P/H oversampling, heather duration and temperature, sampling interval, absolute timestamp, etc.) as required by BSEC.


    @HES_Engineering wrote:

    I have a problem that I don't fully undestand. How many measure do I need to write in the input file and how much time I need to cover with the datalog?


    There is no specific rule here, and it completely depends on your use-case and expectations. The example code was provided for reference only, and simply parses the input file for however many lines are present in the file.

    If you need real-time IAQ estimation, you will need to feed BSEC with relevant sensor data every time a BME680 measurement is done (again, with the relevant settings and timings). If real-time IAQ estimation is not needed, you may as well process batches of your preferred duration, e.g. once an hour, once a day, etc.

    If you don't keep your BSEC instance/process open or running continuously, you would of course need to save and reload a valid state file every time BSEC is closed and re-opened, but the attached example only illustrated an example of a single, continuous run, without state file usage.


    @HES_Engineering wrote:

    In our case we have a BME680 that send one single measure (temp, rH, pressure, gasRes) every 10-15 mins.

    10-15mins is not a valid sampling period for BSEC. The operating mode with the lowest current consumption supported by BSEC is its Ultra-Low-Power (ULP) mode, with a fixed sampling period of 5mins.


    @HES_Engineering wrote:

    How can I perform an IAQ calculation without sending a large amount of data from the sensor (like in this sample)?


    Assuming you are able to store in the backend the trimming values of each individual BME680s you are operating, the minimum amount of data needed for each valid measurement would be an absolute timestamp together with the raw ADC/register values of the temperature/pressure/humidity/gas read-outs. Then prior to feeding these raw ADC values to BSEC, you would need to use the sensor API's compensation formulas to get the relevant units of each output, i.e. °C/%RH/Pa/Ohm. Trimming values read-out is already implemented and done by default when using our sensor APIs, and are unique per sensor, i.e. the trimming values of a specific sensor cannot be used for any other sensor.


    @HES_Engineering wrote:

    How many measures do I need to calculate IAQ with BSEC?

    I've noted that the first 100 rows are always "25" with zero accuracy, how can I manage this in backend?


    When BSEC starts running without loading a valid state file, the IAQ accuracy will show a value of zero (and typ. IAQ=25) for 20min in ULP mode, and 5min LP/HP modes, corresponding to BME680's initial stabilization time. If BSEC remains stuck at zero forever, it typically indicates that the timestamp of the measurements don't meet the timing requirements of current operating mode selected in BSEC, or some other integration issues. After these 20min/5min based on the operating mode, IAQ accuracy should vary between 1 and 3 over time based on the ambient conditions. BSEC may run asynchronously by processing batches of your preffered duration (after implementing state file support as mentioned above), but the BME680 itself must run continously at a fixed sampling rate to perform optimally, otherwise the initial 20min/5min of initialiazation will be autonomously triggered again by BSEC.

    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