← Back to the overview

🛠️ Development & structure

Here I describe how the cocktail machine's controller is built.

The firmware runs on an ESP32 and is written in Rust code. It handles two tasks at the same time: it serves the web interface and drives the stepper motors. Each task runs on its own processor core.

The design at a glance

📱 Browser Phone / tablet / PC Wi-Fi (HTTP) ESP32 Core 0 Wi-Fi + web server serves the web app, accepts HTTP commands Core 1 Motor control generates the step pulses, safety logic, pump Commands ▸ ◂ Status

This keeps the motors running smoothly, even while someone is loading the web interface.

How the two cores exchange data

The web interface

The interface is a single HTML file built into the firmware. It talks to a small HTTP interface, for example:

GET /status GET /dispense?drink=N GET /home GET /moveto GET /estop POST /api/settings POST /api/drinks POST /script

Where the settings are stored

Positions, times and drinks are stored as JSON in the flash memory of the ESP32 and survive every restart. New values are clamped to safe limits before saving.

From recipe to movement

A drink is a list of “slot × portions”. From it, the firmware creates a command sequence for both axes:

(if necessary) home Z → home X →
for each ingredient: X to slot → Sync → per portion: Z up, hold, short return stroke (or pump on) → Sync →
at the end: Z down → homing run → (optional dispensing position).

At each Sync-point the axes wait for each other. Nothing is dosed while the carriage is moving.

Safety features

Technology used

Rust (Edition 2021) ESP-IDF (std) esp-idf-svc embedded-svc serde / serde_json anyhow HTML / CSS / vanilla JS

Source code layout

FileTask
src/main.rsStart-up, Wi-Fi, web server, pins
src/servo.rsMotor control, safety, pump
src/settings.rsSettings and recipe → command sequence
src/config.rsLimits for travel, speed and recipes
src/servo-control-migrated.htmlThe web interface
The cocktail machine is a hobby project and is provided without any warranty.
Home · Legal notice · Privacy