Postlad/Guides/ESP32 BME280 weather station with an online dashboard

ESP32 BME280 weather station with an online dashboard

A BME280 measures temperature, air pressure and humidity on one small I2C board. Wired to an ESP32, it becomes a weather station that sends one HTTP GET a minute and fills a live chart you can share or embed. No MQTT broker, no certificate bundle, no server of your own.

ESP32 DevKit and BME280 wiringA BME280 breakout connects VIN to ESP32 3V3, GND to GND, SCL to GPIO22 and SDA to GPIO21.ESP32 DevKitBME280VINGNDSCLSDA3V3GNDGPIO22 · SCLGPIO21 · SDA
Classic ESP32 DevKit pins. Other ESP32 boards put I2C on different pins; see the wiring notes below.

Reviewed, not yet bench-tested on this exact board and sensor combination.

The program on this page is the one the Postlad setup wizard produces. At app.postlad.com/setup you can choose your board and sensor, get this program with your key filled in, and skip the copy-and-paste of the key.

Parts

  • ESP32 development board (a classic ESP32 DevKit for the pins shown here)
  • BME280 breakout board, 3.3 V or with an onboard regulator
  • Four jumper wires
  • USB cable and a steady USB power supply
  • Arduino IDE 2.x with the ESP32 board package
  • Libraries Adafruit BME280 Library and Adafruit Unified Sensor
  • Free Postlad account and a stream write key
  • For outdoor use: a radiation shield and a separate weatherproof box for the ESP32

Wiring

BME280 pinESP32 DevKit
VIN (or VCC)3V3
GNDGND
SCLGPIO22
SDAGPIO21

GPIO21 and GPIO22 are the default I2C pins on a classic ESP32, so the program does not name them. ESP32-S3, ESP32-C3 and many small boards use other defaults. If yours does, either wire to that board's default SDA and SCL, or add Wire.setPins(sdaPin, sclPin); as the first line of setup().

Power the breakout from 3V3. Some bare BME280 boards have no regulator and are 3.3 V only. Boards with six pins (CSB and SDO as well) can also run over SPI; for I2C leave CSB unconnected or tied high, as the board's sheet says.

Address 0x76 or 0x77

A BME280 answers on one of two I2C addresses, chosen by its SDO pin. Many inexpensive breakouts ship at 0x76; Adafruit's own board uses 0x77. You do not need to know which: the program tries 0x76 first and then 0x77. If neither answers, it prints BME280 not found at 0x76 or 0x77 and sends nothing until the sensor is fixed and the board is reset.

BME280 or BMP280?

BME280 and BMP280 boards look identical and are sometimes sold under each other's name. The BMP280 measures temperature and pressure only. It has no humidity sensor at all.

The quick check is the metal can on the board: the BME280 is close to square, the BMP280 is a longer rectangle. The certain check is the chip ID, which the Adafruit library reads at start-up: it expects a BME280 and refuses anything else. So if a correctly wired board says the BME280 was not found, it is probably a BMP280. Go back to the wizard and choose BMP280 instead; you will log temperature and pressure, without humidity.

Complete program

  1. Install the Arduino IDE and the ESP32 board package.
  2. Install the libraries Adafruit BME280 Library and Adafruit Unified Sensor from the Library Manager.
  3. Wire it up as above.
  4. Make a new sketch, paste the program into the main tab, and add a second tab called secrets.h.
  5. Put your Wi-Fi name and password, and your write key, in secrets.h.
  6. Choose the board and the port, then press Upload.
  7. Open the serial monitor at 115200 baud.
  8. Open your stream.
cpp
// ESP32 -> Postlad
//
// Made by app.postlad.com/setup. Two things to change, both in secrets.h:
// your Wi-Fi name and your Wi-Fi password. Nothing in THIS file needs editing.
//
// Readings appear at https://app.postlad.com/streams
//   BME280 weather sensor -> f1 temperature, f2 pressure, f3 humidity
//
// Plain http:// is deliberate and supported. A board with no room for a
// certificate store still works, which is the whole point of this service.

#include <WiFi.h>
#include <HTTPClient.h>
#include <Wire.h>
#include <Adafruit_BME280.h>
#include "secrets.h"

const char* POSTLAD_URL = "http://api.postlad.com/u";
const char* STREAM_PAGE = "https://app.postlad.com/streams";
const unsigned long SEND_INTERVAL_MS = 60000UL;

WiFiClient client;

Adafruit_BME280 bme;
bool bmeFound = false;

void connectWiFi() {
  if (WiFi.status() == WL_CONNECTED) return;
  Serial.print("Joining ");
  Serial.println(WIFI_SSID);
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.print("\nJoined. This board is ");
  Serial.println(WiFi.localIP());
}

// One attempt. Returns true only when Postlad stored the reading.
bool sendOnce(const String& url) {
  HTTPClient http;
  if (!http.begin(client, url)) {
    Serial.println("Could not start the request.");
    return false;
  }
  int status = http.GET();
  String reply = http.getString();
  http.end();
  reply.trim();
  if (status == 200) {
    Serial.print("stored -> ");
    Serial.println(reply);
    return true;
  }
  Serial.print("not stored (HTTP ");
  Serial.print(status);
  Serial.print("): ");
  Serial.println(reply);
  return false;
}

void setup() {
  Serial.begin(115200);
  delay(300);
  Serial.println();
  Serial.print("Your readings will appear at ");
  Serial.println(STREAM_PAGE);
  bmeFound = bme.begin(0x76) || bme.begin(0x77);
  if (!bmeFound) {
    Serial.println("BME280 not found at 0x76 or 0x77. Check SDA and SCL, then press reset.");
  }
  connectWiFi();
}

void loop() {
  connectWiFi();

  if (!bmeFound) {
    Serial.println("No BME280, so nothing is sent. Check SDA and SCL, then press reset.");
    delay(2000);
    return;
  }
  float bmeTemp = bme.readTemperature();
  float bmePress = bme.readPressure() / 100.0F;
  float bmeHum = bme.readHumidity();

  String url = String(POSTLAD_URL) + "?k=" + POSTLAD_KEY
             + "&f1=" + String(bmeTemp, 1)
             + "&f2=" + String(bmePress, 1)
             + "&f3=" + String(bmeHum, 0)
             ;

  // Three tries, waiting longer each time. A router that is rebooting takes
  // a few seconds; giving up after one attempt loses a reading for nothing.
  unsigned long backoff = 2000;
  for (int attempt = 1; attempt <= 3; attempt++) {
    if (sendOnce(url)) {
      break;
    }
    if (attempt < 3) {
      delay(backoff);
      backoff = backoff * 2;
    }
  }

  delay(SEND_INTERVAL_MS);
}

The second file holds everything private:

cpp
#pragma once
// secrets.h — the only file with anything private in it.
//
// Keep this file off forums, out of screenshots and out of shared folders.
// The program file beside it can be pasted anywhere safely.

// Type your own Wi-Fi name and password between the quotes. 2.4 GHz only.
const char* WIFI_SSID     = "YOUR_WIFI_NAME";
const char* WIFI_PASSWORD = "YOUR_WIFI_PASSWORD";

// Your Postlad write key. It can only add readings to one stream — it cannot
// read anything, change anything, or reach your account.
const char* POSTLAD_KEY   = "YOUR_KEY";

A working board prints something like this once a minute. ok 3 means three fields were taken.

text
Your readings will appear at https://app.postlad.com/streams
Joining YOUR_WIFI_NAME
....
Joined. This board is 192.168.1.42
stored -> ok 3

If a request fails, the program tries twice more, waiting 2 and then 4 seconds, and prints the server's sentence each time. A reply that is not 200 means the reading was not stored.

Set up the fields

On the stream page, name the fields so the chart, CSV export and share page read properly:

FieldNameUnitDecimals
f1Temperature°C1
f2PressurehPa1
f3Humidity%0

Names and units change how the data is shown. They do not change what the device sends. Fields go up to f16, so there is room for a rain gauge or wind sensor later.

Station pressure and sea-level pressure

The BME280 reports station pressure: the actual air pressure where the sensor sits. Weather forecasts quote sea-level pressure, which is station pressure corrected as if the station were at sea level, so that places at different heights can be compared. Pressure falls by roughly 12 hPa for every 100 m of height near the ground, so a station at 300 m reads about 35 hPa below the forecast figure. Neither number is wrong.

A common reduction, using the station's height h in metres and the air temperature T in °C, is:

text
P0 = P × (1 − 0.0065·h / (T + 0.0065·h + 273.15)) ^ −5.257

The Adafruit library has a simpler version built in, based on the standard atmosphere and without a temperature term. To log both numbers, keep f2 as the raw station pressure and send sea-level pressure in f4. In loop(), after bmePress is read:

cpp
  const float ALTITUDE_M = 120.0;  // height of the sensor above sea level
  float seaLevel = bme.seaLevelForAltitude(ALTITUDE_M, bmePress);

and add + "&f4=" + String(seaLevel, 1) to the URL. Be honest with yourself about what that number is. It is an estimate from a standard-atmosphere model, it depends on the altitude you typed in, and national weather services use their own reduction methods. Expect a small, steady offset from the nearest official station; compare over a few calm days rather than chasing it. The BME280's datasheet gives its absolute pressure accuracy as about ±1 hPa, so offsets of that size are the sensor, not the formula.

Outdoor placement

Most home weather stations measure the sun and the wall more than the air. A few rules make a large difference:

  • Use a radiation shield. A stack of white, louvred plates (a small Stevenson screen) keeps direct and reflected sunlight off the sensor while letting air through. A sealed box reads high in sunshine and holds humidity for hours.
  • Keep the ESP32 out of the shield. The board and its regulator are warm. Put them in a separate weatherproof box and run a short four-wire cable to the BME280.
  • Mind the height and the surroundings. About 1.25 to 2 m above grass, in shade, away from walls, paving, vents and windows.
  • Leave drip loops on every cable and let any box drain at the bottom.
  • Expect condensation. Humidity near 100% on a clear night is normal. A sensor that reads 100% for days has probably been wetted and needs to dry out.

The Adafruit library runs the BME280 continuously by default, which warms it slightly. Bosch's datasheet suggests forced mode with no oversampling for weather monitoring at one sample a minute. If your temperature runs high indoors next to a reference thermometer, this optional change takes one measurement per loop instead. Add the first statement to setup() after the line that sets bmeFound, and the second at the top of loop() before the readings:

cpp
  bme.setSampling(Adafruit_BME280::MODE_FORCED,
                  Adafruit_BME280::SAMPLING_X1,  // temperature
                  Adafruit_BME280::SAMPLING_X1,  // pressure
                  Adafruit_BME280::SAMPLING_X1,  // humidity
                  Adafruit_BME280::FILTER_OFF);

  bme.takeForcedMeasurement();

Sending interval and the free plan

Weather changes slowly. The program sends every 60 seconds, which is plenty for temperature, pressure and humidity.

IntervalReadings in a 31-day month, one streamFits Free (100,000 a month per account)
Every 30 s89,280Yes, one stream
Every 60 s44,640Yes, two streams

The Free plan gives you 2 streams and 100,000 readings a month across the account, and accepts at most 1 reading every 5 seconds per stream. An outdoor station and an indoor room monitor, both at 60 seconds, use 89,280 readings in a 31-day month. One reading carries all three fields, so adding a field does not cost more readings.

To change the interval, edit SEND_INTERVAL_MS in the program; it is in milliseconds.

Share and embed the chart

Each stream has a public link and a secret link; people with the link can view the live chart without an account. You can also embed the chart on your own site (see embed a live sensor chart), combine several streams on one board, and export CSV on every plan.

The write key stays on the device. It never appears in a shared link. If it leaks, for example in a public repository or a forum post, rotate it on the stream page and update secrets.h.

Troubleshooting

The serial monitor says BME280 not found

The program tried both addresses, 0x76 and 0x77, and got no answer. Check that SDA and SCL are not swapped, that the board has 3V3 and GND, and whether it is really a BMP280. Until the sensor answers, the program sends nothing: every couple of seconds it prints No BME280, so nothing is sent. instead, so no made-up readings reach your chart. Fix the wiring, then press the reset button; the program only looks for the sensor at start-up.

Humidity is stuck at 100%

A BME280 stuck at 100% has usually been wet, from rain or condensation, and needs time in dry air. A board with no humidity sensor at all, a BMP280, never gets this far: the program reports it as not found at start-up.

Temperature reads a few degrees high

Heat from the ESP32, its regulator or the sun is reaching the sensor. Move the breakout away from the board on a short cable, use a radiation shield outdoors, and consider forced mode as shown above.

Pressure is lower than the forecast

You are looking at station pressure. See station pressure and sea-level pressure.

The HTTP status is negative

A negative number comes from the ESP32's HTTP client, not from the server: no route, a DNS failure or a timeout. Check that the board joined Wi-Fi; the ESP32 works on 2.4 GHz networks only.

The server replies 429

Readings are arriving faster than the stream accepts. Raise SEND_INTERVAL_MS. The reply says the reading was not stored.

FAQ

Can an ESP32 send BME280 readings to the cloud without MQTT?

Yes. One HTTP GET per reading is enough for a weather station. The device sends temperature, pressure and humidity as f1, f2 and f3 and gets a one-line reply saying whether they were stored.

How do I tell a BME280 from a BMP280?

The BMP280 has no humidity sensor and usually a longer, rectangular metal can, while the BME280 can is close to square. The Adafruit BME280 library checks the chip ID at start-up and will not accept a BMP280.

Why is my pressure lower than the weather forecast says?

The sensor reports station pressure at its own height. Forecasts quote sea-level pressure. Correct for your altitude, roughly 12 hPa per 100 m near the ground, or log both values in separate fields.

How often should a weather station send readings?

Once a minute is plenty for temperature, pressure and humidity. At 60 seconds one stream uses 44,640 readings in a 31-day month, so two such streams fit within the free plan's 100,000 readings a month.

How long does Postlad keep the readings?

On the Free plan: every reading kept at full detail for 30 days, then an hourly minimum, maximum and average for 12 months.

Can I put the weather chart on my own website?

Yes. Every stream can be shared through a public or secret link, and the live chart can be embedded in a web page. Viewers do not need an account, and the write key is never part of the link.

Create the stream

Create a free account, make a stream, and either paste its write key into secrets.h or let the setup wizard fill it in for you.

Create your free account →

Sources and verification