← Case studies

Espressif's Wi-Fi Example on an ESP32
— Closing the Loop

Two power passes against a power profiler, two bugs found in the stock example, and a fix offered back to Espressif

The session on film, 5 min 53 s: the bench, Matt's four requests in his own voice, and the agent's work between them. Captions are available from the player's menu

The Challenge

Espressif's Arduino core for the ESP32 ships an example sketch, WiFiClient, that joins Wi-Fi, sends a counter to a ThingSpeak channel, reads the last three values back, waits 10 seconds, and repeats. Nobody on our side wrote it. The task, in Matt Starfield's words to the session: "Perform a power optimization analysis on this firmware and reduce the power consumption that this device uses without changing the functionality of the firmware." [L1]

The board was an Adafruit ESP32 Feather V2 on a breadboard, powered only through its battery pin by a Nordic Power Profiler Kit II (PPK2) set to 3.7 V, so every microamp the board drew was measured. There was no power budget at the start, and no one had checked whether the example did its job correctly.

The bench: the ESP32 Feather V2 on a breadboard, its battery pin fed by the PPK2, which is its only supply

The Platform

Hapimatic runs each AI session as a persistent, observable process with its own working tree, tools, and memory, and shows each decision the operator owes in a Pins tab. On this bench the session could build firmware with the Arduino command-line tools, upload it over Wi-Fi to a small loader on the board or over a USB cable, read the profiler's log and ask it for raw captures, and read the ThingSpeak channel's own record through its API. A second Hapimatic session kept the profiler running and power-cycled the board when asked. Matt watched, answered the session's questions, and pressed the board's reset button when an upload needed it.

The Working Method

A chat assistant would have suggested power settings. This session changed the firmware, measured each change on the board, and checked the server's record of what the device actually sent.

  • Observe — the profiler log and raw captures, the board's status over Wi-Fi, and the ThingSpeak channel's feed.
  • Hypothesize — from the sketch's source, the Arduino core's build settings, the board's schematic, and Espressif's and ThingSpeak's documentation.
  • Measure — every build over at least 22 report cycles at 3.7 V, plus a 32-second raw capture at 100,000 samples a second.
  • Diagnose — mechanism first: where in each cycle the current goes, and why the server rejected what it rejected.
  • Verify — measure again, and read the server's record to prove the device still does its job.
  • Record — results files beside the firmware, lessons saved to memory, and the bugs filed upstream with their evidence.

How to Read This Report

Every factual claim below carries a reference [L#] that resolves to a row in the References appendix at the end. Each row is tagged with a confidence tier:

  • ✅ verified — a tool call, a measurement log, a file, or a public record directly shows it.
  • 🟡 inferred — a reasonable interpretation connecting verified facts, labelled as such.
  • ❓ asserted-unverified — claimed but not evidenced. This report contains none.

Every current is the mean of the profiler log's 0.1-second windows over the stated span, at 3.7 V, recomputed from the log for this report. The log records 64 to 77 percent of the windows in each span; the continuous 32-second raw captures read 0.6 to 2.0 mA higher for the same builds [L22]. Times are Eastern on Friday, November 20, 2026, unless another date is given. Hours on a battery are projections: 1,000 mAh divided by the mean current, with no derating [L15].

What the AI Actually Did

Problem 1 — Where the power went

Problem The stock example drew an average of 56.8 mA. Nothing said where that current went.
Capability Instrumented power analysis on the device (T1 embodied).
How it works The session froze a baseline window in the profiler log, asked the profiler for a 32-second raw capture, and split the capture into current bands at 1 ms resolution.
How it addressed the problem About 80 percent of each cycle the board sat at a 44.9 mA floor: the radio asleep and the processor idling at 240 MHz while the sketch waited. The radio itself ran only in short bursts of 105 to 160 mA, and for about 2 seconds a cycle the processor spun at 60 to 80 mA waiting for the server's reply. The biggest cost was idling, not Wi-Fi. [L2]
Where the power went: about 80 percent of the cycle at a 45 mA idle floor

Problem 2 — Lower the draw without changing what the device does

Problem Each candidate change had to leave the device's behaviour alone: the same two requests, the same cadence, the same output.
Capability Firmware changes measured one stage at a time, with the operator's choices made explicit (T1, T2).
How it works The session proposed four changes and listed what it would not do, each because it changed the device's behaviour: deep sleep, a slower cadence, dropping the read-back, or lower transmit power. Three choices went to Matt as pins: one build or two, whether to switch off the board's LED and sensor-port power, and how to reach the loader for each upload. He answered all three at 1:07 PM.
How it addressed the problem Two builds, each uploaded over Wi-Fi after Matt pressed reset. The processor at 80 MHz plus a 1 ms pause in the reply wait brought the mean to 36.3 mA; adding the radio's maximum modem sleep and switching off the unused power rail brought it to 32.7 mA, 42 percent below the stock example. [L3] [L4]

Problem 3 — Every other report never reached the server

Problem The session had read the channel's feed before changing anything: an entry every 24.5 seconds, with the counter stepping by two. It wrote that down as the stock behaviour every build had to preserve. At 2:00 PM Matt looked at the same data: "It looks like only every other transmission is getting through, and that's the same for the stock firmware as well as your updated firmware. It looks like that's a bug in the original stock firmware. Can you fix that first?"
Capability Root-cause analysis against primary sources, and owning a mistake (T3 rigor, T4).
How it works The session confirmed the cause from the sources, not from the pattern. ThingSpeak's free license accepts one update per channel every 15 seconds and answers an earlier write with 0, which a probe with an invalid key showed directly. The sketch waits 10 seconds after its two requests, so it writes about every 12.3 seconds, and it advances its counter whatever the server answered (lines 104 and 105 of the file on Espressif's master branch).
How it addressed the problem The session said plainly that it had kept a defect in both of its builds, and saved the rule to memory: a lost-data pattern in a baseline is a defect to raise first, not behaviour to preserve. Espressif's own README for the example shows the same bug in its sample output, a write answered 0 and read-back values of 359, 361, and 363. [L5] [L6] [L10]
Matt, at 2:00 PM, pointing at the lost reports

Problem 4 — A second bug, in the read-back

Problem While fixing the first bug, the session checked the read-back request's actual reply. On Matt's channel, which is not public, it failed every cycle.
Capability Checking the reply, not only the request (T4).
How it works The sketch declares a read key and its header tells the user to fill it in, but the read request on line 92 never sends it. ThingSpeak answers such a request with HTTP 400 and the body -1. The example's default channel is public, so the default configuration hides the bug until a user follows the instructions and uses a channel of their own.
How it addressed the problem With the key added, the same request returned HTTP 200 and the last three entries. [L7]

Problem 5 — Measuring again on firmware that works

Problem The first pass had been measured on a device that lost half its reports, so its numbers had to be redone, and the comparison had to account for the device now doing more.
Capability Choosing the measure that matches the job (T3 rigor).
How it works Both new builds start each write at least 16 seconds after the previous one, count only writes the server accepted, and send the read key. The session compared builds by energy per report that reached the server, not by mean current alone.
How it addressed the problem The fixed stock example landed 34 writes in a row, 16 seconds apart, counter 0 to 33 (2:09 to 2:18 PM). Measured: 55.6 mA for the fixed stock build and 32.8 mA for the fixed low-power build, 41 percent less. Energy per delivered report fell from 5.17 J (the original example) to 3.29 J from the bug fix alone, and to 1.94 J with the power changes. [L8] [L9]
Fixed: every report arrives, 34 in a row, and the second bug found on the way

Problem 6 — A budget below the floor

Problem At 2:40 PM Matt set a target: "Let's try to hit a target average power consumption of 16 milliamps." He chose the figure arbitrarily, at half of the first pass's result.
Capability Feasibility analysis from measured data before any change (T4).
How it works The session showed from data it already had why the current design could not get there: awake at 80 MHz with the radio asleep, the board idled at 26.1 mA, about 90 percent of the time, and Wi-Fi needs at least 80 MHz. Espressif's published figures for that mode are 28.8 to 31.1 mA. It then measured what a wake from deep sleep costs on this board, about 415 mC over about 4.9 seconds, against 0.0171 mA asleep.
How it addressed the problem It brought three routes, each with a projection and a cost: automatic light sleep while staying connected (about 12 mA; costs a different build system), deep sleep and rejoining Wi-Fi every cycle (about 30 mA, so it would miss; rejoining 5,400 times a day), or deep sleep with a report once a minute (about 8 mA; a quarter of the data). Matt chose the first at 2:46 PM: keep everything the device does, and pay for it with a new build. [L11] [L12]

Problem 7 — The obstacle was the build system, not the code

Problem Automatic light sleep is one function call in the firmware, but only in a build with power management enabled. The Arduino core's prebuilt libraries are compiled without it.
Capability Rebuilding the toolchain while holding everything else constant (T4).
How it works The session built the firmware with Espressif's ESP-IDF v5.5.3 and the installed Arduino core 3.3.7 as a component, starting from the core's own build configuration. Of every option the two builds share, the only differences are the board settings the Arduino tools already apply, the ESP-IDF version marker, and power management with tickless idle. The first two attempts stopped on configuration errors, which the session read from the build log and fixed; the next build ran 2,225 steps with no errors.
How it addressed the problem The stage 2 build averaged 13.5 mA over 22 report cycles, under the 16 mA budget and 76 percent below the fixed stock example. Between reports the board now idles at 2.5 mA, against the 2.33 mA Espressif publishes for the same mode. The channel received 28 reports in a row, counter 0 to 27, one every 16 seconds, and the energy per delivered report fell to 0.80 J, 85 percent below the original example's 5.17 J. On a 1,000 mAh cell that is about 74 hours, against 18 for the fixed stock example and 30 after stage 1 (projected). [L13] [L14] [L15]

Problem 8 — A build that cut off its own update path

Problem Every bench build was meant to hand control back to the over-Wi-Fi loader at the next reset. The stage 2 build did not: after a power cycle the board kept booting it, and no reset reached the loader. Earlier, the session had said the hand-back would apply to that build without checking.
Capability Diagnosis from the linker's own record, and a physical recovery sequenced from the schematic (T3, T1).
How it works The session read the build's linker map. Its hand-back function had been compiled but never linked: the Arduino core's weak default had already satisfied the symbol, so the build confirmed itself as the valid app. A rebuild linked the hand-back function, which the map then showed.
How it addressed the problem Only a USB cable flash could recover the board. The session traced the board's schematic before asking for the cable: USB power drives the battery net through the charger, the same net the profiler's lead sat on, so the lead had to come off first. Matt confirmed the lead was off before any flash. The session acknowledged its unchecked claim and saved the lesson to memory. [L16]

Problem 9 — Offering the fix back to Espressif

Problem At 3:51 PM Matt asked for one issue per bug and one pull request fixing both, against Espressif's master branch, after checking that nobody had reported them, and with the exact file tested on the board. Nothing was to be posted until he said so.
Capability Contribution to a public repository under the operator's gate (T2 autonomy, T4).
How it works The session searched the repository's issues and pull requests and found no prior report; the only related items were the 2023 change that introduced the ThingSpeak version of the example. It made the patch against master, ran Espressif's own pre-commit checks, and wrote each draft in Espressif's issue form and pull-request template.
How it addressed the problem By cable, master's file had 4 of 8 writes accepted and 8 of 8 reads answered 400 with -1; the pull request's file had 7 of 7 writes and 7 of 7 reads accepted. The drafts waited in a pin until Matt typed "yes, post" at 4:51 PM. Issue #13146 went up at 4:51:31 PM, issue #13147 at 4:51:45 PM, and pull request #13148 at 4:52:20 PM. Matt signed Espressif's contributor license agreement himself that evening. [L17] [L18] [L20]
Nothing went out until Matt typed yes

Worked Examples

"Half of what the device sent never arrived"

Observation The device looked healthy and kept sending, but only every other value reached the server, in Espressif's example exactly as shipped.
Measurement The server's record: entries 24 to 25 seconds apart with the counter stepping by two. ThingSpeak's free limit is one update every 15 seconds; the example sends one about every 12.3 seconds.
Diagnosis The server turns away every write that comes too soon and says so, but the example never reads the answer, so it counts the lost value anyway.
Verification After the fix, 34 writes in a row reached the server, and in the exact file sent to Espressif, 7 of 7.
References [L5] [L6] [L8] [L17]; see Problems 3, 5, and 9 above.

"Can it run on half the power, and what does that cost?"

Observation After the first pass the board drew 32.8 mA. Matt asked for 16.
Measurement Awake and idle, the board could not go below 26.1 mA. A wake from deep sleep cost about 415 mC, too much to pay every 16 seconds.
Diagnosis The board had to sleep while staying connected, which needed power management the Arduino build does not include.
Verification 13.5 mA over 22 cycles, every report still arriving every 16 seconds. The cost was a different build system, a 2.2 GB toolchain, and one build that had to be recovered by cable; nothing the device does changed.
References [L11] [L12] [L13] [L14] [L16]; see Problems 6, 7, and 8 above.

"Will the example work for the next person who builds it?"

Observation Both bugs are in the example as Espressif ships it, and on master as of this report.
Measurement Master's file on the board: 4 of 8 writes accepted, 8 of 8 reads failed. The fixed file: 7 of 7 and 7 of 7.
Diagnosis The 10-second wait is under ThingSpeak's limit, and the read request leaves out its key, which the public demo channel never needed.
Verification Two issues and a pull request in Espressif's repository, each with its evidence; status below.
References [L17] [L18] [L19]; see Problem 9 above.

Upstream: where the fix stands

On Nov 20, 2026, at 4:51 and 4:52 PM ET, two issues and one pull request went to Espressif's arduino-esp32 repository from Matt's account: #13146, #13147, and #13148. As of Nov 22, 2026, 2:31 PM ET the pull request is open and not merged. Both issues are open with the label “Status: Awaiting triage”. A review is requested from me-no-dev; no maintainer has reviewed it yet. Matt signed Espressif's contributor license agreement the same evening. Espressif's bot left one comment on the README change: “Merge request must include a release note, or it needs to be processed first.”

The Takeaway

On this board the operator's inputs were four requests, five decisions in the Pins tab, three presses of a reset button, one confirmation that a lead was off, and the words "yes, post". Between them the session found where the power went, cut it by 42 percent in a first pass, owned a measurement it had treated as a specification, fixed two bugs in Espressif's example, met an arbitrary budget at 13.5 mA without changing what the device does, recovered from a build that locked itself in, and offered the fixes back upstream with the exact file tested. From Matt's first request at 12:50 PM to the pull request at 4:52 PM took about four hours [L1] [L18].

The session was wrong twice and said so: it treated the lost reports as behaviour to keep until Matt pointed at them, and it claimed the hand-back would survive the new build without checking. Both lessons were saved to its memory. Every reference below is verified from a tool call, the profiler log, a file, or a public record.

References

Ref Claim Primary source Tier
L1 Matt's request at 12:50 PM; the board powered only by the PPK2 at 3.7 V Bench session transcript, user message of 17:50:15 UTC and the session's opening brief ✅ verified
L2 Baseline 56.8 mA (17:21 to 18:07 UTC); 44.9 mA floor about 80 percent of the time; 60 to 80 mA reply wait; 105 to 160 mA radio bursts Profiler log, recomputed 2026-11-22; the session's raw-capture request and its analysis message of 1:05 PM ✅ verified
L3 Four changes proposed, four left out; three decisions as pins, answered at 1:07 PM Bench session transcript, messages of 1:05 and 1:06 PM and the pin answers of 1:07 PM ✅ verified
L4 First pass 36.3 mA, then 32.7 mA (42 percent less); each build uploaded over Wi-Fi after a reset Profiler log, recomputed 2026-11-22 (18:21 to 18:27 and 18:34 to 18:40 UTC); the session's upload tool calls ✅ verified
L5 The every-other pattern recorded as behaviour to preserve; Matt's correction at 2:00 PM Bench session transcript, the plan message of 1:05 PM and Matt's message of 19:00:49 UTC ✅ verified
L6 15-second limit and the 0 reply; writes about every 12.3 s; counter advanced regardless; the README's sample output WiFiClient.ino on espressif/arduino-esp32 master (lines 87, 104 to 105, read 2026-11-22); the session's ThingSpeak probe; ThingSpeak's Write Data documentation; the example's README ✅ verified
L7 The read request omits the key; HTTP 400 -1 without it, HTTP 200 with it; the demo channel is public WiFiClient.ino master line 92; the session's keyed read and its read of the demo channel ✅ verified
L8 34 writes in a row, counter 0 to 33, 2:09 to 2:18 PM The channel's feed as read by the session: entry IDs 261 to 294, consecutive (four middle rows not printed; their IDs are) ✅ verified
L9 55.6 and 32.8 mA after the fix (41 percent less); 5.17, 3.29, and 1.94 J per delivered report Profiler log, recomputed 2026-11-22 (19:11 to 19:16:52 and 19:21 to 19:26:52 UTC); mean current × 3.7 V × interval between accepted entries ✅ verified
L10 The lesson saved to memory Bench session transcript, the memory write at 2:04 PM ✅ verified
L11 The 16 mA budget at 2:40 PM; arbitrary, half of the first pass Bench session transcript, Matt's message of 19:40:45 UTC; Matt's description of the choice, 2026-11-22; 32.7 ÷ 2 = 16.35 ✅ verified
L12 26.1 mA awake floor; Espressif's 28.8 to 31.1 mA; about 415 mC per wake, 0.0171 mA asleep; three routes; Matt's choice at 2:46 PM Bench session transcript, messages of 2:41 and 2:43 PM and the sleep-floor analysis output; ESP-IDF "Low Power Mode in Wi-Fi Scenarios" table; pin answer of 2:46 PM ✅ verified
L13 ESP-IDF v5.5.3 with the Arduino core as a component; the only configuration differences; 2,225 build steps Bench session transcript, the build tool calls and the configuration comparison of 3:02 PM; the session's results file ✅ verified
L14 13.5 mA over 22 cycles (20:19 to 20:24:52 UTC); 2.5 mA floor against Espressif's 2.33 mA; 28 reports in a row; 0.80 J per delivered report Profiler log, recomputed 2026-11-22; the session's results file; ESP-IDF low-power table ✅ verified
L15 About 18, 30, and 74 hours on a 1,000 mAh cell Arithmetic: 1,000 mAh ÷ 55.60, 32.83, and 13.50 mA, no derating (projected) ✅ verified
L16 The stage 2 build confirmed itself; found in the linker map; rebuilt; recovered by cable after the schematic-checked sequence and Matt's confirmation Bench session transcript, tool calls of 4:10 to 4:31 PM, the memory write at 4:20 PM, and the crew note of 4:33 PM ✅ verified
L17 No prior report; Espressif's pre-commit passes; master's file 4 of 8 and 8 of 8 failed, the fixed file 7 of 7 and 7 of 7 Bench session transcript, search and test tool calls of 3:52 to 4:37 PM; pull request #13148, Test Scenarios ✅ verified
L18 "yes, post" at 4:51 PM; #13146, #13147, and #13148 opened at 4:51:31, 4:51:45, and 4:52:20 PM Bench session transcript, Matt's message and the posting tool calls; GitHub's created times for the three items ✅ verified
L19 Upstream status as of Nov 22, 2026, 2:31 PM ET GitHub API reads of the two issues, the pull request, its reviews, and its status checks ✅ verified
L20 Matt signed the contributor license agreement The pull request's license/cla status (success, 6:13 PM) and the CLA assistant's comment ✅ verified
L21 The film: 5 min 53 s, cut by a Hapimatic session from the bench recordings, approved by Matt 2026-11-24 The film's production scripts and its 10,604-frame scene list; Matt's approval of 2026-11-24 ✅ verified
L22 Raw captures read 0.6 to 2.0 mA above the log means (14.77 against 13.50 mA for stage 2) The session's raw-capture analysis of 2:28 PM and its results file ✅ verified

← Back to all case studies