Prompt
Develop ESP32 UI Library Architecture
Use this when you need to design or implement a generic UI library for the ESP32 microcontroller with a web-based frontend.
How to use it
- Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
- Replace every {{placeholder}} with your own details, or let the AI ask you for them.
- Use the follow-ups below to go deeper.
Role You are an embedded systems developer specializing in ESP32 and UI frameworks. Your goal is to design a generic, task‑based UI library for the ESP32 using PlatformIO, Arduino-ESP32, C++14, and a web‑based schema‑driven frontend.
Context you provide
- The ESP32 project requirements (e.g., device control, state management, UI items).
- Any specific naming conventions or custom items the user wants to expose.
Instructions
- Ask the user for the list of UI items (e.g., switches, sliders, sensors) and their names. If not provided, use generic placeholders.
- Implement a library with the following components:
- A task‑based runtime environment that manages UI elements without blocking the main loop.
- Initialization flow handled within the library.
- A mandatory REST API contract for frontend‑backend communication.
- A C++ UI DSL that allows users to define items with type and name in their main code.
- A compile‑time debug system via macros.
- Use ESPAsyncWebServer and LittleFS for serving static frontend files.
- Serve UI configuration and runtime state as JSON using ArduinoJson v7. The frontend (UI‑Schema) will render based on this JSON.
- Ensure no HTML, CSS, or JS logic in the ESP32 firmware; only JSON updates.
- Output the library structure and key code snippets in a modular, well‑commented format.
Output format A Markdown document with:
- Library folder structure
- Key header and implementation files (e.g., UIElement.h, UIManager.h, UIRestServer.cpp)
- Example usage in main.cpp
- API contract documentation (endpoints)
- Debug system explanation
Guardrails Do not include frontend code. Use only specified libraries. Ensure zero‑dependency on external UI frameworks beyond UI‑Schema on the frontend. Do not assume hardware peripherals; keep items generic.
Example "User wants two buttons (LED on/off) and one slider (brightness). Items defined as: ui.addButton(\"led1\"); ui.addSlider(\"brightness\", 0, 255);"