Temperature, Humidity and Atmospheric Pressure Sensor (BME280) - Outdoor [RUA]
Project Overview
The Outdoor Environmental Sensor Project is a low-power autonomous system designed to monitor
temperature, relative humidity, and atmospheric pressure in an outdoor environment.
The system prioritizes energy efficiency, reliability, and long-term autonomy, making it suitable
for continuous operation using standard AA batteries.
An ESP32 microcontroller collects data from a BME280 sensor, transmits the measurements via Wi-Fi
to a Raspberry Pi, and immediately enters deep sleep mode to minimize power consumption.
The Raspberry Pi stores, processes, and exposes the data through a web-based interface. You can see here: https://joelbonifacio.dynip.sapo.pt/electro6.1.html
Fig.1 - Materials: ESP32, BME280, batteries, support for the batteries and cables.
BME280 Technical Specifications
Parameter
Value
Temperature Range
-40 °C to +85 °C
Temperature Accuracy
±1.0 °C
Humidity Range
0 – 100 % RH
Humidity Accuracy
±3 % RH
Response Time
1 second
Hysteresis
±1% RH
Pressure Range
300 – 1100 hPa
Absolute Accuracy
±1 hPa
Relative Accuracy
±0.12 hPa (equivalent to ±1 meter in altitude)
RMS Noise
0.2 Pa
Communication Interface
SPI
Operating Voltage
3.3 V
Communication Interface
I2C (Gravity Connector) or SPI
ESP32 ↔ BME280 Wiring Diagram (SPI)
Here is the schematic of the circuit.
Fig.2 - Schematic of the circuit.
FireBeetle 2 ESP32-C6 Firmware (Low Power Mode + SPI)
// ----- CONFIGURAÇÃO HARDWARE -----
// O fio VCC do sensor BME280 liga AQUI, e não nos 3.3V fixos.
// Isto permite desligar o sensor e o LED vermelho completamente.
#define SENSOR_POWER_PIN 14
#define BME_CS 21
#define SPI_SCK 18
#define SPI_MISO 19
#define SPI_MOSI 23
// Battery voltage: built-in ADC on pin 0 (onboard resistive divider)
#define BATTERY_ADC_PIN 0
Adafruit_BME280 bme(BME_CS);
// ----- CONFIGURAÇÃO WIFI -----
const char* ssid = "...";
const char* password = "...";
const char* serverURL = "https://.../api/rua/sensor";
const char* serverBatchURL = "https://.../api/rua/sensor/batch";
// ----- SLEEP -----
const uint64_t SLEEP_MINUTES = 15;
const uint64_t SLEEP_MICROS = SLEEP_MINUTES * 60ULL * 1000000ULL;
void setup() {
// ------------------------------------------------
// STEP 1: POWER ON AND READ SENSOR (Wi-Fi still off!)
// ------------------------------------------------
pinMode(SENSOR_POWER_PIN, OUTPUT);
digitalWrite(SENSOR_POWER_PIN, HIGH);
delay(10);
SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI);
if (!bme.begin(BME_CS)) {
goToSleep();
}
bme.setSampling(Adafruit_BME280::MODE_FORCED, ...);
bme.takeForcedMeasurement();
float temp = bme.readTemperature();
float hum = bme.readHumidity();
float pres = bme.readPressure() / 100.0F;
float volt = (analogReadMilliVolts(BATTERY_ADC_PIN) * 2) / 1000.0F;
// *** CRITICAL POWER SAVING ***
digitalWrite(SENSOR_POWER_PIN, LOW);
// ------------------------------------------------
// STEP 2: CONNECT WI-FI (DHCP, router-reserved IP)
// ------------------------------------------------
WiFi.mode(WIFI_STA);
WiFi.persistent(false); // avoid rewriting credentials to flash every cycle
WiFi.begin(ssid, password);
// ... timeout 10s ...
if (WiFi.status() == WL_CONNECTED) {
// ------------------------------------------------
// STEP 3: SEND DATA (HTTPS with WiFiClientSecure)
// ------------------------------------------------
// ... build JSON {temperature, humidity, pressure, voltage} ...
int response = http.POST(json);
if (response == 200) {
flushQueue(); // send any offline backlog accumulated in LittleFS
}
}
if (!sentLive) {
// Wi-Fi down or server error -> queue reading for later (see Offline Data Buffering)
time_t now = resolveCurrentEpoch(wifiOk, true); // NTP sync on demand
queueReading(now, temp, hum, pres, volt);
}
// ------------------------------------------------
// STEP 4: DEEP SLEEP
// ------------------------------------------------
goToSleep();
}
void goToSleep() {
WiFi.disconnect(true);
WiFi.mode(WIFI_OFF);
esp_sleep_enable_timer_wakeup(SLEEP_MICROS);
esp_deep_sleep_start();
}
void loop() {
// Not needed — the ESP32 wakes from deep sleep by restarting setup()
}
Fig.3 - FireBeetle 2 ESP32-C6 Partial Code. Full source omitted for brevity; includes offline buffering, NTP synchronization, and battery voltage monitoring not shown in full here.
Python Services on Raspberry Pi
Flask API for data ingestion (/api/rua/sensor for real-time readings, /api/rua/sensor/batch for offline backlog — see Offline Data Buffering below);
SQLite database logger;
Data aggregation, statistics, pressure tendency analysis, and battery life forecasting.
Apache Reverse Proxy (electro6.conf)
Apache is configured as a reverse proxy to forward /api/rua requests
to the internal Flask. This covers all sub-routes under that prefix,
including the real-time ingestion endpoint (/api/rua/sensor), the batch endpoint
for offline backlog (/api/rua/sensor/batch), and the read-only data endpoints
consumed by the frontend. This isolates backend services and provides clean, stable URLs.
Offline Data Buffering (LittleFS Persistent Queue)
In the initial version of this project, any reading taken while the Raspberry Pi was unreachable — whether due to a server restart, a network outage, or scheduled maintenance — was silently lost. For an outdoor sensor that may need to operate autonomously for extended periods, this is unacceptable: the most interesting weather data often coincides with the conditions most likely to cause connectivity issues.
The firmware now implements a persistent offline queue using the ESP32's onboard flash memory via LittleFS. When a reading cannot be delivered (either because Wi-Fi is unavailable or the server does not respond with HTTP 200), it is appended to a CSV file stored on flash along with its estimated timestamp. The queue can hold up to 672 readings (~1 week) at the 15-minute interval. Once connectivity is restored and a live reading is successfully acknowledged by the server, the entire backlog is flushed in a single HTTP POST to a dedicated batch endpoint (/api/rua/sensor/batch), and the queue file is deleted only after the server confirms receipt. If the batch delivery itself fails, the file remains intact and retransmission is attempted on the next cycle — no data is ever partially sent or silently discarded.
Timestamping offline readings required solving a non-trivial problem: the ESP32 has no battery-backed real-time clock, so it only knows the current time when it can reach an NTP server. In earlier iterations, the firmware estimated timestamps by counting deep-sleep cycles and multiplying by the nominal 15-minute interval — but the ESP32-C6's default 150 kHz RC oscillator has a frequency tolerance of approximately ±5%, which translates to roughly 9 minutes of drift over 3 hours. The final implementation avoids this entirely: whenever a reading needs to be queued and Wi-Fi is available, the firmware performs an on-demand NTP synchronization at that exact moment, producing an accurate timestamp with no accumulated drift. The internal RTC clock (which does persist across deep-sleep resets) is used as a fallback only when Wi-Fi itself is unavailable — an uncommon scenario, since the most frequent failure mode is server downtime with Wi-Fi still operational.
On the backend, the Flask API exposes a /api/rua/sensor/batch endpoint that accepts an array of readings, each with its own device-side timestamp, and inserts them into the same SQLite table used by real-time readings. Because all existing queries (charts, statistics, pressure tendency, battery forecast) use ORDER BY timestamp rather than insertion order, the late-arriving historical data integrates seamlessly — no frontend changes were required.
// Offline queue — partial firmware excerpt (simplified)
#define QUEUE_FILE "/queue.csv"
const int MAX_QUEUE_ENTRIES = 672; // ~1 week at 15 min intervals
// Called when the live POST fails (Wi-Fi down or server error)
void queueReading(time_t epoch, float temp, float hum, float pres, float volt) {
if (epoch == 0) return; // no valid time reference yet
File f = LittleFS.open(QUEUE_FILE, "a");
f.printf("%lu,%.2f,%.2f,%.2f,%.3f\n", (unsigned long)epoch, temp, hum, pres, volt);
f.close();
}
// Called after a successful live POST — sends the entire backlog at once
void flushQueue() {
if (!LittleFS.exists(QUEUE_FILE)) return;
// ... reads all lines, builds a JSON array, POSTs to /api/rua/sensor/batch ...
// ... deletes the file ONLY after HTTP 200 confirmation ...
}
Fig.3b - Offline queue — partial firmware excerpt (simplified). Full source omitted for brevity.
Power Consumption Analysis
Update (November 2026): this first estimate was checked against the sensor's real field data and turned out to be too pessimistic. It predicted 116–167 days, and the batteries have now run for more than 8 months on a single charge. The calculation below is kept as the first estimate (v1); the Empirical Battery Life Validation section explains what was wrong and how it was corrected.
Let's be conservative with these calculations (meaning I will assume the reasonable "worst-case" scenario).
Hardware Data (Datasheets)
Battery: 3x NiMH 2500mAh batteries.
Theoretical Total Capacity: 2500 mAh.
Note: Since the batteries do not discharge to 0V (the ESP32's onboard regulator needs at least ~3.3V to reliably power the chip), we only utilize a fraction of the nominal charge. We will use 2125 useful mAh as a conservative estimate.
ESP32-C6 Consumption (FireBeetle 2):
Wi-Fi On (TX/RX): Average of 180 mA (peaks of 350mA, but the average is lower).
Awake without Wi-Fi (Measuring sensor): ~30 mA.
Deep Sleep: The datasheet says 13 µA, but let's be realistic and assume 25 µA (0.025 mA) to account for small circuit leakages.
BME280 Sensor Consumption:
Measuring: 1 mA (irrelevant as it is very fast).
Sleeping (via GPIO): 0 mA (cut the power at GPIO14).
15-Minute Cycle (900 Seconds)
Let's calculate the "Energy Cost" of each 15-minute cycle. We will use the unit mAs (milliAmpere-seconds), which is the "currency" of energy spent.
Phase 2: Turn on Wi-Fi and Send (DHCP with a router-side reservation)
With a fixed address reserved by the router (no address negotiation), the connection is fast. Let's assume 2.5 seconds in total to connect, send and receive the "OK".
Time: 2.5 seconds.
Consumption: 180 mA.
Cost: \(180 \text{ mA} \times 2.5 \text{ s} = \mathbf{450 \text{ mAs}}\).
Phase 3: Deep Sleep
The rest of the time until completing the 15 minutes.
Time: \(900 \text{ s} - 2.7 \text{ s} = 897.3 \text{ seconds}\).
Consumption: 0.025 mA (25 µA).
Cost: \(0.025 \text{ mA} \times 897.3 \text{ s} = \mathbf{22.4 \text{ mAs}}\).
Total per Cycle and Duration
Total Cost of 1 cycle (15 min):
\(6 + 450 + 22.4 = \mathbf{478.4 \text{ mAs}}\)
Average Consumption per Second (Average Current):
To know the equivalent continuous average current:
\(\text{Days of life} = \frac{4009}{24} \approx \mathbf{167 \text{ days}}\)
Theoretical Result: ~5 and a half months.
The "Reality Factor" — first estimate (v1)
In theory, it gives 167 days. In practice, there are two invisible enemies:
NiMH Battery Self-discharge: Rechargeable batteries lose charge on their own, even sitting in a drawer. Normal batteries lose 10-20% of their charge per month. If they are "Ready to Use" batteries (like Eneloop or IKEA Ladda), they lose much less.
Regulator Efficiency: The FireBeetle has components that convert the battery voltage to 3.3V. This process is not 100% efficient.
First estimate (v1):
Applying a safety margin of 30% for self-discharge and inefficiencies (safety coefficient: 100% - 30% = 70%):
⚠️ Important caveat: this theoretical figure is a calculation from datasheets, not a direct measurement. NiMH batteries have a discharge curve that stays almost flat for most of their life and only drops sharply near the very end (the "knee" of the curve). This means voltage alone, observed over a few weeks or months, cannot confirm or contradict this estimate — the battery can look perfectly healthy for a long time and then decline quickly once it reaches that knee. See the Empirical Battery Life Validation section below, which compares this model with the sensor's real field data and corrects it.
Conclusion of the first estimate (v1)
Something between 3 to 4 guaranteed months (it could reach 5 months if the batteries are of good quality).
This is the massive difference of:
Using DHCP with a router-side IP reservation (avoids hardcoding gateway/DNS while keeping a fixed IP).
Killing the sensor via GPIO (reduces consumption in sleep).
Using Deep Sleep correctly.
Calling WiFi.persistent(false) to prevent the ESP32 from rewriting Wi-Fi credentials to flash on every cycle (reduces write latency and flash wear).
Field data later showed that this conservative estimate was far too pessimistic: see the validation below.
Empirical Battery Life Validation
The calculation above is a theoretical model built from component datasheets. It is a useful first estimate, but it can't be checked by "waiting and watching the voltage" for a few weeks: NiMH batteries keep an almost flat voltage for most of their life and only drop sharply right at the end:
What the Field Data Says
This sensor has been running on a single charge since 15 February 2026: the batteries have never been recharged. The first estimate predicted 116–167 days. The real batteries passed day 116 (11 June) at 3.80 V and day 167 (1 August) at 3.77 V, still on the plateau, and they are at about 3.7 V today. The first estimate was too pessimistic, and it is worth understanding why:
Charge conservation. An average current of 0.53 mA would have drawn about 3,300 mAh in 260 days, more than the 2,500 mAh the cells hold. So the real average current (self-discharge included) has to be below 0.40 mA and, because the voltage is still on the plateau (at most ~85 % of the capacity used), below about 0.34 mA: at least 1.6 times lower than calculated.
Phase 2 decides everything. 450 of the 478 mAs of each cycle (94 %) are the Wi-Fi connection and the HTTPS request, and I had assumed 180 mA on average for 2.5 s, a worst-case figure. The field data forces that average to be at most ~110 mA. The server also measures 897–898 s between consecutive readings, which fits 2–3 s awake per cycle, so the timing looks right and the current is the number that still has to be measured.
Two unmeasured safety factors. The 85 % "useful capacity" and the 30 % "reality factor" stack to 60 %: together they cut the predicted life by 40 % with no measurement behind them. How much a NiMH cell self-discharges depends heavily on the cell type, so it is better treated as a range than as a fixed percentage.
Revised Model (v2)
The model is corrected in two ways. First, the unknowns that decide the result are treated as ranges instead of single numbers: average current 0.18–0.34 mA (self-discharge included), real capacity 2,300–2,600 mAh, and 95–98 % of it delivered before the voltage reaches 3.3 V. Second, only the combinations compatible with what was observed are kept: the batteries are still on the plateau, so they cannot have used more than about 88 % of their capacity. With the data so far this gives a total life of roughly 10 to 17 months on one charge (80 % range). That range will only narrow when the real current is measured (a shunt resistor and an oscilloscope on one 15-minute cycle will replace the Phase 2 assumption with a measurement) and, above all, when the knee finally arrives.
The first version of the live estimator drew a straight line through the last 45 days of voltage and extended it to 3.3 V. That fails for two reasons: the discharge curve is not a line (a flat plateau followed by a knee), and the battery voltage depends on temperature. Every 15 minutes the ESP32 reports its battery voltage and the outdoor temperature, and the server now does the following:
Find the current charge cycle. A new cycle starts when the daily median voltage rises by at least 0.10 V and stays there, or by at least 0.30 V right after a gap in the readings (batteries swapped or recharged).
Compensate for temperature. The voltage moves about 1 mV for every °C (measured on this very database, with a correlation of 0.75–0.96 inside each day). Without correcting it, the weather alone made the 7-day slope swing between −3.9 and +3.1 mV/day, while the real plateau discharge is only −0.4 to −0.7 mV/day. The coefficient k is measured from the data, not assumed:
\(V_c = V - k\,\left(T - 15\ \text{°C}\right)\)
Remove steps that are not discharge. Flashing the firmware or handling the batteries breaks the 15-minute rhythm and can shift the voltage. Such steps are detected only where the rhythm breaks (a real knee never breaks it) and are taken out of the fits. One of 21 mV was found and removed on 18 October 2026.
Plateau phase: an honest range. While the curve is flat, the end date cannot be computed precisely. The charge budget of the revised model is evaluated over all the compatible combinations, and the 10th, 50th and 90th percentiles give the pessimistic end, the calculated value and the optimistic end.
Detect the knee. The knee is declared when the 14-day slope of the compensated voltage reaches −2.5 mV/day (on this plateau it never went below −1.7) or when the compensated voltage drops under 3.62 V (about 1.2 V per cell).
Knee phase: a countdown to 3.3 V. The falling voltage is fitted with an exponential shape, meaning the slope multiplies by e every τ days, on the last 10 and 5 days. The target is the compensated voltage that corresponds to 3.3 V on the coldest recent nights, because cold lowers the voltage temporarily and those nights are the first to shut the sensor down.
\(V_c(t) = a - b\,e^{\,t/\tau}\)
How reliable is the countdown? It was tested on simulated knees of very different shapes (exponential, logarithmic, S-shaped, two-stage) built on top of the real database. The knee was flagged between 4 and 20 days before the cut-off (a sharper knee leaves less warning), the countdown was typically within ±30 % of the true remaining time, and the stated range contained the real end in 80–98 % of the cases. These are simulations: the real knee of these batteries has not been observed yet, and the estimator adapts as it unfolds. When the knee starts, the server also writes an alert file so that recharging the batteries never depends on someone opening this page.
Live Result (calculated from the current database)
Current voltage—
Voltage at 15 °C—
Temperature effect—
Recent slope—
Days since charge—
Phase—
Voltage at 15 °C is the voltage corrected for temperature, so a cold night and a warm afternoon can be compared. Temperature effect is how many millivolts the voltage changes per °C, measured from the data. Recent slope is how fast the corrected voltage is falling (a positive value means a small recovery, for example after a firmware upload).
Loading live data from the database...
Measured discharge since the last charge (daily medians). Grey (thick, behind): raw voltage. Green: voltage corrected to 15 °C. The orange band is the first estimate (116–167 days); the blue band is the live estimate of when the voltage reaches 3.3 V.
Theoretical vs. Empirical — Side by Side
Method
Basis
Result
Reliability
Theoretical v1 (datasheets)
Component current draw × phase durations, from the calculation above
116–167 days
Disproved by the field data: the real batteries went well past 167 days. Too pessimistic (180 mA assumed during Wi-Fi, plus two unmeasured safety factors)
Empirical (live)
Temperature-compensated voltage history and a charge budget with ranges; exponential knee fit once the knee starts
—
A wide, honest range on the plateau; a precise countdown only once the voltage leaves it
The theoretical estimate and the field data disagreed, and the field data is the one that counts: that is why the model above was corrected instead of defended. The next step is to measure the real current of one full cycle, which will turn the largest remaining guess into a measurement.
But why using 3 AA Batteries Instead of 4 Batteries AA?
Three AA NiMH cells give about 3.6 V nominal (the first reading ever logged, right off the charger, was 4.19 V),
which is safely handled by the ESP32 onboard regulator.
Using 4 batteries would raise the voltage to about 5.6 V fresh off the charger (6 V with alkaline cells), exceeding the regulator's optimal input range and increasing thermal dissipation.
SPI Was Mandatory Instead of I²C
During development, the use of I²C combined with active Wi-Fi on the ESP32 caused
intermittent communication failures and bus lockups.
Migrating the BME280 to SPI provided a dedicated, synchronous communication channel, fully eliminating the instability.
Outdoor Weather-Resistant Enclosure For Testing
I bought a waterproof box and made some minor modifications to adapt it to this project.
It has two large holes in the bottom for ventilation, and right above them is the BME280 sensor.
The goal is to prevent water from entering, especially since it's windy and raining heavily here (which is quite common), but at the same time, to avoid interfering with the sensor readings.
I also put a very fine green mesh to prevent insects from getting in and covering the sensor hole.
Now it will be screwed to the outside wall of the house.
P.S. - It will not be exposed directly to sun/rain.
This is the final result:
Fig.4 - Outdoor weather-resistant enclosure I.
Fig.5 - Outdoor weather-resistant enclosure II.
Fig.6 - Outdoor weather-resistant enclosure III.
Fig.7 - Outdoor weather-resistant enclosure IV.
Fig.8 - Outdoor weather-resistant enclosure on the wall below the balcony.
Temperature, Humidity and Atmospheric Pressure Sensor (BME280) - Outdoor [RUA]
Project Overview
The Outdoor Environmental Sensor Project is a low-power autonomous system designed to monitor temperature, relative humidity, and atmospheric pressure in an outdoor environment. The system prioritizes energy efficiency, reliability, and long-term autonomy, making it suitable for continuous operation using standard AA batteries.
An ESP32 microcontroller collects data from a BME280 sensor, transmits the measurements via Wi-Fi to a Raspberry Pi, and immediately enters deep sleep mode to minimize power consumption. The Raspberry Pi stores, processes, and exposes the data through a web-based interface. You can see here: https://joelbonifacio.dynip.sapo.pt/electro6.1.html
Hardware Components
Fig.1 - Materials: ESP32, BME280, batteries, support for the batteries and cables.
BME280 Technical Specifications
ESP32 ↔ BME280 Wiring Diagram (SPI)
Here is the schematic of the circuit.
Fig.2 - Schematic of the circuit.
FireBeetle 2 ESP32-C6 Firmware (Low Power Mode + SPI)
Fig.3 - FireBeetle 2 ESP32-C6 Partial Code. Full source omitted for brevity; includes offline buffering, NTP synchronization, and battery voltage monitoring not shown in full here.
Python Services on Raspberry Pi
/api/rua/sensorfor real-time readings,/api/rua/sensor/batchfor offline backlog — see Offline Data Buffering below);Apache Reverse Proxy (electro6.conf)
Apache is configured as a reverse proxy to forward
/api/ruarequests to the internal Flask. This covers all sub-routes under that prefix, including the real-time ingestion endpoint (/api/rua/sensor), the batch endpoint for offline backlog (/api/rua/sensor/batch), and the read-only data endpoints consumed by the frontend. This isolates backend services and provides clean, stable URLs.Offline Data Buffering (LittleFS Persistent Queue)
In the initial version of this project, any reading taken while the Raspberry Pi was unreachable — whether due to a server restart, a network outage, or scheduled maintenance — was silently lost. For an outdoor sensor that may need to operate autonomously for extended periods, this is unacceptable: the most interesting weather data often coincides with the conditions most likely to cause connectivity issues.
The firmware now implements a persistent offline queue using the ESP32's onboard flash memory via LittleFS. When a reading cannot be delivered (either because Wi-Fi is unavailable or the server does not respond with HTTP 200), it is appended to a CSV file stored on flash along with its estimated timestamp. The queue can hold up to 672 readings (~1 week) at the 15-minute interval. Once connectivity is restored and a live reading is successfully acknowledged by the server, the entire backlog is flushed in a single HTTP POST to a dedicated batch endpoint (
/api/rua/sensor/batch), and the queue file is deleted only after the server confirms receipt. If the batch delivery itself fails, the file remains intact and retransmission is attempted on the next cycle — no data is ever partially sent or silently discarded.Timestamping offline readings required solving a non-trivial problem: the ESP32 has no battery-backed real-time clock, so it only knows the current time when it can reach an NTP server. In earlier iterations, the firmware estimated timestamps by counting deep-sleep cycles and multiplying by the nominal 15-minute interval — but the ESP32-C6's default 150 kHz RC oscillator has a frequency tolerance of approximately ±5%, which translates to roughly 9 minutes of drift over 3 hours. The final implementation avoids this entirely: whenever a reading needs to be queued and Wi-Fi is available, the firmware performs an on-demand NTP synchronization at that exact moment, producing an accurate timestamp with no accumulated drift. The internal RTC clock (which does persist across deep-sleep resets) is used as a fallback only when Wi-Fi itself is unavailable — an uncommon scenario, since the most frequent failure mode is server downtime with Wi-Fi still operational.
On the backend, the Flask API exposes a
/api/rua/sensor/batchendpoint that accepts an array of readings, each with its own device-side timestamp, and inserts them into the same SQLite table used by real-time readings. Because all existing queries (charts, statistics, pressure tendency, battery forecast) useORDER BY timestamprather than insertion order, the late-arriving historical data integrates seamlessly — no frontend changes were required.Fig.3b - Offline queue — partial firmware excerpt (simplified). Full source omitted for brevity.
Power Consumption Analysis
Update (November 2026): this first estimate was checked against the sensor's real field data and turned out to be too pessimistic. It predicted 116–167 days, and the batteries have now run for more than 8 months on a single charge. The calculation below is kept as the first estimate (v1); the Empirical Battery Life Validation section explains what was wrong and how it was corrected.
Let's be conservative with these calculations (meaning I will assume the reasonable "worst-case" scenario).
Hardware Data (Datasheets)
ESP32-C6 Consumption (FireBeetle 2):
BME280 Sensor Consumption:
15-Minute Cycle (900 Seconds)
Let's calculate the "Energy Cost" of each 15-minute cycle. We will use the unit mAs (milliAmpere-seconds), which is the "currency" of energy spent.
Time: 0.2 seconds (it's very fast).
Consumption: 30 mA.
Cost: \(30 \text{ mA} \times 0.2 \text{ s} = \mathbf{6 \text{ mAs}}\).
With a fixed address reserved by the router (no address negotiation), the connection is fast. Let's assume 2.5 seconds in total to connect, send and receive the "OK".
Time: 2.5 seconds.
Consumption: 180 mA.
Cost: \(180 \text{ mA} \times 2.5 \text{ s} = \mathbf{450 \text{ mAs}}\).
The rest of the time until completing the 15 minutes.
Time: \(900 \text{ s} - 2.7 \text{ s} = 897.3 \text{ seconds}\).
Consumption: 0.025 mA (25 µA).
Cost: \(0.025 \text{ mA} \times 897.3 \text{ s} = \mathbf{22.4 \text{ mAs}}\).
Total per Cycle and Duration
Total Cost of 1 cycle (15 min):
Average Consumption per Second (Average Current):
To know the equivalent continuous average current:
This means that, in practice, the system behaves as if it were consuming only 0.53 mA constantly.
Final Calculation: How Long Does It Last?
We have 2125 mAh (useful capacity). The system consumes 0.53 mA.
The "Reality Factor" — first estimate (v1)
In theory, it gives 167 days. In practice, there are two invisible enemies:
First estimate (v1):
Applying a safety margin of 30% for self-discharge and inefficiencies (safety coefficient: 100% - 30% = 70%):
⚠️ Important caveat: this theoretical figure is a calculation from datasheets, not a direct measurement. NiMH batteries have a discharge curve that stays almost flat for most of their life and only drops sharply near the very end (the "knee" of the curve). This means voltage alone, observed over a few weeks or months, cannot confirm or contradict this estimate — the battery can look perfectly healthy for a long time and then decline quickly once it reaches that knee. See the Empirical Battery Life Validation section below, which compares this model with the sensor's real field data and corrects it.
Conclusion of the first estimate (v1)
Something between 3 to 4 guaranteed months (it could reach 5 months if the batteries are of good quality).
This is the massive difference of:
WiFi.persistent(false)to prevent the ESP32 from rewriting Wi-Fi credentials to flash on every cycle (reduces write latency and flash wear).Field data later showed that this conservative estimate was far too pessimistic: see the validation below.
Empirical Battery Life Validation
The calculation above is a theoretical model built from component datasheets. It is a useful first estimate, but it can't be checked by "waiting and watching the voltage" for a few weeks: NiMH batteries keep an almost flat voltage for most of their life and only drop sharply right at the end:
What the Field Data Says
This sensor has been running on a single charge since 15 February 2026: the batteries have never been recharged. The first estimate predicted 116–167 days. The real batteries passed day 116 (11 June) at 3.80 V and day 167 (1 August) at 3.77 V, still on the plateau, and they are at about 3.7 V today. The first estimate was too pessimistic, and it is worth understanding why:
Revised Model (v2)
The model is corrected in two ways. First, the unknowns that decide the result are treated as ranges instead of single numbers: average current 0.18–0.34 mA (self-discharge included), real capacity 2,300–2,600 mAh, and 95–98 % of it delivered before the voltage reaches 3.3 V. Second, only the combinations compatible with what was observed are kept: the batteries are still on the plateau, so they cannot have used more than about 88 % of their capacity. With the data so far this gives a total life of roughly 10 to 17 months on one charge (80 % range). That range will only narrow when the real current is measured (a shunt resistor and an oscilloscope on one 15-minute cycle will replace the Phase 2 assumption with a measurement) and, above all, when the knee finally arrives.
Methodology: Temperature-Compensated, Two-Phase Estimator
The first version of the live estimator drew a straight line through the last 45 days of voltage and extended it to 3.3 V. That fails for two reasons: the discharge curve is not a line (a flat plateau followed by a knee), and the battery voltage depends on temperature. Every 15 minutes the ESP32 reports its battery voltage and the outdoor temperature, and the server now does the following:
How reliable is the countdown? It was tested on simulated knees of very different shapes (exponential, logarithmic, S-shaped, two-stage) built on top of the real database. The knee was flagged between 4 and 20 days before the cut-off (a sharper knee leaves less warning), the countdown was typically within ±30 % of the true remaining time, and the stated range contained the real end in 80–98 % of the cases. These are simulations: the real knee of these batteries has not been observed yet, and the estimator adapts as it unfolds. When the knee starts, the server also writes an alert file so that recharging the batteries never depends on someone opening this page.
Live Result (calculated from the current database)
Voltage at 15 °C is the voltage corrected for temperature, so a cold night and a warm afternoon can be compared. Temperature effect is how many millivolts the voltage changes per °C, measured from the data. Recent slope is how fast the corrected voltage is falling (a positive value means a small recovery, for example after a firmware upload).
Measured discharge since the last charge (daily medians). Grey (thick, behind): raw voltage. Green: voltage corrected to 15 °C. The orange band is the first estimate (116–167 days); the blue band is the live estimate of when the voltage reaches 3.3 V.
Theoretical vs. Empirical — Side by Side
The theoretical estimate and the field data disagreed, and the field data is the one that counts: that is why the model above was corrected instead of defended. The next step is to measure the real current of one full cycle, which will turn the largest remaining guess into a measurement.
But why using 3 AA Batteries Instead of 4 Batteries AA?
Three AA NiMH cells give about 3.6 V nominal (the first reading ever logged, right off the charger, was 4.19 V), which is safely handled by the ESP32 onboard regulator. Using 4 batteries would raise the voltage to about 5.6 V fresh off the charger (6 V with alkaline cells), exceeding the regulator's optimal input range and increasing thermal dissipation.
SPI Was Mandatory Instead of I²C
During development, the use of I²C combined with active Wi-Fi on the ESP32 caused intermittent communication failures and bus lockups. Migrating the BME280 to SPI provided a dedicated, synchronous communication channel, fully eliminating the instability.
Outdoor Weather-Resistant Enclosure For Testing
I bought a waterproof box and made some minor modifications to adapt it to this project. It has two large holes in the bottom for ventilation, and right above them is the BME280 sensor. The goal is to prevent water from entering, especially since it's windy and raining heavily here (which is quite common), but at the same time, to avoid interfering with the sensor readings. I also put a very fine green mesh to prevent insects from getting in and covering the sensor hole. Now it will be screwed to the outside wall of the house.
P.S. - It will not be exposed directly to sun/rain.
This is the final result:
Fig.4 - Outdoor weather-resistant enclosure I.
Fig.5 - Outdoor weather-resistant enclosure II.
Fig.6 - Outdoor weather-resistant enclosure III.
Fig.7 - Outdoor weather-resistant enclosure IV.
Fig.8 - Outdoor weather-resistant enclosure on the wall below the balcony.
Vented Radiation Shield Implementation
You can see more in the Solidworks section.
Leave A Comment