Arduino Builder, precompiled library issue, BME680, BSEC - ESP32 Arduino?

This is in connection to another post I started about ESP build issues

on a project I am working on. It involves integrating a BME680 sensor into the hardware.
It is a Temperature, Pressure and humidity sensor with a IAQ (Indoor Air Quality) output.

Bosch provide a header and source file for interacting with the sensor, but only for temperature, pressure and humidity.

To extract the IAQ value however, the firmware source needs to be linked against a precompiled library that Bosch provides. The also provide a library for the Arduino framework that does most of the heavy lifting.
This is the GitHub page for the Arduino library

And this is the BSEC binaries themselves

Now platformio provides a easy way to specify the “build_flags” to pass the path and library to link into the final firmware.
I tried compiling the basic example sketch in the library

#include "bsec.h"

// Helper functions declarations
void checkIaqSensorStatus(void);
void errLeds(void);

// Create an object of the class Bsec
Bsec iaqSensor;

String output;

// Entry point for the example
void setup(void)

  iaqSensor.begin(BME680_I2C_ADDR_SECONDARY, Wire);
  output = "\nBSEC library version " + String(iaqSensor.version.major) + "." + String(iaqSensor.version.minor) + "." + String(iaqSensor.version.major_bugfix) + "." + String(iaqSensor.version.minor_bugfix);

  bsec_virtual_sensor_t sensorList[7] = {

  iaqSensor.updateSubscription(sensorList, 7, BSEC_SAMPLE_RATE_LP);

  // Print the header
  output = "Timestamp [ms], raw temperature [°C], pressure [hPa], raw relative humidity [%], gas [Ohm], IAQ, IAQ accuracy, temperature [°C], relative humidity [%]";

// Function that is looped forever
void loop(void)
  Serial.print("ESP Free Heap: ");
  if ( { // If new data is available
    Serial.println("rTemperature: " + String(iaqSensor.rawTemperature));
    Serial.println("Pressure: " + String(iaqSensor.pressure));
    Serial.println("rHumidity: " + String(iaqSensor.rawHumidity));
    Serial.println("Gas Resistance: " + String(iaqSensor.gasResistance));
    Serial.println("IAQ: " + String(iaqSensor.iaqEstimate));
    Serial.println("IAQ Accuracy: " + String(iaqSensor.iaqAccuracy));
    Serial.println("cTemperature: " + String(iaqSensor.temperature));
    Serial.println("cHumidity: " + String(iaqSensor.humidity));                
//    output = String(millis());
//    output += ", " + String(iaqSensor.rawTemperature);
//    output += ", " + String(iaqSensor.pressure);
//    output += ", " + String(iaqSensor.rawHumidity);
//    output += ", " + String(iaqSensor.gasResistance);
//    output += ", " + String(iaqSensor.iaqEstimate);
//    output += ", " + String(iaqSensor.iaqAccuracy);
//    output += ", " + String(iaqSensor.temperature);
//    output += ", " + String(iaqSensor.humidity);
//    Serial.println(output);
  } else {

// Helper function definitions
void checkIaqSensorStatus(void)
  if (iaqSensor.status != BSEC_OK) {
    if (iaqSensor.status < BSEC_OK) {
      output = "BSEC error code : " + String(iaqSensor.status);
      for (;;)
        errLeds(); /* Halt in case of failure */
    } else {
      output = "BSEC warning code : " + String(iaqSensor.status);

  if (iaqSensor.bme680Status != BME680_OK) {
    if (iaqSensor.bme680Status < BME680_OK) {
      output = "BME680 error code : " + String(iaqSensor.bme680Status);
      for (;;)
        errLeds(); /* Halt in case of failure */
    } else {
      output = "BME680 warning code : " + String(iaqSensor.bme680Status);

void errLeds(void)
  digitalWrite(LED_BUILTIN, HIGH);
  digitalWrite(LED_BUILTIN, LOW);

The program compiles and uploads just fine but always returns an error.
Specifically this error

BSEC library version
Timestamp [ms], raw temperature [°C], pressure [hPa], raw relative humidity [%], gas [Ohm], IAQ, IAQ accuracy, temperature [°C], relative humidity [%]
BSEC error code : -2

This tells me that the bsec archive files have been linked against the firmware source.
Compiling the same example in the Arduino IDE works just fine with the sensor returning the correct values for T/P/H and IAQ. The hardware is the same.
Platformio, however, fails with the above error. It is able to compile, link and create and upload the firmware but gives an error.

The only difference I see between the Arduino IDE and the Platformio method of doing things is the extra Arduino-builder-PR219 as mentioned in the GitHub for instructions.

Any suggestions on how I can get even platformio to successfully work with this library??
I would prefer to stick with Platformio since all our development is already streamlined for pio and we are quite happy and satisfied with it. I would really really like to find a way to fix this in pio and not want to look at Arduino for this one library.

Thanks in advance. :slight_smile:

Okay, never mind.
Got the firmware to run properly.

It was a mistake on my part.

Here is the thread over on GitHub Bosch repo if anyone else runs into a similar issue.

If someone comes from the official exmaple, please replace

iaqSensor.begin(BME680_I2C_ADDR_PRIMARY, Wire);


iaqSensor.begin(BME680_I2C_ADDR_SECONDARY, Wire);