# ML-C13 classic ESPTouch receiver

This project replaces the MicroPython runtime. Save your existing project files and private configuration on the computer first. Use the owner-confirmed board: ESP32-S3-N16R8 / YD-ESP32-23 V1.3, component side toward you, antenna up, USB-C sockets down. Native USB is front left; COM is front right. RST is above BOOT.

Use isolated, non-sensitive training Wi-Fi credentials. Classic ESPTouch in this lab is not an authenticated production provisioning channel. The training network is visible, 2.4 GHz WPA2-Personal; SSID 1–32 UTF-8 bytes; password 8–63 printable ASCII characters. Do not include passwords in commands, screenshots or shared logs.

## Computer setup

Install **ESP-IDF v5.5.2** and ESP32-S3 tools with Espressif's Windows setup guide:
https://docs.espressif.com/projects/esp-idf/en/v5.5.2/esp32s3/get-started/windows-setup.html

Open **ESP-IDF PowerShell**. Copy this whole `receiver` folder to `%USERPROFILE%\MoloLab\ml-c13\receiver`. Keep all project files together. Run:

```powershell
Set-Location "$env:USERPROFILE\MoloLab\ml-c13\receiver"
idf.py --version
idf.py set-target esp32s3
idf.py build
```

Expect version 5.5.2 and a successful ESP32-S3 build. Stop on errors. Do not reuse an old `sdkconfig` or `build` folder from a different project. Defaults choose 16 MB flash, a 2 MB factory app partition, primary USB Serial/JTAG console and quiet component logs. PSRAM is not used by this application. The `nvs` partition starts at 0x9000 and has size 0x6000; the `phy_init` partition is at 0xf000, followed by the app at 0x10000. Let `idf.py` calculate and write its generated image list; do not manually substitute these numbers into a MicroPython flash command.

## USB install

Disconnect external circuits and other power. Attach one USB data cable to the front-left **USB** socket. To select the ROM downloader, hold BOOT, tap/release RST, then release BOOT. Identify the current download port. Close other serial tools. Substitute your actual port for COM7:

```powershell
idf.py -p COM7 flash monitor
```

`idf.py flash` writes this build's bootloader, partition table and application with generated flash arguments. An app-only `.bin` is not the merged MicroPython image. Normal startup uses RST with BOOT released. Runtime and download ports can differ; rediscover the runtime port and use `idf.py -p NEW_PORT monitor` if necessary. Exit monitor with **Ctrl-]**.

## Sender

Use Espressif's Android app release **v2.4.0**:
https://github.com/EspressifApp/EsptouchForAndroid/releases/tag/v2.4.0

Follow your phone's installation policy. If it cannot install the app, use the offline exercise instead. Join the target training network on its **2.4 GHz** band, grant the OS permissions required to read Wi-Fi information, and choose **EspTouch**, the classic menu item. **EspTouch V2** is incompatible with this receiver (`SC_TYPE_ESPTOUCH`). App release 2.4.0 is not the protocol named V2.

Check the selected network and enter the training password privately. Press RST normally. Begin the classic sender when the console reports `LAB LISTEN_CLASSIC_90S`. Watch the receiver console and phone result separately. Phone/router permissions and broadcast handling can affect delivery.

## Status contract

- `RECEIVED_NOT_CONNECTED`: a valid classic candidate was decoded; it does not prove station association.
- `LINK_UP`: the candidate's station obtained a nonzero IP address. This does not prove Internet or cloud access.
- `SAVED_NVS`: the app wrote its own NVS blob, namespace `ml_c13`, key `wifi`. Wi-Fi driver storage is RAM-only.
- `ACK_SENT_CHECK_PHONE`: the receiver sent its SmartConfig acknowledgement. Check the phone's displayed result independently.
- `COMPLETE_VERIFY_RESTART`: IP, saving and ACK observed; a normal restart still must verify the saved join.
- `LISTENER_STOPPED`: SmartConfig resources released. The listener never retries forever.
- `TIMEOUT_NO_LINK_RESTART_TO_RETRY`: no current station IP at the deadline. Stop sender, check one cause, then restart normally for a new attempt.
- `LINK_UP_ACK_UNCONFIRMED`: a link exists but the ACK was not observed before the deadline; check the phone and restart result separately.
- `SAVE_ERROR`: do not claim persistence. Stop and get help with storage.
- `STORAGE_ERROR_GET_HELP`: initial NVS setup failed. The input task has not started; typing `c` is not a repair for this state. Stop and get help. Do not erase all flash as a generic fix.

Each fresh setup window lasts at most 90 seconds and accepts the first valid candidate. A failed new candidate does not replace an old saved key. After a successful setup, stop the sender and press RST with BOOT released. The app tries the saved network for at most 15 seconds. Expect `STORED_LINK_UP`; a failed saved join falls back to one new 90-second setup window. The idle state remains available for USB clear; it is not an endless scan.

## Narrow clear and return

In the running IDF monitor, type **c**; press Enter if your terminal buffers input. `LAB_KEY_CLEARED_RESTART` removes only `ml_c13/wifi`, commits and restarts. The next boot should listen without `STORED_JOIN_15S`. This project does not use `/lab_wifi.json`. NVS data is not encrypted here; deletion is not secure erasure. Private backups and other app namespaces are separate.

To return to MicroPython, exit monitor and follow ML-C10's saved-project recovery path using the correct official Octal-SPIRAM ESP32-S3 firmware, then restore the project files. This installed IDF app has no Python REPL.

## Offline practice

From the parent `examples` folder, run `python trace_lab.py receipt-only`, `python trace_lab.py ack-missing`, and `python trace_lab.py complete`. These classify included redacted traces without USB or radio access. Their output explicitly identifies an offline simulation.

## Attribution

The C receiver is derived from Espressif's ESP-IDF v5.5.2 public-domain / optional CC0 SmartConfig example, with upstream notice retained in `main/main.c`:
https://github.com/espressif/esp-idf/blob/v5.5.2/examples/wifi/smart_config/main/smartconfig_main.c

The course changes add a finite deadline, application-owned storage, restart/clear behavior and redacted status messages. ESP-IDF itself retains its upstream licenses. Use this course's source, not the upstream example's credential-printing logging lines, for the lab.
