Trace a timer sleep-and-wake cycle
Trace two sleep-and-wake cycles and audit the measured state ledger behind an average-current and lifetime estimate.

Physics Phoebe: I want you to audit each state duration and measured current before trusting the lifetime number.
Predict the reading, then compare it with the measurement.
Wokwi ESP32
Third party ToolTrace two sleep-and-wake cycles and audit the measured state ledger behind an average-current and lifetime estimate.
Open the ESP32 editor, paste diagram.json, then paste sketch.ino.
Open Wokwi to paste in the files (new tab)Get the files
Use both prepared files. This is a paste-in setup; saving a project requires a Wokwi account.
sketch.ino
- Use the launch button above to open the ESP32 editor in Wokwi.
- Select the editor’s diagram.json tab and replace all its text with the supplied diagram.json.
- Select the sketch.ino tab, replace all its text with the supplied sketch.ino, then click Start Simulation.
Steps
Step 1
- Do
- Paste diagram.json and sketch.ino into a new Wokwi ESP32 project and trace the switched sensor and status paths.
- You will see
- GPIO12 powers the simulated sensor, GPIO34 reads its signal, and GPIO2 drives the awake-status LED.
- Why it matters
- A whole-node energy trace must include sensor and status loads rather than measuring only the microcontroller.

Step 1 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) Step 2
- Do
- Inspect the wake counter, wake-cause check, and five-second teaching interval.
- You will see
- wakeCount uses RTC_DATA_ATTR, undefined startup resets the count, and the timer interval is explicitly labeled as a simulator acceleration.
- Why it matters
- Retained state and wake cause make consecutive duty-cycle traces distinguishable and reproducible.

Step 2 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) Step 3
- Do
- Start the simulation and open Serial Monitor at 115200 baud.
- You will see
- ENERGY CYCLE wake=1 cause=0 appears for the initial boot.
- Why it matters
- The first cycle establishes the baseline reset reason before any timer wake is interpreted.

Step 3 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) Step 4
- Do
- Inspect the first cycle's state lines.
- You will see
- The sensor warm-up lasts 250 ms, then active-compute reports status=ON and sensor=ON.
- Why it matters
- Separating warm-up and active work prevents a short high-current state from disappearing inside an average.

Step 4 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) Step 5
- Do
- Read the measured ledger calculation and compare its two summary lines.
- You will see
- The source chapter's example prints 272.11 mA*s, 0.302 mA average, 1680 mAh usable capacity, and about 232 days.
- Why it matters
- A calculator result becomes reviewable only when its state currents, durations, capacity reserve, and arithmetic remain visible.

Step 5 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) Step 6
- Do
- Confirm the pre-sleep line before the board sleeps.
- You will see
- SLEEP timer=5 s status=OFF sensor=OFF appears after the status and sensor pins are shut down.
- Why it matters
- The simulator can prove control state and timing, but not the physical board's true sleep current.

Step 6 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) Step 7
- Do
- Wait at least 6.5 seconds for a second timer cycle; if the web editor does not resume after deep sleep, record that limitation.
- You will see
- In this captured web run, the last application line remains SLEEP timer=5 s status=OFF sensor=OFF; no second ENERGY CYCLE line appears.
- Why it matters
- The missing web-editor wake is evidence of a simulator boundary, so timer-wake retention still requires a physical-board trace before a power policy is accepted.

Step 7 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
Chapter checks
These questions refer to the chapter’s examples. Use the return links to review their answers.
A battery-life calculator predicts four years, but the model uses datasheet sleep current, nominal battery capacity, and one successful radio transmission per cycle. What should the engineer do before accepting the result?
Return to the chapter’s knowledge checkBeyond a single lifetime figure, what is the most useful thing a battery-life tool provides?
Return to the chapter’s knowledge checkFor a node that reports once per hour with a 0.5 s active burst, a sweep shows halving sleep current gives +59% life while halving active current gives +15%. Which optimization should the team pursue first, and why?
Return to the chapter’s knowledge check