Bosch Sensortec Community

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

    BME680 on ESPHome using Bosch's BSEC library

    BME680 on ESPHome using Bosch's BSEC library

    ChrisE
    Occasional Visitor

    Dear all,

    I am trying to integrate a Bosch BME680 sensor running on the precompiled, closed source "BSEC" library as a custom sensor for ESPHome for an ESP32 for getting an IAQ reading instead of the resistance reading only. In other words, I do not want to use the ESPHome-driver for the sensor but the precompiled Bosch BSEC library wrapped in a custom ESPHome sensor component.

    However, I cannot get ESPHome to compile/link the libraries correctly. What am I missing here?

    Thank you very much for getting me kickstarted with with the precompiled library on ESPHome.

    Best regards,

    Chris

     

    Configuration YAML:

    esphome:
      name: multisensor_1
      platform: ESP32 
      board: nodemcu-32s
      includes: 
        - 'CE_BSEC.h'
      libraries:
        - 'BSEC Software Library'
    
    i2c:
      sda: 21
      scl: 22
      scan: True
      id: id_i2c
    
    sensor:
    ## this is the BOSCH Implementation
      - platform: custom
        lambda: |-
          auto IAQSensor = new CE_BSEC();
          App.register_component(IAQSensor);
          return { IAQSensor->TSensor, IAQSensor->PSensor, IAQSensor->HSensor, IAQSensor->AQSensor };
        sensors:
        -  name: "BME680 Temperature"
           unit_of_measurement: 'V'
           accuracy_decimals: 1
        -  name: "BME680 Pressure"
           unit_of_measurement: 'hPa'
           accuracy_decimals: 1
        -  name: "BME680 relative Humidity"
           unit_of_measurement: '%'
           accuracy_decimals: 1
        -  name: "BME680 IAQ"
           accuracy_decimals: 1

     

    Custom sensor CE_BSEC.h

    #include "esphome.h"
    #include "bsec.h"
    
    class CE_BSEC : public PollingComponent, public Sensor {
     public:
      // constructor
      Bsec iaqSensor;
      Sensor *TSensor = new Sensor();
      Sensor *PSensor = new Sensor();
      Sensor *HSensor = new Sensor();
      Sensor *AQSensor = new Sensor();
    
      CE_BSEC() : PollingComponent(60000) { }
    
      void setup() override {
        // This will be called by App.setup()
        iaqSensor.begin(0x77, Wire);
      }
    
      void update() override {
        float Temp = iaqSensor.temperature;
        TSensor->publish_state(Temp);
        
        float Press = iaqSensor.pressure;
        PSensor->publish_state(Press);
        
        float Hum = iaqSensor.humidity;
        HSensor->publish_state(Hum);
        
        float Qual = iaqSensor.iaq;
        AQSensor->publish_state(Qual);
      }
    };

     

    Compiling .pioenvs/multisensor_1/src/main.cpp.o
    Linking .pioenvs/multisensor_1/firmware.elf
    .pioenvs/multisensor_1/lib0fa/libBSEC Software Library_ID6979.a(bsec.cpp.o):(.literal._ZN4Bsec11beginCommonEv+0x4): undefined reference to `bsec_init'
    .pioenvs/multisensor_1/lib0fa/libBSEC Software Library_ID6979.a(bsec.cpp.o):(.literal._ZN4Bsec11beginCommonEv+0x8): undefined reference to `bsec_get_version'
    .pioenvs/multisensor_1/lib0fa/libBSEC Software Library_ID6979.a(bsec.cpp.o): In function `Bsec::beginCommon()':
    /config/multisensor_1/.piolibdeps/multisensor_1/BSEC Software Library_ID6979/src/bsec.cpp:257: undefined reference to `bsec_init'
    .pioenvs/multisensor_1/lib0fa/libBSEC Software Library_ID6979.a(bsec.cpp.o): In function `Bsec::getVersion()':
    /config/multisensor_1/.piolibdeps/multisensor_1/BSEC Software Library_ID6979/src/bsec.cpp:257: undefined reference to `bsec_get_version'
    collect2: error: ld returned 1 exit status
    *** [.pioenvs/multisensor_1/firmware.elf] Error 1

     

    18 REPLIES 18

    ChrisE
    Occasional Visitor

    UPDATE:

    Compiles successfully after adding

    build_flags  = -I .piolibdeps/multisensor_1/BSEC\ Software\ Library_ID6979/src/inc -L .piolibdeps/multisensor_1/BSEC\ Software\ Library_ID6979/src/esp32 -lalgobsec 

    to "platformio.ini" as suggested in another thread here.

    Thank you anyways 🙂

    Cheers,

    Chris

    ceaswaran
    Occasional Visitor

    I am using the same code with Node MCU /ESP8266 board

    While compiling in ESPhome i get the following error

    Linking /data/bme680_boshcode/.pioenvs/bme680_boshcode/firmware.elf/root/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: cannot find -lalgobseccollect2: error: ld returned 1 exit status*** [/data/bme680_boshcode/.pioenvs/bme680_boshcode/firmware.elf] Error 1========================== [FAILED] Took 2.15 seconds ==========================

    how do I resolve?

    handytech
    Community Moderator
    Community Moderator

    It seems that your are using a different board (ESP8266) than above (ESP32), so you may want to create your own topic/thread.

    We would probably need more information to debug your issue, for example your custom build_flags and confirm that your paths are valid (your could check this other thread too), a log of your compiler/linker command, etc. Note that in Arduino, there are extra changes that need to be applied to the file eagle.app.v6.common.ld.h  in the ESP8266 SDK as described here, since we are not familiar with PlatformIO I don't know if this applies to your tools.

    Hello,

    Thanks for the tips with it i am able to compile. However i not able to get value with the custom component this is my log :

    [11:21:00][V][sensor:013]: 'BME680 Temperature': Received new state 0.000000
    [11:21:00][D][sensor:092]: 'BME680 Temperature': Sending state 0.00000 V with 1 decimals of accuracy
    [11:21:00][VV][api.service:120]: send_sensor_state_response: SensorStateResponse {  key: 3640870636  state: 0  missing_state: NO}
    [11:21:00][V][sensor:013]: 'BME680 Pressure': Received new state 0.000000
    [11:21:00][D][sensor:092]: 'BME680 Pressure': Sending state 0.00000 hPa with 1 decimals of accuracy
    [11:21:00][VV][api.service:120]: send_sensor_state_response: SensorStateResponse {  key: 1365279611  state: 0  missing_state: NO}
    [11:21:00][V][sensor:013]: 'BME680 relative Humidity': Received new state 0.000000
    [11:21:00][D][sensor:092]: 'BME680 relative Humidity': Sending state 0.00000 % with 1 decimals of accuracy
    [11:21:00][VV][api.service:120]: send_sensor_state_response: SensorStateResponse {  key: 1973480034  state: 0  missing_state: NO}
    [11:21:00][V][sensor:013]: 'BME680 IAQ': Received new state 0.000000
    [11:21:00][D][sensor:092]: 'BME680 IAQ': Sending state 0.00000  with 1 decimals of accuracy
    [11:21:00][VV][api.service:120]: send_sensor_state_response: SensorStateResponse {  key: 2104753181  state: 0  missing_state: NO

     I dont understand why i change the i2c_adress to 0x76, and my BME680 is working if i use the platform BME680.

    Do you have any idea ?

    Regards,

     

    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