<p align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="docs/logo-banner-dark.svg" />
    <img src="docs/logo-banner.svg" alt="Bisque — Open-source ESP32-S3 ceramic kiln controller" width="760" />
  </picture>
</p>

<p align="center">
  <a href="https://github.com/BenSeverson/bisque/actions/workflows/build.yml"><img src="https://github.com/BenSeverson/bisque/actions/workflows/build.yml/badge.svg" alt="Build Status" /></a>
  <img src="https://img.shields.io/badge/ESP--IDF-v6.1.1-blue" alt="ESP-IDF v6.1.1" />
  <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-green" alt="MIT License" /></a>
</p>

<p align="center">
  <a href="https://benseverson.github.io/bisque/"><b>▶ Try the live web UI demo</b></a> — interactive, no hardware required
</p>

## Features

**Temperature Control**
- PID controller with auto-tuning (Ziegler-Nichols relay method)
- 1-second control loop with time-proportional SSR output
- Thermocouple calibration offset

**Firing Profiles**
- Up to 20 custom profiles with 16 segments each (ramp rate, target temp, hold time)
- Orton cone firing (cones 022-13) with slow, medium, and fast heating speeds
- Delayed start

**Safety**
- Over-temperature protection (hardware max 1400 C, user-configurable limit)
- Thermocouple fault detection (open circuit, short to GND/VCC)
- Rate-of-rise monitoring (detects runaway >2x programmed rate)
- Not-rising detection (alerts if <10 C rise in 15 min)
- Emergency stop with immediate SSR cutoff

**Web Dashboard**
- Real-time temperature chart with profile overlay (React + Recharts)
- Profile builder with cone fire mode
- Firing history with CSV trace export and cost estimation
- Settings: calibration, safety limits, webhooks, API token

**iOS App**
- Full remote control (SwiftUI)
- Finds the kiln on your Wi-Fi automatically (Bonjour), no IP address to type
- Dynamic Island live activities during firing
- Local notifications for firing complete/error

**LCD Display**
- 4.0" TFT (480x320) with LVGL, adaptive single-screen dashboard (idle/active/paused/complete/error)
- 5-way nav switch (up/down/select/left/right), SELECT-driven modals for profile pick and firing control

**Connectivity**
- Wi-Fi with mDNS (`bisque.local`)
- REST API with optional bearer token auth
- WebSocket for real-time streaming
- Webhook notifications (firing complete/error)

## Screenshots

**Web Dashboard** (React)
<p align="center">
  <img src="docs/screenshots/web-dashboard.png" width="600" alt="Web dashboard showing live firing progress" />
</p>

**LCD Display** (LVGL on 4.0" TFT)
<p align="center">
  <img src="docs/screenshots/lcd-splash.png" width="160" alt="Boot splash" />
  <img src="docs/screenshots/lcd-idle.png" width="160" alt="LCD idle" />
  <img src="docs/screenshots/lcd-heating.png" width="160" alt="LCD heating" />
  <img src="docs/screenshots/lcd-paused.png" width="160" alt="LCD paused" />
  <img src="docs/screenshots/lcd-complete.png" width="160" alt="LCD complete" />
  <img src="docs/screenshots/lcd-error.png" width="160" alt="LCD error" />
</p>
<p align="center">
  <img src="docs/screenshots/lcd-modal-picker.png" width="160" alt="Profile picker modal" />
  <img src="docs/screenshots/lcd-modal-start-confirm.png" width="160" alt="Start confirm modal" />
  <img src="docs/screenshots/lcd-modal-actions.png" width="160" alt="Action menu modal" />
  <img src="docs/screenshots/lcd-modal-actions-paused.png" width="160" alt="Action menu modal (paused)" />
  <img src="docs/screenshots/lcd-modal-actions-autotune.png" width="160" alt="Action menu modal (autotune)" />
</p>

**iOS App** (SwiftUI)
<p align="center">
  <img src="docs/screenshots/ios-app.png" width="280" alt="iOS app" />
</p>

## Hardware

The controller is a single board in [`hardware/kicad/`](hardware/kicad/) — a full KiCad project (schematic + routed **4-layer** board, 100 × 100 mm). Its GPIO map is [`docs/pin-assignments.md`](docs/pin-assignments.md).

<p align="center">
  <img src="hardware/kicad/3d/board-3d-top.png" width="600" alt="Raytraced top-down render of the Bisque controller PCB" />
</p>

It integrates the ESP32-S3-WROOM-1U module (external U.FL antenna), two MAX31856 thermocouple front-ends, two SSR drive channels behind a hardware watchdog, a current-transformer input read by the ESP32's ADC, a ULN2003 auxiliary output bank, three protected dry-contact inputs, USB-C flashing, and an alarm buzzer — with screw terminals for the field wiring and keyed connectors for the display and nav-switch looms. Gerbers, drill files, and an assembly BOM/CPL are committed and ready to upload to a board house.

See [`hardware/kicad/README.md`](hardware/kicad/README.md) for the full BOM, fabrication notes, and the regeneration workflow. GPIO assignments mirror the firmware's `Kconfig` defaults, so stock firmware runs unmodified.

[`hardware/enclosure/`](hardware/enclosure/README.md) documents a complete enclosure build around an off-the-shelf wall-mount steel box — layout, SSR thermal sizing, mains/SELV segregation, and a printable 1:1 drill template for the door.

> **Safety warning:** Kilns operate at dangerous temperatures and voltages. Ensure all high-voltage wiring is performed by a qualified electrician. Use appropriate safety equipment and never leave a firing kiln unattended.

## Getting Started

### Prerequisites

- [ESP-IDF v6.1.1](https://docs.espressif.com/projects/esp-idf/en/v6.1.1/esp32s3/get-started/)
- Node.js 18+
- [XcodeGen](https://github.com/yonaskolb/XcodeGen) (for iOS development)

### Dev Container (recommended)

The fastest way to a reproducible toolchain is the VS Code dev container — it
pins the exact ESP-IDF v6.1.1 image CI uses plus Node 24, the static-analysis
tools, and the Claude Code CLI. Open the repo in VS Code and run **Dev
Containers: Reopen in Container**. Everything below (firmware build, web UI,
`make ci`) then works in the container terminal; only flashing needs a bench.
See [docs/devcontainer.md](docs/devcontainer.md).

### Firmware

```bash
# Build web UI assets first
cd web_ui && npm install && npm run build && cd ..

# Gzip assets for SPIFFS
gzip -k -9 spiffs_data/www/assets/*.js spiffs_data/www/assets/*.css

# Build and flash firmware
source ~/.espressif/v6.1.1/esp-idf/export.sh
idf.py build
idf.py flash monitor
```

### Web UI Development

```bash
cd web_ui
npm install
npm run dev    # Starts dev server with mock kiln simulator
```

### iOS App

```bash
# Generate Xcode project
cd ios/Bisque
xcodegen generate
open Bisque.xcodeproj
```

For simulator testing, start the mock server first:

```bash
cd web_ui && npm run mock-server   # HTTP + WebSocket on localhost:8080
```

In the iOS simulator, tap "Use Mock Server" on the connection screen.

<details>
<summary><strong>Simulator / Mock Server</strong></summary>

A mock kiln server simulates the full API (status, profiles, firing, settings, history, autotune, diagnostics) with realistic temperature physics so you can develop and test without hardware.

### Web UI development

The mock server runs automatically as a Vite plugin when you start the web UI dev server:

```bash
cd web_ui
npm run dev
```

The mock is enabled by default. To disable it and proxy to a real kiln instead:

```bash
VITE_MOCK=false npm run dev
```

Control simulation speed with `VITE_MOCK_SPEED` (default `60` = 60x real-time):

```bash
VITE_MOCK_SPEED=120 npm run dev
```

### iOS app development

A standalone mock server is available for testing the iOS app in the Xcode simulator:

```bash
cd web_ui
npm run mock-server
```

This starts an HTTP + WebSocket server on `localhost:8080`. To change the port or simulation speed:

```bash
MOCK_PORT=9000 MOCK_SPEED=120 npm run mock-server
```

### LCD Simulator

A standalone SDL2-based simulator renders the LVGL display UI on your desktop:

```bash
cd simulator
cmake -B build && cmake --build build
./build/bisque_sim
```

Requires SDL2 (`brew install sdl2` on macOS).

</details>

## Architecture

```
main/                 App entry point, FreeRTOS task creation
components/
  app_config/         Pin definitions, hardware constants
  thermocouple/       MAX31856 SPI driver (2 channels)
  pid_control/        PID controller + Ziegler-Nichols auto-tune
  firing_engine/      Multi-segment firing state machine
  safety/             Watchdog, over-temp, fault detection
  cone_table/         Orton cone temperature lookup (022-13)
  history/            Firing history + temperature traces (NVS)
  display/            ST7796S LCD + LVGL UI (adaptive dashboard)
  web_server/         REST API + WebSocket server
  wifi_manager/       Wi-Fi STA/AP + mDNS
web_ui/               React/TypeScript web dashboard
ios/Bisque/           SwiftUI iOS app
simulator/            LVGL SDL2 desktop simulator
tests/host/           Pure-logic + accelerated firing unit tests (CMake/Unity)
docs/                 Wiring diagrams, screenshots, bench smoke test
```

## Testing

CI runs five automated test layers on every PR — pure-logic unit tests
and accelerated firing scenarios (`tests/host/`), a UI screenshot
regression suite (`simulator/ --diff`), web UI unit tests, and a
cross-language API contract test that validates firmware JSON output
against the frontend's zod schemas.

Before tagging a release, run the [bench smoke test](docs/bench-smoke-test.md) — a 3-8 minute hardware
run that verifies the parts CI can't touch: real SSR clicks, real
thermocouple readings, history persistence across reboot.

## Network security

**Bisque assumes the network it sits on is trusted.** It is a LAN-only
device: the HTTP API and the WebSocket telemetry feed are plain `http://`
and `ws://`, with no TLS. Anyone who can see traffic on the same Wi-Fi can
read the API token and every command sent with it.

The optional API token (Settings → API Token) is therefore a lock on the
front door, not protection against a hostile network. It stops a
housemate's laptop or a curious guest from starting a firing; it does not
stop someone who is already capturing your Wi-Fi traffic. Concretely:

- The token is sent as an `Authorization: Bearer` header on every REST
  request and compared in constant time on the device.
- The WebSocket telemetry feed (`/api/v1/ws`) is authenticated by the same
  check as the REST API. Browsers cannot set headers on a WebSocket
  handshake, so the web UI presents the token as a `?token=` query
  parameter instead — which means that on this one route the credential does
  reach anywhere the URL does, including proxy logs and browser history. The
  iOS app uses `URLSession`, which can set the header, and does. Dropping the
  query parameter would lock every browser out of live telemetry, so it is a
  deliberate trade rather than an oversight.
- Firmware updates are fetched over HTTPS with certificate validation
  against the bundled root store, and the downloaded image is checked
  against the SHA-256 in the release manifest. So an OTA is not exposed by
  the local network being readable — its trust rests on GitHub's TLS, not on
  your LAN.

If that trust assumption does not hold for your network, put the kiln on an
isolated VLAN or guest SSID rather than relying on the token. TLS on-device
with certificate pinning in the clients has been considered and is tracked
in [#149](https://github.com/BenSeverson/bisque/issues/149); it is a
significant amount of firmware and app complexity for a home LAN, and has
not been implemented.

**Never expose a kiln controller directly to the internet.** No port
forwarding, no DMZ. This is a device that applies mains power to a heating
element in an unattended room.

## Releases

Firmware is distributed as [GitHub Releases](https://github.com/BenSeverson/bisque/releases),
each with a full ESP32-S3 flash kit and Sigstore build-provenance
attestations. See [RELEASING.md](RELEASING.md) for the versioning scheme and
the procedure for cutting a release.

## License

[MIT](LICENSE)
