From 490cefc360e11ebcf37de7947f3c7a01dafcad71 Mon Sep 17 00:00:00 2001 From: MangaValk Date: Fri, 16 Oct 2026 16:17:23 +0200 Subject: [PATCH] Home Assistant requests in a task, progress bar, Plex page, bitmap cache - net/ha_api: the HTTP requests run in a FreeRTOS task on core 0; loop() only hands over copies through queues. The web UI's test button polls. No more 3-4 s loop() stalls once a minute; timeout raised to 5 s. - Progress bar page element (page format 4, v3 pages are converted) - Plex user setting (settings v6): {plex_user} in entity ids - Plex page (examples): watchers, play/pause icon, title, progress - Bitmaps cached in RAM: a LittleFS read took ~100 ms on every render and web preview; long JSON lists sent in 2 KB pieces - Backup includes the refresh settings and the Plex user Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 14 +- Pictures/pages/3d-printer.png | Bin 4087 -> 3974 bytes Pictures/pages/aftellen.png | Bin 3745 -> 3789 bytes Pictures/pages/binnen.png | Bin 4310 -> 3927 bytes Pictures/pages/dag-en-nacht-0700.png | Bin 4206 -> 4182 bytes Pictures/pages/dag-en-nacht-1900.png | Bin 4085 -> 4075 bytes Pictures/pages/datum.png | Bin 3967 -> 3789 bytes Pictures/pages/energie.png | Bin 4019 -> 3959 bytes Pictures/pages/plex.png | Bin 0 -> 4022 bytes Pictures/pages/verbruik.png | Bin 4247 -> 4188 bytes Pictures/pages/weer.png | Bin 4162 -> 4043 bytes Pictures/web-ui/bitmaps.png | Bin 182314 -> 183069 bytes Pictures/web-ui/draw.png | Bin 129616 -> 128084 bytes Pictures/web-ui/home-assistant.png | Bin 127531 -> 125684 bytes Pictures/web-ui/pages.png | Bin 412792 -> 414832 bytes Pictures/web-ui/schedule.png | Bin 156569 -> 160044 bytes Pictures/web-ui/settings.png | Bin 184204 -> 186077 bytes Pictures/web-ui/show.png | Bin 346217 -> 358600 bytes Pictures/web-ui/stopwatch.png | Bin 109670 -> 112948 bytes Pictures/web-ui/system.png | Bin 160561 -> 156221 bytes docs/home-assistant.md | 22 +- docs/pages.md | 1 + docs/web-ui.md | 8 +- examples/home-pages.json | 299 ++++++++++++++++++++++--- src/esp32/app.cpp | 5 +- src/esp32/config.h | 12 +- src/esp32/display/bitmap_store.cpp | 51 ++++- src/esp32/display/page_store.cpp | 75 ++++++- src/esp32/logic/page.cpp | 76 +++++++ src/esp32/logic/page.h | 32 ++- src/esp32/logic/page_render.cpp | 34 +++ src/esp32/logic/settings.cpp | 2 +- src/esp32/logic/settings.h | 2 + src/esp32/main.cpp | 3 +- src/esp32/net/ha_api.cpp | 313 ++++++++++++++++++++------- src/esp32/net/ha_api.h | 24 +- src/esp32/system/settings_store.cpp | 18 +- src/esp32/web/page_json.cpp | 10 +- src/esp32/web/web_page.h | 34 ++- src/esp32/web/web_ui.cpp | 51 +++-- test/test_esp32/test_main.cpp | 139 ++++++++++++ tools/make_example_pages.py | 24 +- 42 files changed, 1074 insertions(+), 175 deletions(-) create mode 100644 Pictures/pages/plex.png diff --git a/CLAUDE.md b/CLAUDE.md index c67ecd4..8e7e1e5 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -172,8 +172,18 @@ See README.md for the overview. after adding features; the web page could be served gzipped if it gets tight. - Fonts use the "FDF1" format of `logic/font.h`; the web page writes the same format. `logic/builtin_fonts.cpp` is generated: change `tools/make_builtin_fonts.py` and rerun it. -- Home Assistant values come from HA's REST API (`net/ha_api`), one blocking request per - `loop()` with `HA_HTTP_TIMEOUT`. Keep it that way (watchdog, OTA). +- Home Assistant values come from HA's REST API (`net/ha_api`). The HTTP requests run in + their own FreeRTOS task (core 0, `haApiBegin()`), one at a time; everything else + (entries, watching, values) stays in `loop()`. The task gets copies of what it needs and + answers through a queue of plain structs: never share Strings or other state with it, + and never wait for it in `loop()`. The web UI's test button polls (`{"pending":true}`). + The web server stays in `loop()` on purpose (its handlers touch everything). +- Entity ids may contain `{plex_user}` (`expandEntity()` in `logic/page`), filled in by + `net/ha_api` with `settings.plex_user` in entity id form (`plexUserSlug()`). +- Bitmaps are cached in RAM (`display/bitmap_store`, also missing names): a LittleFS read + takes about 100 ms, and pages are drawn for every frame and every web preview. Writes + must go through `saveBitmap()`/`deleteBitmap()`, which clear the cache. Long JSON lists + are sent in pieces of about 2 KB (`sendPiece()` in `web_ui.cpp`). - Check the page's JavaScript after changes: extract the `