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.
Predict the reading, then compare it with the measurement.
Wokwi ESP32
Third party ToolOpen 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
- 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · 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
- 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · 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 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 checkA 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 checkA 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
Return to Edge-Fog Computing: Common Pitfalls and Solutions · Browse Labs