Update: 2020-05-24

OOP Variante

Esp8266 mit zwei Bme280 als Arduino Tab.

Bme280duo.ino

// ****************************************************************
// Sketch Esp8266 Bme280 Modular(Tab)
// created: Jens Fleischer, 2018-06-03
// last mod: Jens Fleischer, 2018-09-25
// For more information visit: https://fipsok.de
// ****************************************************************
// Hardware: Esp8266, 2 x Bme280, 3 x 4k7 Ohm Widerstand
// SCL an D1 = GPIO5 -->  BME280 1&2
// SDA an D2 = GPIO4 -->  BME280 1
// SDA an D3 = GPIO0 -->  BME280 2
// 4k7 Ohm Widerstand von VCC auf D1
// 4k7 Ohm Widerstand von VCC auf D2
// 4k7 Ohm Widerstand von VCC auf D3
// Getestet auf: Nodemcu, Wemos D1 Mini Pro
/******************************************************************
  Copyright (c) 2018 Jens Fleischer. All rights reserved.

  This file is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.
  This file is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.
*******************************************************************/
// Diese Version von Bme280 sollte als Tab eingebunden werden.
// #include <ESP8266WebServer.h> muss im Haupttab aufgerufen werden
// Die Funktionalität des ESP8266 Webservers ist erforderlich.
// Die Funktion "duoBme();" muss im Setup aufgerufen werden.
// Gib die Höhe in Meter über Meeresspiegel an deinem Standort an
/**************************************************************************************/

#include <Wire.h>
#include <BME280I2C.h>                    // Version 2.3 https://www.github.com/finitespace/BME280

const int hoehe = 163;                    // virtuelle Höhe in Meter über Meeresspiegel an deinem Standort eintragen

struct Bme {
  float temp, hum, pres, sealevel;
  void run(byte SDA, byte SCL) {
    BME280I2C bme;                                          // Standard : Zwangsmodus, Standby-Zeit = 1000 ms
    BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);    // TempUnit_: Celsius, Fahrenheit
    BME280::PresUnit presUnit(BME280::PresUnit_hPa);        // PresUnit_: Pa, hPa, inHg, atm, bar, torr, psi
    Wire.begin(SDA, SCL);
    if (!bme.begin()) {
      Serial.printf("Keinen BME280 Sensor an Pin %d&%d gefunden!\n", SDA, SCL);
    }
    bme.read(pres, temp, hum, tempUnit, presUnit);
    sealevel = pres / pow(1 - ((0.0065 * hoehe) / (temp + (0.0065 * hoehe) + 273.15)), 5.257);
  }
} Bme1, Bme2;

void bme280Duo() {                              // Funktionsaufruf "duoBme();" muss im Setup eingebunden werden
  server.on("/bme280duo", []() {
    Bme1.run(4, 5);                             // Pin für BME280 hier ändern falls erforderlich
    Bme2.run(0, 5);                             // Pin für BME280 hier ändern falls erforderlich
    server.send(200, "application/json", (String)"[\"" + Bme1.temp + "\",\"" + Bme1.hum + "\",\"" + Bme1.sealevel + "\",\"" +
                Bme2.temp + "\",\"" + Bme2.hum + "\",\"" + Bme2.sealevel + "\"]");
  });
}

Die Webseite zum Esp8266 Duo BME280.

bme280duo.html

<!DOCTYPE HTML> <!-- For more information visit: https://fipsok.de -->
<html lang="de">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="style.css">
    <title>Innen und Aussen Klimadaten</title>
    <script>
      function renew() {
        fetch('/bme280duo').then(function (response) {
          return response.json();
        }).then(function (array) {
          document.querySelector('#tempIn').innerHTML = array[0] != 'nan' ? array[0] + '°C' : '---------';
          document.querySelector('#humIn').innerHTML = array[0] != 'nan' ? array[1] + ' %' : 'Fehler';
          document.querySelector('#presIn').innerHTML = array[0] != 'nan' ? array[2] + ' hPa' : '---------';
          document.querySelector('#tempOut').innerHTML = array[0] != 'nan' ? array[3] + '°C' : '---------';
          document.querySelector('#humOut').innerHTML = array[0] != 'nan' ? array[4] + ' %' : 'Fehler';
          document.querySelector('#presOut').innerHTML = array[0] != 'nan' ? array[5] + ' hPa' : '---------';
        });
      }
      document.addEventListener('DOMContentLoaded', renew, setInterval(renew, 1000));
    </script>
    <style>
      div {
		display: flex;
        flex-direction: column;	  
        align-items: center;
        background-color: black;
        margin-bottom: 0.5em;
        width: 290px;
        height: 180px;
        border: .15em solid #aeaeab;
        box-shadow: 5px 10px 5px rgba(0, 0, 0, 0.7);
        border-radius: .2em;
		font-size: 3em;
      }
      span {
        color: #02fc07;
        position: relative;
        top: 0.2em;
        left: .1em;
        font-weight: bold
      }
    </style>
  </head>
  <body>
    <h3>Innenklima</h3>
    <div>
      <span id="tempIn"></span>
      <span id="humIn"></span>
      <span id="presIn"></span>
    </div>
    <h3>Aussenklima</h3>
    <div>
      <span id="tempOut"></span>
      <span id="humOut"></span>
      <span id="presOut"></span>
    </div>
  </body>
</html>

Vorgänger Version Prozedurale Programmierung.

Bme280duo.ino

// ****************************************************************
// Sketch Esp8266 Bme280 Modular(Tab)
// created: Jens Fleischer, 2018-06-03
// last mod: Jens Fleischer, 2018-06-03
// For more information visit: https://fipsok.de
// ****************************************************************
// Hardware: Esp8266, 2 x Bme280, 3 x 4k7 Ohm Widerstand
// SCL an D1 = GPIO5 --> beide BME280
// SDA an D2 = GPIO4
// SDA an D3 = GPIO0
// 4k7 Ohm Widerstand von VCC auf D1
// 4k7 Ohm Widerstand von VCC auf D2
// 4k7 Ohm Widerstand von VCC auf D3
// Getestet auf: Nodemcu, Wemos D1 Mini Pro
/******************************************************************
  Copyright (c) 2018 Jens Fleischer. All rights reserved.

  This file is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.
  This file is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.
*******************************************************************/
// Diese Version von Bme280 sollte als Tab eingebunden werden.
// #include <ESP8266WebServer.h> muss im Haupttab aufgerufen werden
// Die Funktionalität des ESP8266 Webservers ist erforderlich.
// Die Funktion "duoBme();" muss im Setup aufgerufen werden.
// Gib die Höhe in Meter über Meeresspiegel an deinem Standort an
/**************************************************************************************/

#include <Wire.h>
#include <BME280I2C.h>        // Version 2.3 https://www.github.com/finitespace/BME280

void bme280Duo() {       // Funktionsaufruf "duoBme();" muss im Setup eingebunden werden
  server.on("/bme280duo", []() {
    server.send(200, "application/json", bmeData());
  });
}

String bmeData() {
  const int hoehe = 163;        // virtuelle Höhe in Meter über Meeresspiegel an deinem Standort
  float tempIn, tempOut, humIn, humOut, pres, sealevelIn, sealevelOut;
  BME280I2C bme;                    // Standard : Zwangsmodus, Standby-Zeit = 1000 ms
  BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);    //TempUnit_: Celsius, Fahrenheit
  BME280::PresUnit presUnit(BME280::PresUnit_hPa);        //PresUnit_: Pa, hPa, inHg, atm, bar, torr, psi

  Wire.begin(4, 5);
  if (!bme.begin()) {
    Serial.println("Keinen BME280 Sensor an Pin 4&5 gefunden!");
  }
  bme.read(pres, tempIn, humIn, tempUnit, presUnit);
  sealevelIn = (pres / pow(1 - ((0.0065 * hoehe) / (tempIn + (0.0065 * hoehe) + 273.15)), 5.257));    // Berechnung relativer Luftdruck
  Wire.begin(0, 5);
  if (!bme.begin()) {
    Serial.println("Keinen BME280 Sensor an Pin 0&5 gefunden!");
  }
  bme.read(pres, tempOut, humOut, tempUnit, presUnit);
  sealevelOut = (pres / pow(1 - ((0.0065 * hoehe) / (tempOut + (0.0065 * hoehe) + 273.15)), 5.257));
  return (String)"[\"" + tempIn + "\",\"" + humIn + "\",\"" + sealevelIn + "\",\"" + tempOut + "\",\"" + humOut + "\",\"" + sealevelOut + "\"]";
}