Skip to content

Keep a local guard working when the uplink fails

Prove that a threshold alarm still acts locally while an unavailable uplink buffers evidence for ordered reconciliation.

Edge Eddie: I want you to cut the upstream path, prove the local action, and preserve the evidence needed after recovery., your practice guide

Edge Eddie: I want you to cut the upstream path, prove the local action, and preserve the evidence needed after recovery.
Predict the reading, then compare it with the measurement.

Wokwi ESP32

Third party Tool

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-10. Date: 2026-09-10.

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,789 bytes · Circuit connections

Download

sketch.ino

1,464 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-10 on 2026-09-10; the tool may have moved on — the text steps are the contract.

  1. 1 Step 1

    Do
    Open a new Wokwi ESP32 project, paste diagram.json and sketch.ino, and inspect the sensor, GPIO13 uplink button, and three LED paths.
    You will see
    Input: inspect the running Wokwi circuit and diagram.json. The potentiometer feeds ESP32 GPIO34. The blue button uses GPIO13 to toggle the modeled uplink. Red, green, and yellow LEDs show alarm, link, and buffer state.
    Why it matters
    The red local alarm is lit at the starting 3202 sample. Serial Monitor compares that value with LIMIT=2500. The uplink LED is separate from the alarm path. This wiring makes the local-versus-link decision visible.
    Step 1: The sensor, uplink control, and three status LEDs are wired to the ESP32. The ring marks the local alarm and uplink paths.
    Step 1 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  2. 2 Step 2

    Do
    In the Wokwi simulation panel, inspect the LIMIT comparison and confirm that digitalWrite(ALARM_LED, alarm) is outside the uplink condition.
    You will see
    Input: inspect LIMIT and digitalWrite(ALARM_LED, alarm) in sketch.ino. The code sets LIMIT=2500 and compares reading >= LIMIT. The alarm write precedes the if (!uplinkOnline) buffer branch. Serial Monitor shows sample=3202 local_action=ALARM with uplink=ON.
    Why it matters
    The alarm decision uses the current local ADC reading. The write is outside the uplink condition. The red LED remains lit when later uplink state changes. A local guard therefore need not await network service.
    Step 2: The local alarm write is visible. The ring marks the code that keeps the decision local.
    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
    Input: start Wokwi and open Serial Monitor. Observed: "EDGE-FOG LOCAL GUARD READY". Observed: "GPIO13 toggles the simulated uplink; local decisions never wait for it." Observed: "sample=3202 limit=2500 local_action=ALARM uplink=ON buffered=0".
    Why it matters
    The reading is 702 counts above the limit. The local action begins as ALARM. The connected baseline has no buffered events. The ADC and link state are simulated.
    Step 3: EDGE-FOG LOCAL GUARD READY and the first decision record appear. The ring marks the startup proof.
    Step 3 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  4. 4 Step 4

    Do
    Press the blue Toggle uplink button once.
    You will see
    Input: hold and release Toggle uplink in Wokwi. Observed: "UPLINK=OFF". Observed next: "sample=3202 limit=2500 local_action=ALARM uplink=OFF buffered=1". Expected: the alarm persists when the uplink is OFF.
    Why it matters
    The button models an outage without changing the sample. The reading remains 702 counts above the limit. The first offline decision is buffered. The state agrees with the real screenshot.
    Step 4: UPLINK=OFF appears after the button press. The ring marks the modeled outage state.
    Step 4 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  5. 5 Step 5

    Do
    Leave the sensor above LIMIT while the uplink remains off; watch the next decision row in Serial Monitor.
    You will see
    Input: keep the above-limit sensor value while uplink is OFF. Observed: "sample=3202 limit=2500 local_action=ALARM uplink=OFF buffered=1". Observed later: the same decision reaches buffered=4. Expected: ALARM remains local through the outage.
    Why it matters
    The local decision does not depend on connectivity. The buffer grows during the outage. The 3202 input exceeds LIMIT=2500. No remote service is tested here.
    Step 5: local_action=ALARM remains active while uplink=OFF. The ring marks the independent local decision.
    Step 5 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  6. 6 Step 6

    Do
    In the Wokwi simulation panel, wait for at least three offline samples.
    You will see
    Input: keep the Wokwi uplink OFF while sample=3202. Serial Monitor: limit=2500 and local_action=ALARM continue. The offline count rises through buffered=18 and buffered=19. The marked offline row reports buffered=19; the next reaches 20.
    Why it matters
    The 3202 input stays above the 2500 alarm limit. The red local alarm LED remains lit during the outage. The serial count shows twenty retained events in this run. The local decision continues while uplink=OFF.
    Step 6: The Wokwi Serial Monitor reaches buffered=20 while the uplink is OFF. The ring marks buffered=19 before the count reaches 20.
    Step 6 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  7. 7 Step 7

    Do
    In the Wokwi simulation panel, press Toggle uplink again and inspect the next serial rows.
    You will see
    Input: press the blue Toggle uplink button again. Serial Monitor: "UPLINK=ON" follows buffered=20. The next row says "RECONCILE sent=20 original_event_order=preserved". Subsequent online rows show buffered=0 while ALARM continues.
    Why it matters
    The twenty offline events are counted at reconnection. The reconciliation line explicitly preserves original event order. New online decisions continue with an empty buffer. This run checks local continuity and recovery in the simulator.
    Step 7: The Wokwi Serial Monitor reports RECONCILE sent=20 and then buffered=0. The ring marks the reconciliation line.
    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 cold-chain gateway normally approves compressor commands, but truck sensors must protect cargo while the gateway is rebooting. What is the safest ownership pattern?

    Return to the chapter’s knowledge check
  2. A site buffer holds one hour of raw vibration samples. A two-hour network outage happens, and the same buffer is also used for fault alarms. What is the main design risk?

    Return to the chapter’s knowledge check
  3. A production cell requires a local reject decision before a part leaves the inspection station. The fog node can fail over to a standby node in 20 seconds. What should the review flag?

    Return to the chapter’s knowledge check

Caution

The potentiometer, threshold, GPIO button, LEDs, buffer, and reconciliation are teaching models. They do not prove sensor accuracy, durable storage, real network failure timing, failover, or production safety. On hardware use current-limiting resistors and validate the local safe state independently of the uplink.

Return to Edge-Fog Computing: Common Pitfalls and Solutions · Browse Labs