Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    BSEC STATE to file

    nkat
    Occasional Visitor

    BSEC STATE to file

    Hello everyone, I am just looking for your feedback for snipping of the C++ coding. Because bsec_get_state() and bsec_set_srare() with fread() and fwrite() example is absent from the BME68X Sensor API at the github site. Also, I am not very talented with C++, just a novice.

    The program is compiled and running fine. But I am not sure if it is ACTUALLY working or not. I don’t have a debug tool to see if it is behaving appropriately. The coding is expecting to run on Raspberry Pi 4 it is using bsec_2-0-6-1_generic_release_04302021..

    Here are the snipped coding with bsec gets_state() for loading state from file and is set to BSEC; Usual error check logics are removed to simplify.

    >>>
    bsec_state = fopen("/tmp/bme68x.state", "rb");

    unit8_t = result;
    result = fread(serialized_state, sizeof(unsigned char), BSEC_MAX_STATE_BLOB_SIZE, bsec_state);

    bsec_result = bsec_set_state(serialized_state, n_serialized_state, work_buffer_state, n_work_buffer_state);
    <<<

    And here are tyhe snipped coding with bsec_set_state() and save state into the file.
    >>>
    bsec_state = fopen("/tmp/bme68x.state", "wb");

    bsec_state = bsec_get_state(0, serialized_state, n_serialized_state, work_buffer_state, n_work_buffer_state, &n_serialized_state);

    result = fwrite(serialized_state, sizeof(serialized_state), 1, bsec_state)
    <<<

    1 REPLY 1
    BSTRobin
    Community Moderator

    Re: BSEC STATE to file

    Hello nkat,

    Do you use BME680 or BME688?

    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