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

    handytech
    Community Moderator
    Community Moderator

    @KKox_ wrote:
    [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

    From your description it isn't clear if you are not able to get proper data from the BME680 or from BSEC, or if the issue comes from something else in your project or platform setup.


    @KKox_ wrote:

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


    I cannot comment about your platform/project, but I can try to clarify the I²C address behavior of the BME680. In I²C mode, the BME680's slave address can take two values: 0x76 or 0x77. The selection is made in hardware, and is based on the value on the SDO pin of the BME680, which must be tied directly to GND or VDDIO:

    • if SDO is tied to GND, the BME680 slave address will be 0x76,
    • if SDO is tied to VDDIO, the BME680 slave address will be 0x77.

    Since the slave address of the BME680 is defined by your hardware connections, you must typically manually inform your software about the decision made and expected address.

    Sorry my explanation was not clear.

    I can get data from my BME680 with ESPhome BME680 default script by defining my BME on 0x76. But using the custom script of this thread i can no get any data. I modify 0x77 by 0x76 but nothing is collected and i dont understand why.. so i tired to get some help from here!

     

    Hello,

    Just a quick update to let you know that it as not a compilation problem or I2C adresses.

    It is actually working with esphome, i just do the config file by myself i was unable to use expample script from this thread.

    Screenshot_2020-07-08 Aperçu - Home Assistant.png

    I just get a lower  relative humidity (33%) than my xiaomi sensor (37.69%) in the same room, but trends are always the same!

    Thanks for help!

     

     

    anupvasudev
    Occasional Visitor

    Hello,

    were you able to solve this problem of always getting "Sending state 0.00000" ?

    I managed to compile esphome with the BSEC library. However I always get 0 values. Any help is much appriciated. I dont see other issues from the logs.

    Hello,

    I have to custom the main.cpp  before compiling to get values. Its not a problem with BSEC Library but with ESPHOME.

    Cheers,

     

     

    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