# V19.6 — Live hardware engineering bench

## Scope and safety
All 102 prior labs remain unchanged. This release provides a local hardware gateway and reference device programs, not a deployed institutional hardware service. The public static and connected cloud editions run an explicitly labeled teaching demonstration only. Live mode connects only through the native loopback gateway. No automatic substitution of model data for live measurements. No remote actuator access through Cloudflare. Only a supervised low-voltage LED pulse is supported; never connect motors, relays, heaters, mains or safety-critical equipment. A software watchdog is not a hardware interlock. Disconnect power if a device misbehaves.

## Wiring (power off before changing wiring)
| Board | DHT22 data | DHT22 supply | Optional LED |
|---|---|---|---|
| ESP32 DevKit | GPIO4 | 3.3 V and GND | Not supported in this sketch |
| Raspberry Pi 4 | BCM4 (physical pin 7) | 3.3 V (pin 1) and GND (pin 6) | BCM17 (pin 11) → 330 Ω → LED anode; cathode → GND |
For a bare DHT22, check its datasheet pin orientation and use a 4.7–10 kΩ pull-up from DATA to 3.3 V; breakout modules may already include one. Do not connect Pi/ESP GPIO to 5 V. Check board-specific pinout. On the Pi, `enable_led` is false by default.

## Broker and gateway
Use an administrator-managed private Mosquitto or compatible MQTT broker with TLS, a trusted CA, hostname matching, disabled anonymous access, per-device accounts and topic ACLs. Do not expose an unsecured public broker. Example topic policy (adapt account names): gateway reads `psut/hil196/pi01/telemetry` and `psut/hil196/esp01/telemetry`, writes `psut/hil196/pi01/led` only if explicitly authorized; pi01 writes its own telemetry and reads its own LED topic; esp01 writes only its own telemetry. No wildcard cross-device write. Do not retain telemetry or commands. Use unique client IDs. Certificate provisioning and broker deployment are administrator tasks.

Full editions only: install Python 3.10+ and `python -m pip install -r hardware196/requirements.txt` in a dedicated venv. Copy `hardware196/gateway.example.json` to a **private directory outside the portal**, e.g. `C:\iot-private\gateway.json`, fill in broker DNS hostname, port (normally 8883), gateway username/password, absolute CA file path, and enrolled device IDs. Do not add credentials to any published directory. Stop `START_LOCAL_SERVER.cmd` before running `START_HARDWARE.cmd "C:\iot-private\gateway.json"` or `python hardware196/server.py --config /absolute/private/gateway.json`. Open `http://localhost:8760/hil196.html`. The server binds loopback only; keep it local. Gateway LED control remains off unless explicitly enabled in both Pi and gateway configs and authorized in ACLs. Do not share access to this local browser/server with untrusted users. The local token and origin/host checks mitigate cross-site requests; not an institutional authentication boundary.

## ESP32 reference node (telemetry only)
Copy `hardware196/esp32_hil` to a private Arduino sketch folder of the same name. Install Arduino ESP32 board support, PubSubClient, Adafruit DHT sensor library and Adafruit Unified Sensor. Copy `credentials.example.h` to `credentials.h` there, set Wi-Fi, private broker, unique enrolled device ID (letters, numbers, `_`, `-`, 1–32 characters) and CA PEM. Ensure SNTP can synchronize time. Compile and upload to your ESP32 DevKit; serial monitor 115200 baud. Publishes valid DHT22 samples approximately every 2.5 seconds using QoS 0, without retention. Never use `setInsecure`. No actuator command subscriber. Firmware compilation and physical operation are not validated here.

## Raspberry Pi reference node
Copy `hardware196/core.py` and `pi_node.py` to a private directory on Pi OS. Install a virtual environment with Paho 2.1.0, adafruit-circuitpython-dht, Adafruit Blinka and gpiozero; install OS GPIO dependencies for your Pi OS release and confirm GPIO permissions. Use `pi.example.json` as template in a private folder; configure separate device credentials, broker hostname, CA and unique ID. Run `python pi_node.py --config /absolute/private/pi.json`. DHT failures are logged; no fabricated readings. Python stdout provides serial-like observation lines. A real serial reader is not implemented; paste logs manually in the bench.

## Experiment
1. Start broker and devices, then local gateway. Connect using the bench. A subscription status alone does not imply device telemetry. Select device, verify temperature/humidity and receipt age, and compare readings against a reference thermometer. Unplug/disconnect and observe stale status; reconnect, check sequence counters. The graph retains up to 120 accepted records per enrolled device and displays the current boot only. At most 16 devices and 64 boot IDs per device per gateway process; restart for a new acquisition session. No durable server storage.
2. Optional Pi LED: test wiring first. Enable only when supervised. Request a single pulse after checking the confirmation. Gateway requires receipt age <=4 s, cooldown >=6 s, new sample sequence and capability. Device checks boot ID, sequence, 8 s uptime deadline and 2 s pulse maximum; software watchdog deactivates LED on expiry/disconnect. A broker queue acceptance is not physical confirmation. Device echo records command acceptance, not electrical measurement. Never retry automatically on uncertain outcome. QoS 0 command transport is intentional; no persistent retransmission. Delayed telemetry can still be received, so receipt freshness is not a proof of acquisition freshness.
3. Import a V19.3 closed-loop evidence JSON (wait-step temperature records). Compare unpaired descriptive means only; align conditions, sampling windows and units before making claims. Export JSON and CSV; record actual board, sensor, calibration and acquisition notes. Evidence Portfolio supports the new schema; imported data does not certify physical provenance. Sequence gaps are not PDR; command echo delay is not one-way latency.
4. Prepare contextual AI prompt with observed values, notes and pasted logs, review and approve before sharing; never paste credentials. The offline mentor remains available through navigation. Cloud direct AI elsewhere remains unchanged.

## Verification
`python verification/runner.py --profile hardware-in-loop --output hil196-test.json` runs bounded registry, pulse and real local HTTP checks without MQTT dependencies. The test uses generated inputs and a controlled transport. Real MQTT/TLS, device compilation, Pi GPIO, sensor calibration, live cloud deployment and hardware timing need independent on-site validation. Browser tests use in-memory Chromium; actual connected transport is not exercised by them.

References: Paho 2.x client docs https://eclipse.dev/paho/files/paho.mqtt.python/html/client.html ; Adafruit DHT https://docs.circuitpython.org/projects/dht/en/latest/ ; ESP32 MQTTs example https://docs.emqx.com/en/cloud/latest/connect_to_deployments/esp32.html .
