3.2 KiB
Building and Flashing the Frontend
The Calendink Provider uses a modern Svelte 5 frontend, built with Vite and TailwindCSS. The frontend is served directly from the ESP32's www_0 or www_1 LittleFS partition, allowing the user interface to be updated completely independently from the underlying firmware.
1. Prerequisites
Before you can build the frontend, make sure you have Node.js installed on your machine. All frontend code is located inside the frontend/ directory.
cd frontend
npm install
2. Development Mode
During development, you don't need to rebuild and reflash the ESP32 every time you change a button color! You can run the Vite development server on your PC, and it will proxy API requests to the ESP32 over WiFi.
- Ensure the ESP32 is powered on and connected to your local network.
- Update
frontend/.env.developmentwith the IP address of your ESP32 (e.g.,VITE_API_BASE=http://192.168.50.216). - Start the dev server:
npm run dev
3. Building for Production (ESP32)
When you are ready to deploy your frontend changes to the ESP32, you must package everything into a single file and compress it. Our custom build script handles this for you.
Run the following command inside the frontend/ folder:
npm run build:esp32
What this does:
- Runs Vite's production build.
- Inlines all CSS and JS into
index.html(thanks tovite-plugin-singlefile). - Runs
scripts/gzip.jsto heavily compressindex.htmldown to anindex.html.gzfile (~15-20KB). - Outputs the final files to the
frontend/dist/directory.
4. Flashing the Filesystem
Now that frontend/dist/ contains your compressed web app, you must tell the ESP-IDF build system to turn that folder into a LittleFS binary image and flash it.
In your standard ESP-IDF terminal (from the project root, not the frontend/ folder):
-
Enable Web Deployment via Menuconfig (if not already done):
idf.py menuconfig # Navigate to: Calendink Configuration -> Deploy Web Pages # Make sure it is checked (Y) -
Build and Flash:
idf.py build idf.py flash
Because CONFIG_CALENDINK_DEPLOY_WEB_PAGES is enabled, CMake will automatically:
- Detect your
frontend/dist/folder. - Run
mklittlefsto package it intowww.bin. - Flash
www.bindirectly to the activewww_0partition on the ESP32!
5. Over-The-Air (OTA) Updates
Once the backend supports it (Phase 2+), you can update the frontend without using USB or idf.py.
- Build the assets:
npm run build:esp32 - Package the image:
npm run ota:package- This generates a versioned binary in
frontend/bin/(e.g.,www_v1.0.5.bin). - Configuration: If the tool is not in your PATH, add its path to
frontend/.env:(Note: The script also supportsMKLITTLEFS_PATH=C:\path\to\mklittlefs.exelittlefs-python.exeusually found in thebuild/littlefs_py_venv/Scripts/folder).
- This generates a versioned binary in
- Upload via Dashboard:
- Open the dashboard in your browser.
- Go to the Frontend Update section.
- Select the
www.binfile and click Flash. - The device will automatically write to the inactive partition and reboot.