Skip to content

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., your practice guide

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 Tool

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

Tier 1 · Web · No account

Version tested: Compiled and booted by the Wokwi gate (ESP32 Arduino core 3.3.11); captured in the Wokwi web editor on 2026-09-09. Date: 2026-09-09.

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.

diagram.json

1,262 bytes · Circuit connections

Download

sketch.ino

2,058 bytes · ESP32 program

Download

  1. Use the launch button above to open the ESP32 editor in Wokwi.
  2. Select the editor’s diagram.json tab and replace all its text with the supplied diagram.json.
  3. Select the sketch.ino tab, replace all its text with the supplied sketch.ino, then click Start Simulation.

Steps

Screens captured against Wokwi ESP32 Compiled and booted by the Wokwi gate (ESP32 Arduino core 3.3.11); captured in the Wokwi web editor on 2026-09-09 on 2026-09-09; the tool may have moved on — the text steps are the contract.

  1. 1 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: The simulated sensor and awake-status LED connect through GPIO12, GPIO34, and GPIO2. The ring marks the switched loads.
    Step 1 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  2. 2 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: The five-second teaching interval and retained wake counter are declared. The ring marks the timer and RTC state.
    Step 2 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  3. 3 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: ENERGY CYCLE wake=1 cause=0 The ring marks the initial boot cycle and undefined wake cause.
    Step 3 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  4. 4 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: STATE sensor-warmup duration=250 ms reading=0 STATE active-compute status=ON sensor=ON The ring marks the warm-up and active state evidence.
    Step 4 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  5. 5 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: LEDGER charge=272.11 mA*s average=0.302 mA LIFE usable=1680 mAh estimate=232 days The ring marks the measured-ledger average and lifetime estimate.
    Step 5 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  6. 6 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: SLEEP timer=5 s status=OFF sensor=OFF The ring marks the pre-sleep peripheral state and timer.
    Step 6 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  7. 7 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: SLEEP timer=5 s status=OFF sensor=OFF The ring marks the state before the timer-wake timeout; this web-editor run did not produce a second application cycle.
    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.

  1. 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 check
  2. Beyond a single lifetime figure, what is the most useful thing a battery-life tool provides?

    Return to the chapter’s knowledge check
  3. For 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

Caution

The five-second Wokwi timer is a teaching acceleration; the source deployment example uses 900 seconds. Wokwi shows firmware states, not trustworthy current. Measure the complete physical node in series with a suitable profiler or meter, account for USB and radio peaks, and never place an ammeter directly across a supply.

Return to Power Management Tools · Browse Labs