The brief I set myself was modest: a little box on the garden fence that tells me the temperature, humidity and pressure, and runs for months on a battery. The ESP32 had only really landed for hobbyists in the last few months, and the dual-core, wifi-and-bluetooth, deep-sleep-with-actual-low-power story was exactly the right shape for this. So I bought a handful of dev boards, a BME280, and a small LiPo, and set off to build the thing.
It mostly works now. "Mostly" is carrying a lot of weight in that sentence, and the gap between "works on the bench" and "mostly works on the fence" is where all the actual learning lived.
the easy part
The sensor side was genuinely pleasant. The BME280 talks I2C and gives you temperature, humidity and barometric pressure from one tidy little module. Wire it to the default I2C pins, pull in a library, and you're reading sane values in about twenty minutes. The ESP32's wifi came up first try, and getting a reading published to my MQTT broker took an afternoon. The naive version of this project was done by teatime on day one.
Adafruit_BME280 bme;
void setup() {
bme.begin(0x76);
float t = bme.readTemperature();
float h = bme.readHumidity();
float p = bme.readPressure() / 100.0F; // hPa
publish(t, h, p);
esp_deep_sleep_start();
}
That's the whole shape of it. Wake, read, publish, sleep. If the world were kind, that would be the end of the post.
the battery, which is where it got interesting
The world is not kind, and the world's unkindness here is measured in milliamps. My first "finished" version flattened the battery in about four days. For a thing meant to last months, that's a failure, and the deep-sleep numbers said it shouldn't be happening.
The ESP32 itself, in deep sleep, draws a handful of microamps. Lovely. But the board draws far more, because the dev board has friends: a USB-to-serial chip, a power LED that is on permanently for no reason anyone asked for, and a linear regulator with a quiescent current that dwarfs the sleeping microcontroller. My fence box was spending almost all its energy keeping a power LED lit and a serial chip awake for a USB port that wasn't even connected.
The measurements were brutal. Deep sleep on the bare module: about 10 microamps. Deep sleep on the dev board as shipped: closer to 1.2 milliamps, a hundred-fold worse, and entirely down to the supporting cast.
So the second half of this project was surgery. I desoldered the power LED, which felt vandalistic but bought back a good chunk. I moved to powering the board through a more efficient regulator and bypassed the onboard one. I stopped using the USB-serial path entirely for deployment. After all that, sleep current dropped to something that projects to months rather than days, which was the original brief.
the "mostly" list
It works. It also has a list of things that are true but that I've chosen to live with, which is what "mostly" means in practice.
- Wifi connection time is the real battery cost, not the sleep. Waking up and associating with the access point takes a couple of seconds and a few hundred milliamps. The deep sleep I obsessed over saves microamps; the wifi wake costs milliamps for seconds. The actual energy budget is dominated by how often it reports, not how little it sips between reports. I report every fifteen minutes, which is plenty for weather, and that interval is the single biggest lever on battery life.
- The humidity reads high when the box has been sealed in the sun. Self-heating and a too-snug enclosure. A couple of vent holes drilled in the bottom helped, but it's still not a calibrated instrument and I've stopped pretending it is.
- It occasionally misses a report. If the access point is slow to respond, the ESP32 gives up and goes back to sleep rather than draining the battery waiting. So the data has gaps. For a garden thermometer that is completely fine; for anything I cared about I'd add a small retry budget and a local buffer.
- Time is hard. With deep sleep you lose your sense of when you are. I lean on the MQTT broker to timestamp on receipt rather than trusting the device's notion of the clock, which is good enough and avoids dragging NTP into every wake cycle.
was it worth it
Yes, easily, though not for the weather data, which I could have bought far more accurately for less than I spent on dev boards I then desoldered components off. It was worth it because the deep-sleep power budget is one of those topics you can read about endlessly and not actually understand until you've watched your own multimeter and been lied to by a dev board's marketing. The ESP32 is a genuinely impressive bit of kit, and the deep-sleep story is real, but the board it comes on is built for development, not for living on a fence for six months. Bridging that gap, microamp by microamp, taught me more than the project was ever nominally about.
It's on the fence now. It mostly works. I've made my peace with the adverb.