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

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

https://community.platformio.org/t/esp-weird-build-and-upload-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)
{
  Serial.begin(115200);

  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);
  Serial.println(output);
  checkIaqSensorStatus();

  bsec_virtual_sensor_t sensorList[7] = {
    BSEC_OUTPUT_RAW_TEMPERATURE,
    BSEC_OUTPUT_RAW_PRESSURE,
    BSEC_OUTPUT_RAW_HUMIDITY,
    BSEC_OUTPUT_RAW_GAS,
    BSEC_OUTPUT_IAQ_ESTIMATE,
    BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_TEMPERATURE,
    BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_HUMIDITY,
  };

  iaqSensor.updateSubscription(sensorList, 7, BSEC_SAMPLE_RATE_LP);
  checkIaqSensorStatus();

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

// Function that is looped forever
void loop(void)
{
  Serial.print("ESP Free Heap: ");
  Serial.println(ESP.getFreeHeap()>>10);
  if (iaqSensor.run()) { // If new data is available
    Serial.println();
    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 {
    checkIaqSensorStatus();
  }
}

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

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

void errLeds(void)
{
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(100);
  digitalWrite(LED_BUILTIN, LOW);
  delay(100);
}

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

BSEC library version 1.4.6.0
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.

https://github.com/BoschSensortec/BSEC-Arduino-library/issues/15

If someone comes from the official exmaple, please replace

iaqSensor.begin(BME680_I2C_ADDR_PRIMARY, Wire);

with

iaqSensor.begin(BME680_I2C_ADDR_SECONDARY, Wire);