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

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

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
    The potentiometer feeds GPIO34; GPIO13 toggles the modeled uplink; red, green, and yellow LEDs show alarm, link, and buffer state.
    Why it matters
    The host chapter asks which path owns a safety decision when the fog tier fails.
    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
    Inspect the LIMIT comparison and confirm that digitalWrite(ALARM_LED, alarm) is outside the uplink condition.
    You will see
    LIMIT is 2500 and the local alarm output depends only on the current sensor reading.
    Why it matters
    A local guard must not block on an upstream service or acknowledgement.
    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
    EDGE-FOG LOCAL GUARD READY appears, followed by samples that name the limit, local action, uplink state, and buffered count.
    Why it matters
    A declared startup state and compact record make the outage run repeatable.
    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
    UPLINK=OFF appears and the green link LED turns off.
    Why it matters
    GPIO13 models the failed upstream path without changing the local sensor or controller.
    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 and watch the next decision row.
    You will see
    local_action=ALARM remains visible with uplink=OFF.
    Why it matters
    This is the Local Guard acceptance result: urgent behavior survives loss of the fog or cloud path.
    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
    Wait for at least three offline samples.
    You will see
    The yellow buffer LED stays on and buffered reaches at least 3.
    Why it matters
    The failure drill must distinguish continuing control from delayed evidence.
    Step 6: The offline record shows buffered=3 or more. The ring marks the retained evidence count.
    Step 6 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  7. 7 Step 7

    Do
    Press Toggle uplink again and inspect the next serial rows.
    You will see
    UPLINK=ON is followed by RECONCILE sent= with original_event_order=preserved, then buffered=0.
    Why it matters
    Recovery is incomplete until delayed records are marked and reconciled without being mistaken for fresh alarms.
    Step 7: Reconnection sends the buffered records in original event order and clears the count. The ring marks the reconciliation proof.
    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