text: 
  #include <Wire.h>
  #include <SPI.h>
  #include <Adafruit_Sensor.h>
  #include "Adafruit_BME680.h"
  
  // Project spesific include
  
  #include "SensorMonitor.h"
  
  #include "bme680.h"
  #include "jsondocdb.h"
  
  // SensorID for the BME680
  
  
  Adafruit_BME680 bme; // I2C
  
  
  String addSensorPayload(String payload,String sensorName,int sensorValue)
  {
    return("{\"sensorname\":\""+sensorName+"\",\"sensorvalue\":\""+sensorValue+"\"}");
  }
  
  
  void sensorBME680(String sensorId,boolean setupSensor, boolean readSensor, boolean updateCloud){
    //if (setupSensor) BME680init(sensorId,updateCloud);
    if (readSensor) BME680read(sensorId,updateCloud); 
  }
  
  boolean BME680init(String sensorId,boolean updateCloud) {
    Serial.println(F("BME680 init"));
  
    if (!bme.begin()) {
      Serial.println("Could not find a valid BME680 sensor, check wiring!");
  
       if (updateCloud){
          postCloud(sensorId,"BME680 ERROR",0);
       }
      return (false);
    }
  
    // Set up oversampling and filter initialization
    bme.setTemperatureOversampling(BME680_OS_8X);
    bme.setHumidityOversampling(BME680_OS_2X);
    bme.setPressureOversampling(BME680_OS_4X);
    bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
    bme.setGasHeater(320, 150); // 320*C for 150 ms
    Serial.println ("BME680 ready");
    return(true);
  }
  
  void BME680read(String sensorId,boolean updateCloud) {
  
    if (! bme.performReading()) {
      Serial.println("Failed to perform reading :(");
       if (updateCloud){
          postCloud(sensorId,"BME680 ERROR",1);
       }
      return;
    }
    Serial.print("Temperature = ");
    Serial.print(bme.temperature);
    Serial.println(" *C");
  
    Serial.print("Pressure = ");
    Serial.print(bme.pressure / 100.0);
    Serial.println(" hPa");
  
    Serial.print("Humidity = ");
    Serial.print(bme.humidity);
    Serial.println(" %");
  
    Serial.print("Gas = ");
    Serial.print(bme.gas_resistance / 1000.0);
    Serial.println(" KOhms");
  
    Serial.print("Approx. Altitude = ");
    Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
    Serial.println(" m");
    Serial.print("Gas = ");
  
    Serial.print(bme.gas_resistance / 1000.0);
    Serial.println(" KOhms");
  
    Serial.println();
   
    if (updateCloud){
      
      float temp=bme.temperature;
      temp=temp*1000;
      int tempi=(int) temp;
  
        String payload="{\"sensortype\":\"BME680\",\"objectname\":\""+sensorId+"\",\"sensordata\":[";
        payload=payload+addSensorPayload(payload,"TempMC",tempi)+",";
        payload=payload+addSensorPayload(payload,"Pres",bme.pressure/100)+",";
        payload=payload+addSensorPayload(payload,"Hum",bme.humidity)+",";
        payload=payload+addSensorPayload(payload,"AirQ",bme.gas_resistance);
        payload=payload+"]}"; 
        postJSONDocument(payload);
  
    }
  }
  