1 Commits
Author SHA1 Message Date
jimmy b2077c0199 Improve ESP-NOW messaging and tab defaults
- Use shared ESPNOW payload limit and message splitting
- Expand default tab names and add flash/build artifacts.

Made-with: Cursor
2026-03-14 02:41:08 +13:00
291 changed files with 15323 additions and 39552 deletions

No files matched your search

-3
View File
@@ -1,3 +0,0 @@
# graphify
- **graphify** (`.claude/skills/graphify/SKILL.md`) - any input to knowledge graph. Trigger: `/graphify`
When the user types `/graphify`, use the installed graphify skill or instructions before doing anything else.
@@ -1 +0,0 @@
0.9.101
-797
View File
@@ -1,797 +0,0 @@
---
name: graphify
description: "Use for any question about a codebase, its architecture, file relationships, or project content — especially when graphify-out/ exists, where the question should be treated as a graphify query first. Turns any input (code, docs, papers, images, videos) into a persistent knowledge graph with god nodes, community detection, and query/path/explain tools."
---
# /graphify
Turn any folder of files into a navigable knowledge graph with community detection, an honest audit trail, and three outputs: interactive HTML, GraphRAG-ready JSON, and a plain-language GRAPH_REPORT.md.
## Usage
```
/graphify # full pipeline on current directory (HTML viz; add --obsidian for a vault)
/graphify <path> # full pipeline on specific path
/graphify https://github.com/<owner>/<repo> # clone repo then run full pipeline on it
/graphify https://github.com/<owner>/<repo> --branch <branch> # clone a specific branch
/graphify <url1> <url2> ... # clone multiple repos, build each, merge into one cross-repo graph
/graphify <path> --mode deep # thorough extraction, richer INFERRED edges
/graphify <path> --update # incremental - re-extract only new/changed files
/graphify <path> --directed # build directed graph (preserves edge direction: source→target)
/graphify <path> --whisper-model medium # use a larger Whisper model for better transcription accuracy
/graphify <path> --cluster-only # rerun clustering on existing graph
/graphify <path> --no-viz # skip visualization, just report + JSON
/graphify <path> --html # (HTML is generated by default - this flag is a no-op)
/graphify <path> --svg # also export graph.svg (embeds in Notion, GitHub)
/graphify <path> --graphml # export graph.graphml (Gephi, yEd)
/graphify <path> --neo4j # generate graphify-out/cypher.txt for Neo4j
/graphify <path> --neo4j-push bolt://localhost:7687 # push directly to Neo4j
/graphify <path> --falkordb # generate graphify-out/cypher.txt for FalkorDB
/graphify <path> --falkordb-push falkordb://localhost:6379 # push directly to FalkorDB
/graphify <path> --mcp # start MCP stdio server for agent access
/graphify <path> --watch # watch folder, auto-rebuild on code changes (no LLM needed)
/graphify <path> --wiki # build agent-crawlable wiki (index.md + one article per community)
/graphify <path> --obsidian --obsidian-dir ~/vaults/my-project # write vault to custom path (e.g. existing vault)
/graphify add <url> # fetch URL, save to ./raw, update graph
/graphify add <url> --author "Name" # tag who wrote it
/graphify add <url> --contributor "Name" # tag who added it to the corpus
/graphify query "<question>" # BFS traversal - broad context
/graphify query "<question>" --dfs # DFS - trace a specific path
/graphify query "<question>" --budget 1500 # cap answer at N tokens
/graphify path "AuthModule" "Database" # shortest path between two concepts
/graphify explain "SwinTransformer" # plain-language explanation of a node
```
## What graphify is for
Drop any folder of code, docs, papers, images, or video into graphify and get a queryable knowledge graph. Persistent across sessions, honest audit trail (EXTRACTED/INFERRED/AMBIGUOUS), community detection surfaces cross-document connections you wouldn't think to ask about.
**When a graph is worth building:** this applies when you are choosing a tool yourself; if the user invoked `/graphify`, follow that request as asked. AST extraction of code is fast and free, but semantic extraction of docs, papers and images runs the model over every file, which can cost minutes and tens of thousands of tokens.
If a graph already exists, query it. With no graph, one targeted lookup ("where is X defined", "what calls Y" in an ordinary-sized codebase) is faster and free with a plain text search such as `grep` and `Read`: search directly instead of running the steps below, and mention that a graph can be built if the user wants one. Build one when you expect many questions against this corpus, the corpus is large or unfamiliar, the question needs links text search cannot see (doc to code, across documents), or it is structural (communities, bridges, import cycles).
## What You Must Do When Invoked
If the user invoked `/graphify --help` or `/graphify -h` (with no other arguments), print the contents of the `## Usage` section above verbatim and stop. Do not run any commands, do not detect files, do not default the path to `.`. Just print the Usage block and return.
**Fast path — existing graph:** Before doing anything else, check whether `graphify-out/graph.json` exists. The expected location is `graphify-out/graph.json` relative to the **current working directory** (i.e. the project root where you are running commands). If it exists AND the user's request is a natural-language question about the codebase (e.g. "How does X work?", "What calls Y?", "Trace the data flow through Z") and NOT an explicit rebuild command (`--update`, `--cluster-only`, or a bare path/URL that implies fresh extraction): **skip Steps 1–5 entirely and jump straight to `## For /graphify query`.** Run `graphify query "<question>"` immediately. Do not run detect. Do not check corpus size. Do not ask the user to narrow. The graph is already built — use it.
If no path was given, use `.` (current directory). Do not ask the user for a path.
If the path argument starts with `https://github.com/` or `http://github.com/`, treat it as a GitHub URL - run Step 0 before anything else, then continue with the resolved local path.
Follow these steps in order unless the fast path above applies.
### Step 0 - GitHub repos and multi-path merge (only if a URL or several paths)
Only when the path is one or more `https://github.com/...` URLs, or several local subfolders to merge. See `references/github-and-merge.md` for the clone, cross-repo merge, and monorepo flow, then continue with the resolved local path. A plain local path skips this step.
### Step 1 - Ensure graphify is installed
```bash
# Detect the correct Python interpreter (handles uv tool, pipx, venv, system installs)
PYTHON=""
GRAPHIFY_BIN=$(which graphify 2>/dev/null)
# 1. uv tool installs — most reliable on modern Mac/Linux
if [ -z "$PYTHON" ] && command -v uv >/dev/null 2>&1; then
_UV_PY=$(uv tool run --from graphifyy python -c "import sys; print(sys.executable)" 2>/dev/null)
if [ -n "$_UV_PY" ]; then PYTHON="$_UV_PY"; fi
fi
# 2. Read shebang from graphify binary (pipx and direct pip installs)
if [ -z "$PYTHON" ] && [ -n "$GRAPHIFY_BIN" ]; then
_SHEBANG=$(head -1 "$GRAPHIFY_BIN" | tr -d '#!')
case "$_SHEBANG" in
*[!a-zA-Z0-9/_.@-]*) ;;
*) "$_SHEBANG" -c "import graphify" 2>/dev/null && PYTHON="$_SHEBANG" ;;
esac
fi
# 3. Fall back to python3
if [ -z "$PYTHON" ]; then PYTHON="python3"; fi
if ! "$PYTHON" -c "import graphify" 2>/dev/null; then
if command -v uv >/dev/null 2>&1; then
uv tool install --upgrade graphifyy -q 2>&1 | tail -3
_UV_PY=$(uv tool run --from graphifyy python -c "import sys; print(sys.executable)" 2>/dev/null)
if [ -n "$_UV_PY" ]; then PYTHON="$_UV_PY"; fi
else
"$PYTHON" -m pip install graphifyy -q 2>/dev/null \
|| "$PYTHON" -m pip install graphifyy -q --break-system-packages 2>&1 | tail -3
fi
fi
# Write interpreter path for all subsequent steps (persists across invocations)
mkdir -p graphify-out
"$PYTHON" -c "import sys; open('graphify-out/.graphify_python', 'w', encoding='utf-8').write(sys.executable)"
# Save scan root so `graphify update` (no args) knows where to look next time.
# The scan path is passed through a quoted heredoc, never substituted into the
# command line itself: a bare `cd <path>` (or an unquoted heredoc, which
# still expands $()/backticks in its body) would let a malicious path execute
# as shell code the moment this line runs.
"$PYTHON" -c "import os, sys; out_path = os.path.abspath('graphify-out/.graphify_root'); os.chdir(sys.stdin.readline().rstrip('\n')); open(out_path, 'w', encoding='utf-8').write(os.getcwd())" <<'GRAPHIFY_ROOT_EOF'
INPUT_PATH
GRAPHIFY_ROOT_EOF
```
If the import succeeds, print nothing and move straight to Step 2.
**In every subsequent bash block, replace `python3` with `$(cat graphify-out/.graphify_python)` to use the correct interpreter.**
### Step 2 - Detect files
```bash
$(cat graphify-out/.graphify_python) -c "
import json
from graphify.detect import detect
from pathlib import Path
from graphify.paths import out_path
from graphify.watch import _read_build_excludes, _read_build_gitignore
result = detect(Path('INPUT_PATH'), extra_excludes=_read_build_excludes(out_path()), gitignore=_read_build_gitignore(out_path()))
# Write the sidecar from Python, not a shell redirect, so the same block renders
# on PowerShell hosts without console-encoding drift (#2528).
Path('graphify-out/.graphify_detect.json').write_text(json.dumps(result, ensure_ascii=False), encoding=\"utf-8\")
print(f'Detected {result[\"total_files\"]} files')
"
```
Replace INPUT_PATH with the actual path the user provided. Do NOT cat or print the JSON - read it silently and present a clean summary instead:
```
Corpus: X files · ~Y words
code: N files (.py .ts .go ...)
docs: N files (.md .txt ...)
papers: N files (.pdf ...)
images: N files
video: N files (.mp4 .mp3 ...)
```
Omit any category with 0 files from the summary.
Then act on it:
- If `total_files` is 0: stop with "No supported files found in [path]."
- If `skipped_sensitive` is non-empty: report the count and list the skipped file names, so a wrongly-flagged source or doc is visible and can be renamed or moved (#2106).
- If `total_words` > 2,000,000 OR `total_files` > 500: show the warning. Then compute the top 5 first-level subdirectories by file count:
- Read `scan_root` from the detect JSON (always an absolute path to the resolved INPUT_PATH).
- Concatenate all file lists across all types (`code`, `document`, `paper`, `image`, `video`).
- Filter out any path that starts with `scan_root + "/graphify-out/"` to exclude converted sidecars.
- For each file, strip the `scan_root` prefix and take the first path component. Files directly in `scan_root` with no subdirectory count as `(root)`.
- If all files are in `(root)` with no subdirectories, do not ask to narrow — no subfolders exist. Instead suggest `--no-cluster` to skip the expensive clustering step and proceed.
- Otherwise rank by count, show the top 5 with file counts, then ask which subfolder to run on. Wait for the user's answer before proceeding.
- Otherwise: proceed directly to Step 2.5 if video files were detected, or Step 3 if not.
### Step 2.5 - Video and audio (only if video files detected)
Skip this step entirely if `detect` returned zero `video` files. When the corpus has video or audio, see `references/transcribe.md` to transcribe them to text first, then treat the transcripts as doc files in Step 3.
### Step 3 - Extract entities and relationships
**Before starting:** note whether `--mode deep` was given. You must pass `DEEP_MODE=true` to every subagent in Step B2 if it was. Track this from the original invocation - do not lose it.
This step has two parts: **structural extraction** (deterministic, free) and **semantic extraction** (LLM, costs tokens).
> **graphify needs no API key. Never ask the user for one, and never block on one.** Code is extracted structurally (AST) with no LLM and no key at all — a code-only corpus (the common `/graphify .` on a repo) skips semantic extraction entirely, so it needs nothing here: go straight to Part A and skip Part B. Semantic extraction (only for docs, papers, and images) uses Gemini **only if** `GEMINI_API_KEY`/`GOOGLE_API_KEY` is already set; otherwise the host agent itself is the LLM. graphify does **not** read `ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, or any other provider key. If you catch yourself about to prompt for, wait on, or stop because of a missing API key, that is a misread of this skill — proceed without one.
**Before semantic extraction:** check whether `GEMINI_API_KEY` or `GOOGLE_API_KEY` is set. If neither is set, print this one-liner to the user:
> Tip: set `GEMINI_API_KEY` or `GOOGLE_API_KEY` to use Gemini for semantic extraction (`pip install 'graphifyy[gemini]'`).
Print it once, then continue — do not wait for the user to supply a key. If `GEMINI_API_KEY` or `GOOGLE_API_KEY` IS set, use `graphify.llm.extract_corpus_parallel(files, backend="gemini")` for semantic extraction instead of dispatching subagents. The default Gemini model is `gemini-3-flash-preview`; set `GRAPHIFY_GEMINI_MODEL` or pass `--model` in headless CLI flows to override it.
> **No other API keys are read.** When `GEMINI_API_KEY`/`GOOGLE_API_KEY` are unset, semantic extraction falls to the host agent itself — the running session is the LLM. On a host that dispatches subagents (e.g. Claude Code), dispatch them as written in Part B. On a host that runs the CLI directly in a terminal and cannot dispatch subagents, do not stall: a code-only corpus has no semantic work, so write the empty semantic file (Part B "Fast path") and continue to Part C; for a corpus with docs/papers/images, either set a Gemini key or extract those inline yourself, but in no case prompt for `ANTHROPIC_API_KEY` — that prompt is a misread of this skill.
**Run Part A (AST) and Part B (semantic) in parallel. Dispatch all semantic subagents AND start AST extraction in the same message. Both can run simultaneously since they operate on different file types. Merge results in Part C as before.**
Note: Parallelizing AST + semantic saves 5-15s on large corpora. AST is deterministic and fast; start it while subagents are processing docs/papers.
#### Part A - Structural extraction for code files
For any code files detected, run AST extraction in parallel with Part B subagents:
```bash
$(cat graphify-out/.graphify_python) -c "
import sys, json
from graphify.extract import collect_files, extract
from pathlib import Path
import json
code_files = []
detect = json.loads(Path('graphify-out/.graphify_detect.json').read_text(encoding=\"utf-8\"))
for f in detect.get('files', {}).get('code', []):
code_files.extend(collect_files(Path(f)) if Path(f).is_dir() else [Path(f)])
if code_files:
# root= anchors node ids and source_file on the scan root; cache_root only says
# where graphify-out/cache lives. Pass both: without root= the anchor falls back
# to cache_root, so pointing the cache elsewhere would rename every node (#3727).
result = extract(code_files, cache_root=Path('INPUT_PATH'), root=Path('INPUT_PATH'))
Path('graphify-out/.graphify_ast.json').write_text(json.dumps(result, indent=2, ensure_ascii=False), encoding=\"utf-8\")
print(f'AST: {len(result[\"nodes\"])} nodes, {len(result[\"edges\"])} edges')
else:
Path('graphify-out/.graphify_ast.json').write_text(json.dumps({'nodes':[],'edges':[],'input_tokens':0,'output_tokens':0}, ensure_ascii=False), encoding=\"utf-8\")
print('No code files - skipping AST extraction')
"
```
#### Part B - Semantic extraction (parallel subagents)
**Fast path:** If detection found zero docs, papers, and images (code-only corpus), skip Part B entirely and go straight to Part C. AST handles code - there is nothing for semantic subagents to do. **First write an empty semantic file** so Part C's merge has its input (it reads `.graphify_semantic.json` unconditionally; without this a code-only run hits `FileNotFoundError`):
```bash
$(cat graphify-out/.graphify_python) -c "
import json
from pathlib import Path
Path('graphify-out/.graphify_semantic.json').write_text(json.dumps({'nodes':[],'edges':[],'hyperedges':[],'input_tokens':0,'output_tokens':0}), encoding='utf-8')
"
```
**MANDATORY: You MUST use the Agent tool here. Reading files yourself one-by-one is forbidden - it is 5-10x slower. If you do not use the Agent tool you are doing this wrong.**
Before dispatching subagents, print a timing estimate:
- Load `total_words` and file counts from `graphify-out/.graphify_detect.json`
- Estimate agents needed: `ceil(uncached_non_code_files / 22)` (chunk size is 20-25 files, capped at ~6000 total lines)
- Estimate time: ~45s per agent batch (they run in parallel, so total ≈ 45s × ceil(agents/parallel_limit))
- Print: "Semantic extraction: ~N files → X agents, estimated ~Ys"
**Step B0 - Check extraction cache first**
Before dispatching any subagents, check which files already have cached extraction results:
SPEC_PATH below is the **absolute** path of the `references/extraction-spec.md` that ships beside this SKILL.md — the same file Step B2 loads and hands to every subagent. It is the extraction prompt, so cache entries are attributed to it: when a graphify upgrade changes the prompt, entries produced by the old one are re-extracted instead of replayed, and unchanged prompts keep their entries (#1939). Substitute the real path in both Step B0 and Step B3 — pass the same one to each, and do not drop the argument.
```bash
$(cat graphify-out/.graphify_python) -c "
import json
from graphify.cache import check_semantic_cache
from pathlib import Path
detect = json.loads(Path('graphify-out/.graphify_detect.json').read_text(encoding=\"utf-8\"))
# Only content files go to semantic extraction. Code is already covered structurally
# by the AST pass (Part A); flattening every category here makes subagents re-read
# every source file (#1392). Video is transcribed to a document in Step 2.5 first.
all_files = [f for cat in ('document', 'paper', 'image') for f in detect['files'].get(cat, [])]
cached_nodes, cached_edges, cached_hyperedges, uncached = check_semantic_cache(all_files, root='INPUT_PATH', prompt_file='SPEC_PATH')
# Always (re)write the cache file: write hits, else DELETE any leftover from a prior
# run so Part C never merges a stale .graphify_cached.json (#1392).
if cached_nodes or cached_edges or cached_hyperedges:
Path('graphify-out/.graphify_cached.json').write_text(json.dumps({'nodes': cached_nodes, 'edges': cached_edges, 'hyperedges': cached_hyperedges}, ensure_ascii=False), encoding=\"utf-8\")
else:
Path('graphify-out/.graphify_cached.json').unlink(missing_ok=True)
Path('graphify-out/.graphify_uncached.txt').write_text('\n'.join(uncached), encoding=\"utf-8\")
# Nothing has been dispatched yet, so any chunk file on disk is a leftover from an
# interrupted run, and Step B3 merges every .graphify_chunk_*.json it finds.
for stale in Path('graphify-out').glob('.graphify_chunk_*.json'):
stale.unlink()
print(f'Cache: {len(all_files)-len(uncached)} files hit, {len(uncached)} files need extraction')
"
```
Only dispatch subagents for files listed in `graphify-out/.graphify_uncached.txt`. If all files are cached, skip Steps B1 and B2 but still run Step B3's commands: its merge is the only Part B step that writes `graphify-out/.graphify_semantic.json`, and Part C reads that file unconditionally. Do not write an empty `.graphify_semantic.json` instead, because that drops every cached node.
**Step B1 - Split into chunks**
Load files from `graphify-out/.graphify_uncached.txt`. Split into chunks bounded by BOTH limits: at most 20-25 files AND at most ~6000 total lines per chunk. A text file longer than 2000 lines gets a chunk to itself - that is past the Read tool's single-call cap, so sharing a chunk with other files guarantees it is only partly read. Each image gets its own chunk (vision needs separate context). When splitting, group files from the same directory together so related artifacts land in the same chunk and cross-file relationships are more likely to be extracted.
Both bounds matter. The line bound is not only about the 2000-line Read cap: a subagent holding 25 files splits its attention across all of them and skims the dense ones, and a 590-line plan can come back with zero nodes that way. Bounding content as well as file count is what keeps a chunk's coverage honest (#2225).
**Step B2 - Dispatch ALL subagents in a single message**
Call the Agent tool multiple times IN THE SAME RESPONSE - one call per chunk. This is the only way they run in parallel. If you make one Agent call, wait, then make another, you are doing it sequentially and defeating the purpose.
**IMPORTANT - subagent type:** Always use `subagent_type="general-purpose"`. Do NOT use `Explore` - it is read-only and cannot write chunk files to disk, which silently drops extraction results. General-purpose has Write and Bash access which the subagent needs.
Concrete example for 3 chunks:
```
[Agent tool call 1: files 1-15, subagent_type="general-purpose"]
[Agent tool call 2: files 16-30, subagent_type="general-purpose"]
[Agent tool call 3: files 31-45, subagent_type="general-purpose"]
```
All three in one message. Not three separate messages.
Each subagent receives this exact prompt (substitute FILE_LIST, CHUNK_NUM, TOTAL_CHUNKS, DEEP_MODE, and CHUNK_PATH).
CHUNK_PATH must be an **absolute** path — derive it before dispatching:
```bash
PROJECT_ROOT=$(pwd) # cwd — where Part C globs graphify-out/ (NOT .graphify_root/scan dir, #1392)
# Then for chunk N: CHUNK_PATH="${PROJECT_ROOT}/graphify-out/.graphify_chunk_0N.json"
```
Subagent prompt template:
See `references/extraction-spec.md` for the exact subagent prompt (JSON schema, node-ID rules, confidence rubric, frontmatter, hyperedge, and vision rules). Load it only here, only when at least one chunk holds a doc, paper, or image; a pure-code corpus has skipped Part B and never reads it. Pass each subagent that prompt verbatim with FILE_LIST, CHUNK_NUM, TOTAL_CHUNKS, DEEP_MODE, and CHUNK_PATH substituted, and have it write the result to CHUNK_PATH.
**Step B3 - Collect, cache, and merge**
Wait for all subagents. For each result:
- Check that `graphify-out/.graphify_chunk_NN.json` exists on disk — this is the success signal
- If the file exists and contains valid JSON with `nodes` and `edges`, include it and save to cache
- If the file is missing, the subagent was likely dispatched as read-only (Explore type) — print a warning: "chunk N missing from disk — subagent may have been read-only. Re-run with general-purpose agent." Do not silently skip.
- If a subagent failed or returned invalid JSON, print a warning and skip that chunk - do not abort
If more than half the chunks failed or are missing, stop and tell the user to re-run and ensure `subagent_type="general-purpose"` is used.
**Step B3.5 - Verify each reported file was actually read to its end**
A subagent that only read the first Read call's worth of a long file still writes a well-formed chunk, so "chunk file exists and parses" is not evidence of coverage. Compare each file's self-reported `coverage` against its real length:
```bash
$(cat graphify-out/.graphify_python) -c "
import json, glob
from pathlib import Path
covered = {}
for c in sorted(glob.glob('graphify-out/.graphify_chunk_*.json')):
d = json.loads(Path(c).read_text(encoding=\"utf-8\"))
for src, n in (d.get('coverage') or {}).items():
covered[src] = max(covered.get(src, 0), int(n))
partial = []
for src, n in sorted(covered.items()):
p = Path(src)
if not p.is_absolute():
p = Path('INPUT_PATH') / src
if not p.is_file():
continue
total = sum(1 for _ in p.open(encoding='utf-8', errors='replace'))
if total and n < total:
partial.append((src, n, total))
Path('graphify-out/.graphify_partial.txt').write_text('\n'.join(s for s, _, _ in partial), encoding=\"utf-8\")
if partial:
print(f'WARNING: {len(partial)} file(s) were only partly read. They are cached as partial and retried on the next --update:')
for src, n, total in partial:
print(f' {src}: read {n} of {total} lines')
else:
print('Coverage OK - every file a subagent reported was read to its last line')
"
```
Tell the user which files came up short and what was lost (the line counts are printed above). The nodes already extracted for those files are kept - they are still true - but the file is cached as partial and left unstamped in the manifest below, so the next `--update` re-dispatches it and replace-on-re-extract swaps the partial node set for a complete one. This is the same mechanism the library path uses for a truncated LLM response (#933, #1950), so both paths now recover instead of silently keeping a half-read file forever. A file a subagent did not report at all is not counted as partial - there is nothing to compare against - which is why the prompt rule in `references/extraction-spec.md` asks for the count in the first place.
Merge all chunk files into `.graphify_semantic_new.json`. **After each Agent call completes, read the real token counts from the Agent tool result's `usage` field and write them back into the chunk JSON before merging** — the chunk JSON itself always has placeholder zeros. Then run:
```bash
$(cat graphify-out/.graphify_python) -c "
import json, glob
from pathlib import Path
chunks = sorted(glob.glob('graphify-out/.graphify_chunk_*.json'))
all_nodes, all_edges, all_hyperedges = [], [], []
total_in, total_out = 0, 0
for c in chunks:
d = json.loads(Path(c).read_text(encoding=\"utf-8\"))
all_nodes += d.get('nodes', [])
all_edges += d.get('edges', [])
all_hyperedges += d.get('hyperedges', [])
total_in += d.get('input_tokens', 0)
total_out += d.get('output_tokens', 0)
Path('graphify-out/.graphify_semantic_new.json').write_text(json.dumps({
'nodes': all_nodes, 'edges': all_edges, 'hyperedges': all_hyperedges,
'input_tokens': total_in, 'output_tokens': total_out,
}, indent=2, ensure_ascii=False), encoding=\"utf-8\")
print(f'Merged {len(chunks)} chunks: {total_in:,} in / {total_out:,} out tokens')
"
```
Save new results to cache. Pass the same SPEC_PATH as Step B0 — it stamps each entry with the prompt that produced it, and a write under a different prompt than the read lands where the next run won't look (#1939):
```bash
$(cat graphify-out/.graphify_python) -c "
import json
from graphify.cache import save_semantic_cache
from pathlib import Path
new = json.loads(Path('graphify-out/.graphify_semantic_new.json').read_text(encoding=\"utf-8\")) if Path('graphify-out/.graphify_semantic_new.json').exists() else {'nodes':[],'edges':[],'hyperedges':[]}
uncached = [line for line in Path('graphify-out/.graphify_uncached.txt').read_text(encoding=\"utf-8\").splitlines() if line]
# A partly-read file is cached with partial: True, which load_cached treats as a MISS,
# so the next --update re-dispatches it instead of serving a truncated extraction forever
# (#2225). Same contract the library path uses for a truncated LLM response (#933/#1950).
partial = [line for line in Path('graphify-out/.graphify_partial.txt').read_text(encoding=\"utf-8\").splitlines() if line] if Path('graphify-out/.graphify_partial.txt').exists() else []
saved = save_semantic_cache(new.get('nodes', []), new.get('edges', []), new.get('hyperedges', []), root='INPUT_PATH', allowed_source_files=uncached, prompt_file='SPEC_PATH', partial_source_files=partial)
note = f' ({len(partial)} left partial for retry)' if partial else ''
print(f'Cached {saved} files' + note)
"
```
Merge cached + new results into `graphify-out/.graphify_semantic.json`:
```bash
$(cat graphify-out/.graphify_python) -c "
import json
from pathlib import Path
cached = json.loads(Path('graphify-out/.graphify_cached.json').read_text(encoding=\"utf-8\")) if Path('graphify-out/.graphify_cached.json').exists() else {'nodes':[],'edges':[],'hyperedges':[]}
new = json.loads(Path('graphify-out/.graphify_semantic_new.json').read_text(encoding=\"utf-8\")) if Path('graphify-out/.graphify_semantic_new.json').exists() else {'nodes':[],'edges':[],'hyperedges':[]}
all_nodes = cached['nodes'] + new.get('nodes', [])
all_edges = cached['edges'] + new.get('edges', [])
all_hyperedges = cached.get('hyperedges', []) + new.get('hyperedges', [])
seen = set()
deduped = []
for n in all_nodes:
if n['id'] not in seen:
seen.add(n['id'])
deduped.append(n)
merged = {
'nodes': deduped,
'edges': all_edges,
'hyperedges': all_hyperedges,
'input_tokens': new.get('input_tokens', 0),
'output_tokens': new.get('output_tokens', 0),
}
Path('graphify-out/.graphify_semantic.json').write_text(json.dumps(merged, indent=2, ensure_ascii=False), encoding=\"utf-8\")
print(f'Extraction complete - {len(deduped)} nodes, {len(all_edges)} edges ({len(cached[\"nodes\"])} from cache, {len(new.get(\"nodes\",[]))} new)')
"
```
Clean up temp files: `rm -f graphify-out/.graphify_cached.json graphify-out/.graphify_uncached.txt graphify-out/.graphify_semantic_new.json`
#### Part C - Merge AST + semantic into final extraction
```bash
$(cat graphify-out/.graphify_python) -c "
import sys, json
from pathlib import Path
ast = json.loads(Path('graphify-out/.graphify_ast.json').read_text(encoding=\"utf-8\"))
sem = json.loads(Path('graphify-out/.graphify_semantic.json').read_text(encoding=\"utf-8\"))
# Stamp tier provenance on the semantic side. build._is_ast_tier reads
# _origin when present and otherwise guesses from the SHAPE of
# source_location ('L<line>' means AST). A subagent that writes 'L12' for a
# doc section therefore made that node read as AST, and the next
# graphify update deleted it along with the re-extracted code file it
# seemed to belong to (#2843). extract() stamps its own items 'ast'; the
# semantic side must say so explicitly.
for n in sem['nodes']:
n.setdefault('_origin', 'semantic')
for e in sem['edges']:
e.setdefault('_origin', 'semantic')
# Merge: AST nodes first, semantic nodes deduplicated by id
seen = {n['id'] for n in ast['nodes']}
merged_nodes = list(ast['nodes'])
for n in sem['nodes']:
if n['id'] not in seen:
merged_nodes.append(n)
seen.add(n['id'])
merged_edges = ast['edges'] + sem['edges']
merged_hyperedges = sem.get('hyperedges', [])
merged = {
'nodes': merged_nodes,
'edges': merged_edges,
'hyperedges': merged_hyperedges,
'input_tokens': sem.get('input_tokens', 0),
'output_tokens': sem.get('output_tokens', 0),
}
Path('graphify-out/.graphify_extract.json').write_text(json.dumps(merged, indent=2, ensure_ascii=False), encoding=\"utf-8\")
total = len(merged_nodes)
edges = len(merged_edges)
print(f'Merged: {total} nodes, {edges} edges ({len(ast[\"nodes\"])} AST + {len(sem[\"nodes\"])} semantic)')
"
```
### Step 4 - Build graph, cluster, analyze, generate outputs
**Before starting:** the code blocks below pass `directed=IS_DIRECTED` to `build_from_json()`. Replace `IS_DIRECTED` with `True` if `--directed` was given (builds a `DiGraph` preserving edge direction source→target), otherwise `False` (the default undirected `Graph`). Substitute it the same way you substitute `INPUT_PATH` — do not leave the literal `IS_DIRECTED` in the code.
```bash
mkdir -p graphify-out
$(cat graphify-out/.graphify_python) -c "
import sys, json
from graphify.build import build_from_json
from graphify.cluster import cluster, score_all
from graphify.analyze import god_nodes, surprising_connections, suggest_questions
from graphify.report import generate
from graphify.export import to_json
from pathlib import Path
extraction = json.loads(Path('graphify-out/.graphify_extract.json').read_text(encoding=\"utf-8\"))
detection = json.loads(Path('graphify-out/.graphify_detect.json').read_text(encoding=\"utf-8\"))
# root= mirrors the --update runbook (#1361): relativize source_file to the same
# base so the full build and incremental --update never drift apart on re-extract.
G = build_from_json(extraction, root='INPUT_PATH', directed=IS_DIRECTED)
# Guard BEFORE any write: an empty extraction must not clobber a good graph.json /
# GRAPH_REPORT.md / analysis sidecar. Check immediately after build (#1392).
if G.number_of_nodes() == 0:
print('ERROR: Graph is empty - extraction produced no nodes.')
print('Possible causes: all files were skipped, binary-only corpus, or extraction failed.')
raise SystemExit(1)
communities = cluster(G)
cohesion = score_all(G, communities)
tokens = {'input': extraction.get('input_tokens', 0), 'output': extraction.get('output_tokens', 0)}
gods = god_nodes(G)
surprises = surprising_connections(G, communities)
labels = {cid: 'Community ' + str(cid) for cid in communities}
# Placeholder questions - regenerated with real labels in Step 5
questions = suggest_questions(G, communities, labels)
# Export FIRST and honor the #479 shrink-guard: to_json returns False (writing
# nothing) when the new graph is smaller than the existing graph.json. Only write
# GRAPH_REPORT.md + the analysis sidecar when the graph was actually written, so
# they never describe a graph that graph.json doesn't contain (#1392).
wrote = to_json(G, communities, 'graphify-out/graph.json')
if not wrote:
print('ERROR: refused to shrink graphify-out/graph.json (existing graph has more nodes; #479).')
print('If this shrink is intentional (you deleted files), re-run a full build with --force.')
raise SystemExit(1)
report = generate(G, communities, cohesion, labels, gods, surprises, detection, tokens, 'INPUT_PATH', suggested_questions=questions)
Path('graphify-out/GRAPH_REPORT.md').write_text(report, encoding=\"utf-8\")
analysis = {
'communities': {str(k): v for k, v in communities.items()},
'cohesion': {str(k): v for k, v in cohesion.items()},
'gods': gods,
'surprises': surprises,
'questions': questions,
}
Path('graphify-out/.graphify_analysis.json').write_text(json.dumps(analysis, indent=2, ensure_ascii=False), encoding=\"utf-8\")
print(f'Graph: {G.number_of_nodes()} nodes, {G.number_of_edges()} edges, {len(communities)} communities')
"
```
If this step prints `ERROR: Graph is empty`, stop and tell the user what happened - do not proceed to labeling or visualization.
Replace INPUT_PATH with the actual path.
### Step 4.5 - Graph health check (read-only integrity gate)
A non-destructive diagnostic on the extraction, before labeling. It surfaces edge collapse, dangling/missing endpoints, and self-loops — the silent-corruption modes of incremental updates and AST/LLM id mismatches. Read-only; never aborts.
```bash
$(cat graphify-out/.graphify_python) -c "
import json
from pathlib import Path
from graphify.diagnostics import diagnose_extraction, format_diagnostic_report
extraction = json.loads(Path('graphify-out/.graphify_extract.json').read_text(encoding=\"utf-8\"))
summary = diagnose_extraction(extraction, directed=IS_DIRECTED, root='INPUT_PATH')
print(format_diagnostic_report(summary))
flags = [f'{summary[k]} {label}' for k, label in (
('dangling_endpoint_edges', 'dangling-endpoint edges'),
('missing_endpoint_edges', 'missing-endpoint edges'),
('self_loop_edges', 'self-loop edges'),
('directed_same_endpoint_collapsed_edges', 'collapsed (directed) edges'),
('undirected_same_endpoint_collapsed_edges', 'collapsed (undirected) edges'),
) if summary.get(k, 0)]
print('GRAPH HEALTH WARNING: ' + '; '.join(flags) + ' - graph may be incomplete/corrupt.' if flags else 'Graph health: OK (no dangling/missing/collapsed edges).')
"
```
Substitute `IS_DIRECTED` and `INPUT_PATH` as in Step 4. If a `GRAPH HEALTH WARNING` prints, surface it in the final summary (do not abort — the graph is still usable, but the integrity issue must be visible, per the Honesty Rules).
### Step 5 - Label communities
Read `graphify-out/.graphify_analysis.json`. For each community key, look at its node labels and write a 2-5 word plain-language name (e.g. "Attention Mechanism", "Training Pipeline", "Data Loading").
Then regenerate the report and save the labels for the visualizer:
```bash
$(cat graphify-out/.graphify_python) -c "
import sys, json
from graphify.build import build_from_json
from graphify.cluster import score_all
from graphify.analyze import god_nodes, surprising_connections, suggest_questions
from graphify.report import generate
from graphify.export import to_json
from pathlib import Path
extraction = json.loads(Path('graphify-out/.graphify_extract.json').read_text(encoding=\"utf-8\"))
detection = json.loads(Path('graphify-out/.graphify_detect.json').read_text(encoding=\"utf-8\"))
analysis = json.loads(Path('graphify-out/.graphify_analysis.json').read_text(encoding=\"utf-8\"))
# root= as in Step 4 / the --update runbook (#1361) — same base for node-key parity.
G = build_from_json(extraction, root='INPUT_PATH', directed=IS_DIRECTED)
communities = {int(k): v for k, v in analysis['communities'].items()}
cohesion = {int(k): v for k, v in analysis['cohesion'].items()}
tokens = {'input': extraction.get('input_tokens', 0), 'output': extraction.get('output_tokens', 0)}
# LABELS - replace these with the names you chose above
labels = LABELS_DICT
# Regenerate questions with real community labels (labels affect question phrasing)
questions = suggest_questions(G, communities, labels)
report = generate(G, communities, cohesion, labels, analysis['gods'], analysis['surprises'], detection, tokens, 'INPUT_PATH', suggested_questions=questions)
Path('graphify-out/GRAPH_REPORT.md').write_text(report, encoding=\"utf-8\")
Path('graphify-out/.graphify_labels.json').write_text(json.dumps({str(k): v for k, v in labels.items()}, ensure_ascii=False), encoding=\"utf-8\")
# Re-export so graph.json nodes carry the curated community_name (#2490).
# Same extraction as Step 4, so the #479 shrink-guard passes on node count;
# if it still refuses, surface the guard message - do not force past it.
wrote = to_json(G, communities, 'graphify-out/graph.json', community_labels=labels)
if not wrote:
print('ERROR: refused to shrink graphify-out/graph.json (existing graph has more nodes; #479).')
print('If this shrink is intentional (you deleted files), re-run a full build with --force.')
print('Report updated with community labels')
"
```
Replace `LABELS_DICT` with the actual dict you constructed (e.g. `{0: "Attention Mechanism", 1: "Training Pipeline"}`).
Replace INPUT_PATH with the actual path.
### Step 6 - Generate Obsidian vault (opt-in) + HTML
**Generate HTML always** (unless `--no-viz`). **Obsidian vault only if `--obsidian` was explicitly given** — skip it otherwise, it generates one file per node.
If `--obsidian` was given:
- If `--obsidian-dir <path>` was also given, pass it via `--dir`. Otherwise defaults to `graphify-out/obsidian`.
```bash
graphify export obsidian
# or with custom dir: graphify export obsidian --dir ~/vaults/my-project
```
Generate the HTML graph (always, unless `--no-viz`):
```bash
graphify export html # auto-aggregates to community view if graph > 5000 nodes
# or: graphify export html --no-viz
```
### Steps 6b-8 - Wiki, Neo4j, FalkorDB, SVG, GraphML, MCP, benchmark (only on their flags)
These run only when their flag is present (`--wiki`, `--neo4j`/`--neo4j-push`, `--falkordb`/`--falkordb-push`, `--svg`, `--graphml`, `--mcp`) or, for the token-reduction benchmark, when `total_words` exceeds 5,000. A default run with no export flags skips all of them. See `references/exports.md` for each one. Run any `--wiki` export before Step 9 cleanup so `.graphify_labels.json` is still available.
---
### Step 9 - Save manifest, update cost tracker, clean up, and report
```bash
$(cat graphify-out/.graphify_python) -c "
import json
from pathlib import Path
from datetime import datetime, timezone
from graphify.detect import save_manifest
# Save manifest for --update
detect = json.loads(Path('graphify-out/.graphify_detect.json').read_text(encoding=\"utf-8\"))
extract = json.loads(Path('graphify-out/.graphify_extract.json').read_text(encoding=\"utf-8\"))
# In --update mode, 'all_files' carries the full corpus; 'files' is the changed
# subset. Full-rebuild mode populates only 'files', so the fallback handles that.
# root= relativizes the manifest keys to the scan root (same base as the build),
# so the on-disk manifest is portable across clones/machines and a later --update
# matches cached files instead of missing every one (#1417).
#
# Only stamp semantic files (docs/papers/images) that ACTUALLY produced output:
# a detected file whose chunk failed or was omitted must stay unstamped so the
# next --update re-queues it, otherwise it is marked done and its content is lost
# forever (#2015). This mirrors the library extract path exactly
# (cli._stamped_manifest_files + clear_semantic + scan_corpus); do not stamp the
# raw corpus. Code files are always stamped (AST is deterministic); only semantic
# types are gated on output.
from graphify.cli import _stamped_manifest_files
_corpus = detect.get('all_files') or detect['files']
# A file a subagent only partly read DID produce output, so the stamp filter alone would
# keep it - but its node set covers just the head of the file, and stamping it means
# detect_incremental reads it as done and never re-queues it, leaving the truncated graph
# live forever. Name those files so they stay unstamped and are retried next run (#2225).
_pf = Path('graphify-out/.graphify_partial.txt')
_partial = {l.strip() for l in _pf.read_text(encoding=\"utf-8\").splitlines() if l.strip()} if _pf.exists() else set()
_manifest_files = _stamped_manifest_files(_corpus, extract, Path('INPUT_PATH'), partial_source_files=_partial)
# Files dispatched this run (the changed subset) but NOT stamped above still carry
# a stale semantic_hash from a prior run; clear it so detect_incremental re-queues
# them instead of reading them as unchanged (#1948).
_sem_types = ('document', 'paper', 'image')
_dispatched = {f for t, fl in detect['files'].items() if t in _sem_types for f in fl}
_stamped = {f for fl in _manifest_files.values() for f in fl}
_cleared = _dispatched - _stamped
# scan_corpus = the RAW full corpus (not the stamp-filtered subset) so in-root
# files newly excluded since last run are dropped rather than masquerading as
# deletions; untouched files' prior rows are still preserved (#1908).
_scan = {f for fl in _corpus.values() for f in fl}
save_manifest(_manifest_files, root='INPUT_PATH', scan_corpus=_scan, clear_semantic=_cleared or None)
# Update cumulative cost tracker
input_tok = extract.get('input_tokens', 0)
output_tok = extract.get('output_tokens', 0)
cost_path = Path('graphify-out/cost.json')
if cost_path.exists():
cost = json.loads(cost_path.read_text(encoding=\"utf-8\"))
else:
cost = {'runs': [], 'total_input_tokens': 0, 'total_output_tokens': 0}
cost['runs'].append({
'date': datetime.now(timezone.utc).isoformat(),
'input_tokens': input_tok,
'output_tokens': output_tok,
'files': detect.get('total_files', 0),
})
cost['total_input_tokens'] += input_tok
cost['total_output_tokens'] += output_tok
cost_path.write_text(json.dumps(cost, indent=2, ensure_ascii=False), encoding=\"utf-8\")
print(f'This run: {input_tok:,} input tokens, {output_tok:,} output tokens')
print(f'All time: {cost[\"total_input_tokens\"]:,} input, {cost[\"total_output_tokens\"]:,} output ({len(cost[\"runs\"])} runs)')
"
rm -f graphify-out/.graphify_detect.json graphify-out/.graphify_extract.json graphify-out/.graphify_ast.json graphify-out/.graphify_semantic.json graphify-out/.graphify_analysis.json graphify-out/.graphify_partial.txt
find graphify-out -maxdepth 1 -name '.graphify_chunk_*.json' -delete 2>/dev/null
rm -f graphify-out/.needs_update 2>/dev/null || true
```
Replace INPUT_PATH with the actual path (same value used in Steps 4-5) so the manifest is relativized to the scan root.
Tell the user (omit the obsidian line unless --obsidian was given):
```
Graph complete. Outputs in PATH_TO_DIR/graphify-out/
graph.html - interactive graph, open in browser
GRAPH_REPORT.md - audit report
graph.json - raw graph data
obsidian/ - Obsidian vault (only if --obsidian was given)
```
If graphify saved you time, consider supporting it: https://github.com/sponsors/safishamsi
Replace PATH_TO_DIR with the actual absolute path of the directory that was processed.
If PATH_TO_DIR is inside a git repository, add one line to the report: `graphify-out/` was written into the working tree, so unless the repository already ignores it, it will show in `git status`; the user can add `graphify-out/` to `.gitignore`, or commit only the outputs their team should share (see https://docs.graphify.com/guides/team-workflows).
Then paste these sections from GRAPH_REPORT.md directly into the chat:
- God Nodes
- Surprising Connections
- Suggested Questions
Do NOT paste the full report - just those three sections. Keep it concise.
Then immediately offer to explore. Pick the single most interesting suggested question from the report - the one that crosses the most community boundaries or has the most surprising bridge node - and ask:
> "The most interesting question this graph can answer: **[question]**. Want me to trace it?"
If the user says yes, run `/graphify query "[question]"` on the graph and walk them through the answer using the graph structure - which nodes connect, which community boundaries get crossed, what the path reveals. Keep going as long as they want to explore. Each answer should end with a natural follow-up ("this connects to X - want to go deeper?") so the session feels like navigation, not a one-shot report.
The graph is the map. Your job after the pipeline is to be the guide.
---
## Interpreter guard for subcommands
Before running any subcommand below (`--update`, `--cluster-only`, `query`, `path`, `explain`, `add`), check that `.graphify_python` exists. If it's missing (e.g. user deleted `graphify-out/`), re-resolve the interpreter first:
```bash
if [ ! -f graphify-out/.graphify_python ]; then
GRAPHIFY_BIN=$(which graphify 2>/dev/null)
if [ -n "$GRAPHIFY_BIN" ]; then
PYTHON=$(head -1 "$GRAPHIFY_BIN" | tr -d '#!')
case "$PYTHON" in *[!a-zA-Z0-9/_.@-]*) PYTHON="python3" ;; esac
else
PYTHON="python3"
fi
mkdir -p graphify-out
"$PYTHON" -c "import sys; open('graphify-out/.graphify_python', 'w', encoding='utf-8').write(sys.executable)"
fi
```
## For --update and --cluster-only
Both are non-default subcommands. `--update` re-extracts only new or changed files; `--cluster-only` reruns clustering on the existing graph. See `references/update.md` for both flows.
---
## For /graphify query
When `graphify-out/graph.json` already exists and the user asks a question about the corpus, answer from the graph rather than rebuilding it:
```bash
graphify query "<question>"
```
Before traversal, expand the question against the graph's own vocabulary so a wording mismatch does not collapse the answer to noise. If the `graphify query` CLI is unavailable, fall back to an inline NetworkX traversal of `graphify-out/graph.json`. Answer using only what the graph output contains, and quote `source_location` when citing a specific fact. For that vocab-expansion step, the BFS/DFS traversal modes, the `--budget` cap, the NetworkX fallback, `save-result` feedback, and the `/graphify path` and `/graphify explain` flows, see `references/query.md`.
---
## For /graphify add and --watch
Neither is part of the default build. When the user runs `/graphify add <url>` to fetch a URL into the corpus, or passes `--watch` to auto-rebuild on file changes, see `references/add-watch.md`.
---
## For the commit hook and native CLAUDE.md integration
When the user asks to install the post-commit auto-rebuild hook or wire graphify into a project's CLAUDE.md, see `references/hooks.md`.
---
## Honesty Rules
- Never invent an edge. If unsure, use AMBIGUOUS.
- Never skip the corpus check warning.
- Always show token cost in the report.
- Never hide cohesion scores behind symbols - show the raw number.
- Never run HTML viz on a graph with more than 5,000 nodes without warning the user.
@@ -1,56 +0,0 @@
# graphify reference: add a URL and watch a folder
Load this when the user ran `/graphify add <url>` or passed `--watch`. Neither is part of the default build.
## For /graphify add
Fetch a URL and add it to the corpus, then update the graph.
```bash
$(cat graphify-out/.graphify_python) -c "
import sys
from graphify.ingest import ingest
from pathlib import Path
try:
out = ingest('URL', Path('./raw'), author='AUTHOR', contributor='CONTRIBUTOR')
print(f'Saved to {out}')
except ValueError as e:
print(f'error: {e}', file=sys.stderr)
sys.exit(1)
except RuntimeError as e:
print(f'error: {e}', file=sys.stderr)
sys.exit(1)
"
```
Replace `URL` with the actual URL, `AUTHOR` with the user's name if provided, `CONTRIBUTOR` likewise. If the command exits with an error, tell the user what went wrong - do not silently continue. After a successful save, automatically run the `--update` pipeline on `./raw` to merge the new file into the existing graph.
Supported URL types (auto-detected):
- YouTube / any video URL → audio downloaded via yt-dlp, transcribed to `.txt` on next run (requires `pip install 'graphifyy[video]'`)
- Twitter/X → fetched via oEmbed, saved as `.md` with tweet text and author
- arXiv → abstract + metadata saved as `.md`
- PDF → downloaded as `.pdf`
- Images (.png/.jpg/.webp) → downloaded, Claude vision extracts on next run
- Any webpage → converted to markdown via html2text
---
## For --watch
Start a background watcher that monitors a folder and auto-updates the graph when files change.
```bash
$(cat graphify-out/.graphify_python) -m graphify.watch "$(cat graphify-out/.graphify_root)" --debounce 3
```
This watches the same folder graphify extracted, read from the trusted `graphify-out/.graphify_root` that Step 1 resolved - there is no path to substitute, so a scan root containing shell metacharacters can never be re-interpreted here. Behavior depends on what changed:
- **Code files only (.py, .ts, .go, etc.):** re-runs AST extraction + rebuild + cluster immediately, no LLM needed. `graph.json` and `GRAPH_REPORT.md` are updated automatically.
- **Docs, papers, or images:** writes a `graphify-out/needs_update` flag and prints a notification to run `/graphify --update` (LLM semantic re-extraction required).
Debounce (default 3s): waits until file activity stops before triggering, so a wave of parallel agent writes doesn't trigger a rebuild per file.
Press Ctrl+C to stop.
For agentic workflows: run `--watch` in a background terminal. Code changes from agent waves are picked up automatically between waves. If agents are also writing docs or notes, you'll need a manual `/graphify --update` after those waves.
@@ -1,91 +0,0 @@
# graphify reference: extra exports and benchmark
Load this when the user passed one of the export flags (`--wiki`, `--neo4j`, `--neo4j-push`, `--falkordb`, `--falkordb-push`, `--svg`, `--graphml`, `--mcp`), or when the corpus is large enough for the token-reduction benchmark. Each step runs only for its own flag.
### Step 6b - Wiki (only if --wiki flag)
**Only run this step if `--wiki` was explicitly given in the original command.**
Run this before Step 9 (cleanup) so `.graphify_labels.json` is still available.
```bash
graphify export wiki
```
### Step 7 - Neo4j export (only if --neo4j or --neo4j-push flag)
**If `--neo4j`** - generate a Cypher file for manual import:
```bash
graphify export neo4j
```
**If `--neo4j-push`** - push directly to Neo4j using the destination URI supplied with the original `/graphify` command. Only push when this flag was explicitly given.
Pass the exact URI from the original `/graphify` command as one argument. When constructing a shell command, quote the URI for the shell that will execute the command (use `shlex.quote` for POSIX shells), or use a structured argument interface. Keep the URI as data; never interpolate it unquoted or evaluate it as shell code. Never replace a supplied URI with localhost. If the user explicitly requested a push but supplied no URI, use the documented local default. Do not print the URI or credentials in status output or generated artifacts.
```bash
graphify export neo4j --push 'bolt://remote-host:7687' --user neo4j
```
Default URI is `bolt://localhost:7687`, default user is `neo4j`. Prefer the `NEO4J_PASSWORD` environment variable so the password is kept off argv; ask for credentials only when needed. Uses MERGE - safe to re-run without creating duplicates.
### Step 7a - FalkorDB export (only if --falkordb or --falkordb-push flag)
**If `--falkordb`** - generate a Cypher file. The statements are OpenCypher, but FalkorDB's `GRAPH.QUERY` runs one statement at a time (no bulk script import like Neo4j's `cypher-shell`), so prefer `--falkordb-push` to load a graph. Use this only when you want the portable `cypher.txt` artifact:
```bash
graphify export falkordb
```
**If `--falkordb-push`** - push directly to FalkorDB using the destination URI supplied with the original `/graphify` command. Only push when this flag was explicitly given.
Pass the exact URI from the original `/graphify` command as one argument. When constructing a shell command, quote the URI for the shell that will execute the command (use `shlex.quote` for POSIX shells), or use a structured argument interface. Keep the URI as data; never interpolate it unquoted or evaluate it as shell code. Never replace a supplied URI with localhost. If the user explicitly requested a push but supplied no URI, use the documented local default. Do not print the URI or credentials in status output or generated artifacts. Credentials are optional; ask only if the instance requires authentication, and use `FALKORDB_PASSWORD` for a password rather than printing it.
```bash
graphify export falkordb --push 'falkordb://remote-host:6379'
```
Default URI is `falkordb://localhost:6379` (the scheme is informational - `redis://` or a bare `host:port` work too), auth is optional, and the target graph defaults to `graphify`. Uses MERGE - safe to re-run without creating duplicates.
### Step 7b - SVG export (only if --svg flag)
```bash
graphify export svg
```
### Step 7c - GraphML export (only if --graphml flag)
```bash
graphify export graphml
```
### Step 7d - MCP server (only if --mcp flag)
```bash
$(cat graphify-out/.graphify_python) -m graphify.serve graphify-out/graph.json
```
This starts a stdio MCP server that exposes tools: `query_graph`, `get_node`, `get_neighbors`, `get_community`, `god_nodes`, `graph_stats`, `shortest_path`. Add to Claude Desktop or any MCP-compatible agent orchestrator so other agents can query the graph live.
To configure in Claude Desktop, add to `claude_desktop_config.json`. Claude Desktop can't run `$(...)`, and under `uv tool install` the system `python3` can't import graphify — so set `command` to the **absolute interpreter path** printed by `cat graphify-out/.graphify_python`:
```json
{
"mcpServers": {
"graphify": {
"command": "<absolute path from: cat graphify-out/.graphify_python>",
"args": ["-m", "graphify.serve", "/absolute/path/to/graphify-out/graph.json"]
}
}
}
```
### Step 8 - Token reduction benchmark (only if total_words > 5000)
If `total_words` from `graphify-out/.graphify_detect.json` is greater than 5,000, run:
```bash
graphify benchmark
```
Print the output directly in chat. If `total_words <= 5000`, skip silently - the graph value is structural clarity, not token compression, for small corpora.
@@ -1,86 +0,0 @@
# graphify reference: extraction subagent prompt
Load this in Step 3 Part B when the corpus has at least one doc, paper, or image chunk. A pure-code corpus skips Part B and never reads this file. Each semantic subagent receives the prompt below verbatim (substitute FILE_LIST, CHUNK_NUM, TOTAL_CHUNKS, DEEP_MODE, and CHUNK_PATH).
```
You are a graphify extraction subagent. Read the files listed and extract a knowledge graph fragment.
Output ONLY valid JSON matching the schema below - no explanation, no markdown fences, no preamble.
Files (chunk CHUNK_NUM of TOTAL_CHUNKS):
FILE_LIST
Read every file in this list COMPLETELY before extracting anything from it. The Read tool
returns at most 2000 lines per call and reports NO error and NO warning when it truncates, so a
long file silently yields a partial extraction. When a file is longer than one call, keep paging
with offset/limit until you have actually seen its last line - never assume the first call
returned the whole file. Never emit nodes for a file you have only partly read. A partial
extraction is worse than none: replace-on-re-extract first DROPS that file's existing nodes and
then re-adds only what you saw, so the unread tail disappears from the graph, and the file is then
recorded as successfully extracted and never retried (#2225).
Report the coverage you actually achieved, so a short read is caught instead of guessed at: add a
top-level "coverage" object mapping each FILE_LIST path you extracted to the number of lines you
read, e.g. {"coverage": {"docs/plan.md": 452}}. If you could not reach a file's last line, still
report the count you did read. A short count is recoverable - Step B3 warns, the entry is cached
as partial, and the next --update retries the file - whereas a missing entry is indistinguishable
from a complete read.
Rules:
- EXTRACTED: relationship explicit in source (import, call, citation, "see §3.2")
- INFERRED: reasonable inference (shared data structure, implied dependency)
- AMBIGUOUS: uncertain - flag for review, do not omit
Code files: focus on semantic edges AST cannot find (call relationships, shared data, arch patterns).
Do not re-extract imports - AST already has those.
Doc/paper files: extract named concepts, entities, citations. For rationale (WHY decisions were made, trade-offs, design intent): store as a `rationale` attribute on the relevant concept node — do NOT create a separate rationale node or fragment node. Only create a node for something that is itself a named entity or concept. Use `file_type:"rationale"` for concept-like nodes (ideas, principles, mechanisms, design patterns). `file_type` MUST be one of exactly these six values: `code`, `document`, `paper`, `image`, `rationale`, `concept`. Any other value is invalid and will be rejected.
Code files: when adding `calls` edges, source MUST be the caller (the function/class doing the calling), target MUST be the callee. Never reverse this direction. `calls` edges MUST stay within one language: a Python function cannot `calls` a JS/TS/Go/Rust/Java symbol and vice versa — cross-language call edges are phantom artifacts, never emit them.
Image files: use vision to understand what the image IS - do not just OCR.
UI screenshot: layout patterns, design decisions, key elements, purpose.
Chart: metric, trend/insight, data source.
Tweet/post: claim as node, author, concepts mentioned.
Diagram: components and connections.
Research figure: what it demonstrates, method, result.
Handwritten/whiteboard: ideas and arrows, mark uncertain readings AMBIGUOUS.
DEEP_MODE (if --mode deep was given): be aggressive with INFERRED edges - indirect deps,
shared assumptions, latent couplings. Mark uncertain ones AMBIGUOUS instead of omitting.
Semantic similarity: if two concepts in this chunk solve the same problem or represent the same idea without any structural link (no import, no call, no citation), add a `semantically_similar_to` edge marked INFERRED with a confidence_score reflecting how similar they are (0.6-0.95). Examples:
- Two functions that both validate user input but never call each other
- A class in code and a concept in a paper that describe the same algorithm
- Two error types that handle the same failure mode differently
Only add these when the similarity is genuinely non-obvious and cross-cutting. Do not add them for trivially similar things.
Hyperedges: if 3 or more nodes clearly participate together in a shared concept, flow, or pattern that is not captured by pairwise edges alone, add a hyperedge to a top-level `hyperedges` array. Examples:
- All classes that implement a common protocol or interface
- All functions in an authentication flow (even if they don't all call each other)
- All concepts from a paper section that form one coherent idea
Use sparingly — only when the group relationship adds information beyond the pairwise edges. Maximum 3 hyperedges per chunk.
If a file has YAML frontmatter (--- ... ---), copy source_url, captured_at, author,
contributor onto every node from that file.
confidence_score is REQUIRED on every edge - never omit it, never use 0.5 as a default:
- EXTRACTED edges: confidence_score = 1.0 always
- INFERRED edges: pick exactly ONE value from this set — never 0.5:
0.95 direct structural evidence (shared data structure, named cross-file reference).
0.85 strong inference (clear functional alignment, no direct symbol link).
0.75 reasonable inference (shared problem domain + similar shape, requires interpretation).
0.65 weak inference (thematically related, no shape evidence).
0.55 speculative but plausible (surface-level co-occurrence only).
Models follow discrete rubrics better than continuous ranges; the bimodal
distribution observed in production (>50% at 0.5, >40% at 0.85+) shows the
range guidance is being collapsed to a binary. If no value above fits, mark
the edge AMBIGUOUS rather than picking 0.4 or below.
- AMBIGUOUS edges: 0.1-0.3
Node ID format: lowercase, word characters only (`[^\W]` after casefolding — `[a-z0-9_]` for ASCII input, but non-ASCII letters and digits are kept as-is), no dots or slashes. Format: `{stem}_{entity}` where stem is the **full repo-relative path with the extension dropped**, every path segment kept and joined with `_` (each segment lowercased with non-alphanumeric chars replaced by `_`), and entity is the symbol name similarly normalized. Use every directory level, not just the immediate parent — this keeps same-named files in different directories distinct. Examples: `src/auth/session.py` + `ValidateToken` → `src_auth_session_validatetoken`; `lib/utils/helpers.py` + `parse_url` → `lib_utils_helpers_parse_url`; `tests/test_foo.py` + `_helper` → `tests_test_foo_helper`; `docs/v1/api/README.md` + `getUser` → `docs_v1_api_readme_getuser`. Top-level files (no parent dir, e.g. `setup.py`) use just the filename stem: `setup_my_func`. This must match the ID the AST extractor generates — using just the filename (e.g., `session_validatetoken`) or only the immediate parent (e.g., `auth_session_validatetoken`) will create orphan ghost-duplicate nodes. If you are re-extracting a project built under the old immediate-parent format, the user should run `graphify extract --force` to rebuild cleanly. CRITICAL: never append chunk numbers, sequence numbers, or any suffix to an ID (no `_c1`, `_c2`, `_chunk2`, etc.). IDs must be deterministic from the label alone — the same entity must always produce the same ID regardless of which chunk processes it.
Generate the extraction JSON matching this schema exactly:
{"nodes":[{"id":"auth_session_validatetoken","label":"Human Readable Name","file_type":"code|document|paper|image|rationale|concept","source_file":"<FILE_LIST path verbatim>","source_location":null,"source_url":null,"captured_at":null,"author":null,"contributor":null}],"edges":[{"source":"node_id","target":"node_id","relation":"calls|implements|references|cites|conceptually_related_to|shares_data_with|semantically_similar_to|rationale_for","confidence":"EXTRACTED|INFERRED|AMBIGUOUS","confidence_score":1.0,"source_file":"<FILE_LIST path verbatim>","source_location":null,"weight":1.0}],"hyperedges":[{"id":"snake_case_id","label":"Human Readable Label","nodes":["node_id1","node_id2","node_id3"],"relation":"participate_in|implement|form","confidence":"EXTRACTED|INFERRED","confidence_score":0.75,"source_file":"<FILE_LIST path verbatim>"}],"input_tokens":0,"output_tokens":0,"coverage":{"<FILE_LIST path verbatim>":0}}
source_file RULE (every node, edge, and hyperedge): set source_file to the path of the originating file EXACTLY as it appears in FILE_LIST — verbatim and absolute. Do NOT shorten to a basename, do NOT re-relativize, do NOT strip any directory prefix, and do NOT change separators (the engine canonicalizes separators and relativizes against the build root downstream). Copy the FILE_LIST entry character-for-character. This keeps the full build and incremental --update on the same base, so build_merge's replace-on-re-extract matches the existing node instead of accumulating a duplicate.
Then write the JSON to disk using the Write tool at this exact absolute path (no relative paths — Write resolves relative paths against an undefined cwd and the file will be silently lost):
CHUNK_PATH
```
@@ -1,46 +0,0 @@
# graphify reference: GitHub clone and cross-repo merge
Load this when the user passed one or more `https://github.com/...` URLs, or named several local subfolders to merge into one graph.
### Step 0 - Clone GitHub repo(s) (only if a GitHub URL was given)
**Single repo:**
```bash
LOCAL_PATH=$(graphify clone <github-url> [--branch <branch>])
# Use LOCAL_PATH as the target for all subsequent steps
```
**Multiple repos (cross-repo graph):**
```bash
# Clone each repo, run the full pipeline on each, then merge
graphify clone <url1> # → ~/.graphify/repos/<owner1>/<repo1>
graphify clone <url2> # → ~/.graphify/repos/<owner2>/<repo2>
# Run /graphify on each local path to produce their graph.json files
# Then merge:
graphify merge-graphs \
~/.graphify/repos/<owner1>/<repo1>/graphify-out/graph.json \
~/.graphify/repos/<owner2>/<repo2>/graphify-out/graph.json \
--out graphify-out/cross-repo-graph.json
```
Graphify clones into `~/.graphify/repos/<owner>/<repo>` and reuses existing clones on repeat runs. Each node in the merged graph carries a `repo` attribute so you can filter by origin.
**Multiple local subfolders (monorepo or multi-service layout):**
The skill pipeline writes all intermediate and final outputs to `graphify-out/` in the current working directory. Running the skill on each subfolder separately will clobber the same output dir. Instead, use the CLI directly for each subfolder — it places `graphify-out/` *inside* the scanned path:
```bash
graphify extract ./core/ # → ./core/graphify-out/graph.json
graphify extract ./service/ # → ./service/graphify-out/graph.json
graphify extract ./platform/ # → ./platform/graphify-out/graph.json
# Add --backend gemini|kimi|openai|deepseek|claude-cli depending on which API key you have set
# Then merge at the project root:
graphify merge-graphs \
./core/graphify-out/graph.json \
./service/graphify-out/graph.json \
./platform/graphify-out/graph.json \
--out graphify-out/graph.json
```
Once `graphify-out/graph.json` exists, the fast path above takes over: any codebase question runs `graphify query` directly on the merged graph — no re-extraction, no size gate.
@@ -1,33 +0,0 @@
# graphify reference: commit hook and native CLAUDE.md integration
Load this when the user asked to install the post-commit hook or wire graphify into a project's CLAUDE.md.
## For git commit hook
Install a post-commit hook that auto-rebuilds the graph after every commit. No background process needed - triggers once per commit, works with any editor.
```bash
graphify hook install # install
graphify hook uninstall # remove
graphify hook status # check
```
After every `git commit`, the hook detects which code files changed (via `git diff HEAD~1`), re-runs AST extraction on those files, and rebuilds `graph.json` and `GRAPH_REPORT.md`. Doc/image changes are ignored by the hook - run `/graphify --update` manually for those.
If a post-commit hook already exists, graphify appends to it rather than replacing it.
---
## For native CLAUDE.md integration
Run once per project to make graphify always-on in Claude Code sessions:
```bash
graphify claude install
```
This writes a `## graphify` section to the local `CLAUDE.md` that instructs Claude to check the graph before answering codebase questions and rebuild it after code changes. No manual `/graphify` needed in future sessions.
```bash
graphify claude uninstall # remove the section
```
-317
View File
@@ -1,317 +0,0 @@
# graphify reference: query, path, explain
Load this when the user asks a question against an existing graph, or runs `/graphify path` or `/graphify explain`. The core's query stub points here for the full traversal flow. These flows use the `graphify query` CLI when it is available and fall back to an inline NetworkX traversal otherwise.
Two traversal modes - choose based on the question:
| Mode | Flag | Best for |
|------|------|----------|
| BFS (default) | _(none)_ | "What is X connected to?" - broad context, nearest neighbors first |
| DFS | `--dfs` | "How does X reach Y?" - trace a specific chain or dependency path |
First check the graph exists:
```bash
$(cat graphify-out/.graphify_python) -c "
from pathlib import Path
if not Path('graphify-out/graph.json').exists():
print('ERROR: No graph found. Run /graphify <path> first to build the graph.')
raise SystemExit(1)
"
```
If it fails, stop and tell the user to run `/graphify <path>` first.
### Step 0 — Constrained query expansion (REQUIRED before traversal)
graphify's `query` CLI matches nodes via case-folded substring + IDF — there is **no stemming, no synonyms, no cross-language match** inside the binary, and the inline fallback below matches the same way. If the user's question uses different language or different domain vocabulary than the graph's labels (user says "обработчик" / graph says "handler"; user says "authentication" / graph says "Guardian"), the literal matcher returns 0 hits and the answer collapses to noise.
Fix this **without inventing tokens** by expanding the query against the actual graph vocabulary first:
1. Extract the token vocabulary from node labels:
```bash
$(cat graphify-out/.graphify_python) -c "
import json, re
from pathlib import Path
data = json.loads(Path('graphify-out/graph.json').read_text(encoding='utf-8'))
vocab = set()
for n in data['nodes']:
for c in re.findall(r'[^\W\d_]+', n.get('label','') or '', re.UNICODE):
parts = re.findall(r'[A-Z]+(?=[A-Z][a-z])|[A-Z]?[a-z]+|[A-Z]+', c) or [c]
for p in parts:
t = p.lower()
if 3 <= len(t) <= 30:
vocab.add(t)
Path('graphify-out/.vocab.txt').write_text('\n'.join(sorted(vocab)), encoding='utf-8')
print(f'vocab: {len(vocab)} tokens')
"
```
2. Read `graphify-out/.vocab.txt`. Then for the user's question, select **up to 12 tokens from this exact list** that semantically match the query intent. Hard constraints:
- You MUST pick only tokens present in the vocabulary file. Do NOT invent tokens.
- If a query concept has no plausible token in the vocab, skip it — do not substitute a near-synonym from training memory.
- If **no** vocab tokens match the query at all, output an empty list and tell the user the corpus has no relevant vocabulary for this question. Do not fabricate a search.
- Translate cross-language: Russian "аутентификация" → look for `auth`, `credential`, `token`, `security` IFF present in vocab.
- Morphology: "handlers" maps to `handler` IFF present; "todos" maps to `todo` IFF present.
3. Print the selection explicitly to the user before running the query, so the expansion is auditable:
```
Query expanded to (from graph vocab, N tokens): [token1, token2, ...]
```
If the list is empty, say so plainly and stop — do not proceed to traversal.
### Step 1 — Traversal
Build the **expanded query string** by joining the selected tokens with spaces. Use this string as `QUESTION` below — NOT the original user question. (The original question is preserved only for `save-result` at the end.)
Prefer the CLI when it is installed:
```bash
graphify query "QUESTION"
# or: graphify query "QUESTION" --dfs --budget 3000
```
If the CLI is unavailable, load `graphify-out/graph.json` and run the traversal inline:
1. Find the 1-3 nodes whose label best matches the expanded tokens.
2. Run the appropriate traversal from each starting node.
3. Read the subgraph - node labels, edge relations, confidence tags, source locations.
4. Answer using **only** what the graph contains. Quote `source_location` when citing a specific fact.
5. If the graph lacks enough information, say so - do not hallucinate edges.
```bash
$(cat graphify-out/.graphify_python) -c "
import sys, json
from networkx.readwrite import json_graph
from pathlib import Path
data = json.loads(Path('graphify-out/graph.json').read_text(encoding='utf-8'))
G = json_graph.node_link_graph(data, edges='links')
question = 'QUESTION'
mode = 'MODE' # 'bfs' or 'dfs'
terms = [t.lower() for t in question.split() if len(t) >= 3] # match the vocab threshold; keeps api/jwt/ios (#1392)
# Find best-matching start nodes
scored = []
for nid, ndata in G.nodes(data=True):
label = ndata.get('label', '').lower()
score = sum(1 for t in terms if t in label)
if score > 0:
scored.append((score, nid))
scored.sort(reverse=True)
start_nodes = [nid for _, nid in scored[:3]]
if not start_nodes:
print('No matching nodes found for query terms:', terms)
sys.exit(0)
subgraph_nodes = set()
if mode == 'dfs':
# DFS: follow one path as deep as possible before backtracking.
# Depth-limited to 6 to avoid traversing the whole graph.
visited = set()
stack = [(n, 0) for n in reversed(start_nodes)]
while stack:
node, depth = stack.pop()
if node in visited or depth > 6:
continue
visited.add(node)
subgraph_nodes.add(node)
for neighbor in G.neighbors(node):
if neighbor not in visited:
stack.append((neighbor, depth + 1))
else:
# BFS: explore all neighbors layer by layer up to depth 3.
frontier = set(start_nodes)
subgraph_nodes = set(start_nodes)
for _ in range(3):
next_frontier = set()
for n in frontier:
for neighbor in G.neighbors(n):
if neighbor not in subgraph_nodes:
next_frontier.add(neighbor)
subgraph_nodes.update(next_frontier)
frontier = next_frontier
# Traversal chooses the nodes; collect relationships separately so seed edges,
# cycles, and cross-links are not lost just because both endpoints were visited.
# Taking the induced subgraph also keeps edges to nodes beyond the depth limit
# out of the result. data=True retains each edge's own attributes, including
# distinct parallel relationships in a MultiGraph.
subgraph_edges = [
(u, v, edge_data)
for u, v, edge_data in G.subgraph(subgraph_nodes).edges(data=True)
if u != v
]
# Token-budget aware output: rank by relevance, cut at budget (~4 chars/token)
token_budget = BUDGET # default 2000
char_budget = token_budget * 4
# Score each node by term overlap for ranked output
def relevance(nid):
label = G.nodes[nid].get('label', '').lower()
return sum(1 for t in terms if t in label)
ranked_nodes = sorted(subgraph_nodes, key=relevance, reverse=True)
lines = [f'Traversal: {mode.upper()} | Start: {[G.nodes[n].get(\"label\",n) for n in start_nodes]} | {len(subgraph_nodes)} nodes']
for nid in ranked_nodes:
d = G.nodes[nid]
lines.append(f' NODE {d.get(\"label\", nid)} [src={d.get(\"source_file\",\"\")} loc={d.get(\"source_location\",\"\")}]')
for u, v, edge_data in subgraph_edges:
if u in subgraph_nodes and v in subgraph_nodes:
lines.append(f' EDGE {G.nodes[u].get(\"label\",u)} --{edge_data.get(\"relation\",\"\")} [{edge_data.get(\"confidence\",\"\")}]--> {G.nodes[v].get(\"label\",v)}')
output = '\n'.join(lines)
if len(output) > char_budget:
output = output[:char_budget] + f'\n... (truncated at ~{token_budget} token budget - use --budget N for more)'
print(output)
"
```
Replace `QUESTION` with the **expanded** query string, `MODE` with `bfs` or `dfs`, and `BUDGET` with the token budget (default `2000`, or whatever `--budget N` specifies). Then answer based on the subgraph output above, using only what the graph contains.
After writing the answer, save it back into the graph so it improves future queries. Include the expanded tokens inside the `--answer` text (e.g. `"Expanded from original query via vocab: [tokens]. Then traversed..."`) so the next `--update` extracts the expansion history as a graph node:
```bash
$(cat graphify-out/.graphify_python) -m graphify save-result --question "ORIGINAL_QUESTION" --answer "ANSWER" --type query --nodes NODE1 NODE2
```
Replace `ORIGINAL_QUESTION` with the user's verbatim question, `ANSWER` with your full answer text (containing the expanded-token trace), `NODE1 NODE2` with the list of node labels you cited. This closes the feedback loop: the next `--update` will extract this Q&A as a node in the graph.
**Work memory (self-improving loop).** Add an `--outcome` so future sessions learn from this one — append `--outcome useful|dead_end|corrected` to the `save-result` command (and `--correction "the right answer"` when correcting):
- `useful` — the cited nodes answered the question well (they become *preferred sources*).
- `dead_end` — the question/path led nowhere; don't re-derive it next time.
- `corrected` — the saved answer was wrong; `--correction` records what was right.
At the **start** of graph work, refresh and read the lessons: run `graphify reflect --if-stale` (cheap, deterministic, no LLM; `--if-stale` makes it a no-op when `LESSONS.md` is already newer than every input, e.g. when the git hook just refreshed it), then read `graphify-out/reflections/LESSONS.md`. It lists **preferred sources** (start there), **known dead ends** (skip them), and prior **corrections**. Running `reflect` yourself keeps the lessons current even without the git hook installed; if the post-commit hook *is* installed, `--if-stale` means your session-start run costs almost nothing.
---
## For /graphify path
Find the shortest path between two named concepts in the graph. Prefer the CLI when installed:
```bash
graphify path "NODE_A" "NODE_B"
```
If the CLI is unavailable, run it inline:
```bash
$(cat graphify-out/.graphify_python) -c "
import json, sys
import networkx as nx
from networkx.readwrite import json_graph
from pathlib import Path
data = json.loads(Path('graphify-out/graph.json').read_text(encoding='utf-8'))
G = json_graph.node_link_graph(data, edges='links')
a_term = 'NODE_A'
b_term = 'NODE_B'
def find_node(term):
term = term.lower()
scored = sorted(
[(sum(1 for w in term.split() if w in G.nodes[n].get('label','').lower()), n)
for n in G.nodes()],
reverse=True
)
return scored[0][1] if scored and scored[0][0] > 0 else None
src = find_node(a_term)
tgt = find_node(b_term)
if not src or not tgt:
print(f'Could not find nodes matching: {a_term!r} or {b_term!r}')
sys.exit(0)
try:
path = nx.shortest_path(G, src, tgt)
print(f'Shortest path ({len(path)-1} hops):')
for i, nid in enumerate(path):
label = G.nodes[nid].get('label', nid)
if i < len(path) - 1:
_raw = G[nid][path[i+1]]; edge = next(iter(_raw.values()), {}) if isinstance(G, nx.MultiGraph) else _raw
rel = edge.get('relation', '')
conf = edge.get('confidence', '')
print(f' {label} --{rel}--> [{conf}]')
else:
print(f' {label}')
except nx.NetworkXNoPath:
print(f'No path found between {a_term!r} and {b_term!r}')
except nx.NodeNotFound as e:
print(f'Node not found: {e}')
"
```
Replace `NODE_A` and `NODE_B` with the actual concept names from the user. Then explain the path in plain language - what each hop means, why it's significant.
After writing the explanation, save it back:
```bash
$(cat graphify-out/.graphify_python) -m graphify save-result --question "Path from NODE_A to NODE_B" --answer "ANSWER" --type path_query --nodes NODE_A NODE_B
```
---
## For /graphify explain
Give a plain-language explanation of a single node - everything connected to it. Prefer the CLI when installed:
```bash
graphify explain "NODE_NAME"
```
If the CLI is unavailable, run it inline:
```bash
$(cat graphify-out/.graphify_python) -c "
import json, sys
import networkx as nx
from networkx.readwrite import json_graph
from pathlib import Path
data = json.loads(Path('graphify-out/graph.json').read_text(encoding='utf-8'))
G = json_graph.node_link_graph(data, edges='links')
term = 'NODE_NAME'
term_lower = term.lower()
# Find best matching node
scored = sorted(
[(sum(1 for w in term_lower.split() if w in G.nodes[n].get('label','').lower()), n)
for n in G.nodes()],
reverse=True
)
if not scored or scored[0][0] == 0:
print(f'No node matching {term!r}')
sys.exit(0)
nid = scored[0][1]
data_n = G.nodes[nid]
print(f'NODE: {data_n.get(\"label\", nid)}')
print(f' source: {data_n.get(\"source_file\",\"unknown\")}')
print(f' type: {data_n.get(\"file_type\",\"unknown\")}')
print(f' degree: {G.degree(nid)}')
print()
print('CONNECTIONS:')
for neighbor in G.neighbors(nid):
_raw = G[nid][neighbor]; edge = next(iter(_raw.values()), {}) if isinstance(G, nx.MultiGraph) else _raw
nlabel = G.nodes[neighbor].get('label', neighbor)
rel = edge.get('relation', '')
conf = edge.get('confidence', '')
src_file = G.nodes[neighbor].get('source_file', '')
print(f' --{rel}--> {nlabel} [{conf}] ({src_file})')
"
```
Replace `NODE_NAME` with the concept the user asked about. Then write a 3-5 sentence explanation of what this node is, what it connects to, and why those connections are significant. Use the source locations as citations.
After writing the explanation, save it back:
```bash
$(cat graphify-out/.graphify_python) -m graphify save-result --question "Explain NODE_NAME" --answer "ANSWER" --type explain --nodes NODE_NAME
```
@@ -1,52 +0,0 @@
# graphify reference: transcribe video and audio
Load this only when `detect` reported one or more `video` files. A corpus with no video never reads this.
### Step 2.5 - Transcribe video / audio files (only if video files detected)
Skip this step entirely if `detect` returned zero `video` files.
Video and audio files cannot be read directly. Transcribe them to text first, then treat the transcripts as doc files in Step 3.
**Strategy:** Read the god nodes from `graphify-out/.graphify_detect.json` (or the analysis file if it exists from a previous run). You are already a language model — write a one-sentence domain hint yourself from those labels. Then pass it to Whisper as the initial prompt. No separate API call needed.
**However**, if the corpus has *only* video files and no other docs/code, use the generic fallback prompt: `"Use proper punctuation and paragraph breaks."`
**Step 1 - Write the Whisper prompt yourself.**
Read the top god node labels from detect output or analysis, then compose a short domain hint sentence, for example:
- Labels: `transformer, attention, encoder, decoder` → `"Machine learning research on transformer architectures and attention mechanisms. Use proper punctuation and paragraph breaks."`
- Labels: `kubernetes, deployment, pod, helm` → `"DevOps discussion about Kubernetes deployments and Helm charts. Use proper punctuation and paragraph breaks."`
**Export** it as `GRAPHIFY_WHISPER_PROMPT` (the exact name the transcriber reads — and it must be `export`ed so the child Python process sees it) for the next command.
**Step 2 - Transcribe:**
```bash
export GRAPHIFY_WHISPER_MODEL=base # or whatever --whisper-model the user passed (must be exported)
export GRAPHIFY_WHISPER_PROMPT="<the one-sentence domain hint you composed in Step 1>"
$(cat graphify-out/.graphify_python) -c "
import json, os, sys
from pathlib import Path
from graphify.transcribe import transcribe_all
detect = json.loads(Path('graphify-out/.graphify_detect.json').read_text(encoding=\"utf-8\"))
video_files = detect.get('files', {}).get('video', [])
prompt = os.environ.get('GRAPHIFY_WHISPER_PROMPT', 'Use proper punctuation and paragraph breaks.')
transcript_paths = transcribe_all(video_files, initial_prompt=prompt)
# Write the JSON from Python (NOT a shell '>' redirect): transcribe_all/Whisper
# print progress to stdout, which would otherwise corrupt the JSON file (#1392).
Path('graphify-out/.graphify_transcripts.json').write_text(json.dumps(transcript_paths, ensure_ascii=False), encoding=\"utf-8\")
print(f'Transcribed {len(transcript_paths)} file(s)', file=sys.stderr)
"
```
After transcription:
- Read the transcript paths from `graphify-out/.graphify_transcripts.json`
- Add them to the docs list before dispatching semantic subagents in Step 3B
- Print how many transcripts were created: `Transcribed N video file(s) -> treating as docs`
- If transcription fails for a file, print a warning and continue with the rest
**Whisper model:** Default is `base`. If the user passed `--whisper-model <name>`, `export GRAPHIFY_WHISPER_MODEL=<name>` (it must be exported, not just assigned) before running the command above.
@@ -1,221 +0,0 @@
# graphify reference: incremental update and cluster-only
Load this only when the user passed `--update` or `--cluster-only`. A first-time full build never reads this file.
## For --update (incremental re-extraction)
Use when you've added or modified files since the last run. Only re-extracts changed files - saves tokens and time.
```bash
$(cat graphify-out/.graphify_python) -c "
import sys, json
from graphify.detect import detect_incremental, save_manifest
from pathlib import Path
from graphify.paths import out_path
from graphify.watch import _read_build_excludes, _read_build_gitignore
result = detect_incremental(Path('INPUT_PATH'), extra_excludes=_read_build_excludes(out_path()), gitignore=_read_build_gitignore(out_path()))
new_total = result.get('new_total', 0)
nf = result.get('new_files', {})
print(json.dumps({
'new_total': new_total,
'deleted': len(result.get('deleted_files', [])),
'new_by_type': {t: len(v) for t, v in nf.items()},
'total_files': result.get('total_files'),
'total_words': result.get('total_words'),
'skipped_sensitive': result.get('skipped_sensitive', []),
}, indent=2, ensure_ascii=False))
print('Full result: graphify-out/.graphify_incremental.json')
Path('graphify-out/.graphify_incremental.json').write_text(json.dumps(result, ensure_ascii=False), encoding=\"utf-8\")
deleted = list(result.get('deleted_files', []))
if new_total == 0 and not deleted:
print('No files changed since last run. Nothing to update.')
raise SystemExit(0)
if deleted:
print(f'{len(deleted)} deleted file(s) to prune.')
if new_total > 0:
print(f'{new_total} new/changed file(s) to re-extract.')
"
```
Then populate `.graphify_detect.json` so Steps 3A–6 (which read it unconditionally) see the right state for an incremental run. `files` carries the changed subset (drives Step 3A AST + Step 3B0 cache check on only what changed); `all_files` carries the full corpus for any step that needs corpus-wide context:
```bash
$(cat graphify-out/.graphify_python) -c "
import json
from pathlib import Path
r = json.loads(Path('graphify-out/.graphify_incremental.json').read_text(encoding=\"utf-8\"))
Path('graphify-out/.graphify_detect.json').write_text(json.dumps({
'files': r.get('new_files', {}),
'all_files': r.get('files', {}),
'total_files': r.get('new_total', 0),
'total_words': r.get('total_words', 0),
'skipped_sensitive': r.get('skipped_sensitive', []),
'needs_graph': True,
}, ensure_ascii=False), encoding=\"utf-8\")
"
```
If new files exist, first check whether all changed files are code files:
```bash
$(cat graphify-out/.graphify_python) -c "
import json
from pathlib import Path
result = json.loads(open('graphify-out/.graphify_incremental.json', encoding='utf-8').read()) if Path('graphify-out/.graphify_incremental.json').exists() else {}
code_exts = {'.py','.ts','.js','.go','.rs','.java','.cpp','.c','.rb','.swift','.kt','.cs','.scala','.php','.cc','.cxx','.hpp','.h','.kts','.lua','.toc','.f','.F','.f90','.F90','.f95','.F95','.f03','.F03','.f08','.F08'}
new_files = result.get('new_files', {})
all_changed = [f for files in new_files.values() for f in files]
code_only = all(Path(f).suffix.lower() in code_exts for f in all_changed)
print('code_only:', code_only)
"
```
If `code_only` is True: print `[graphify update] Code-only changes detected - skipping semantic extraction (no LLM needed)`, run Step 3A (AST) on the changed files, then follow only Part B's **Fast path** to overwrite `.graphify_semantic.json` with an empty result and run Part C to create `.graphify_extract.json` from the fresh AST result. Skip semantic cache checks/writes and subagents (Steps B0–B3); do not reuse semantic sidecars from a prior run. Continue to the incremental merge and Steps 4–8 only after Part C has completed.
If `code_only` is False (any changed file is a doc/paper/image/video): **first, if any changed file is in `new_files['video']`, run `references/transcribe.md` (Step 2.5) on those files, then rewrite `.graphify_detect.json` to move the resulting transcript paths into `files['document']` and drop `files['video']`** — otherwise raw `.mp4/.mp3` paths are fed to semantic subagents as unreadable media (#1392). Then run the full Steps 3A–3C pipeline as normal.
If no new files exist (only deletions), create an empty extraction so the merge step can prune:
```bash
if [ ! -f graphify-out/.graphify_extract.json ]; then
echo '[graphify update] Only deletions -- creating empty extraction for merge.'
$(cat graphify-out/.graphify_python) -c "
import json
from pathlib import Path
Path('graphify-out/.graphify_extract.json').write_text(json.dumps({'nodes':[],'edges':[],'hyperedges':[],'input_tokens':0,'output_tokens':0}), encoding='utf-8')
"
fi
```
Then:
```bash
$(cat graphify-out/.graphify_python) -c "
import json
from pathlib import Path
from graphify.build import build_merge
from graphify.detect import save_manifest
# Load new extraction and incremental state
new_extraction = json.loads(Path('graphify-out/.graphify_extract.json').read_text(encoding=\"utf-8\"))
incremental = json.loads(Path('graphify-out/.graphify_incremental.json').read_text(encoding=\"utf-8\"))
deleted = list(incremental.get('deleted_files', []))
# prune_sources is ONLY for genuinely DELETED files. Changed/re-extracted files are
# handled by build_merge's replace-on-re-extract (#1344): every source_file in
# new_chunks is dropped from the base before merge, so old/stale nodes don't survive.
# Do NOT add changed here: with root= passed, prune_set relativizes to the same base
# as the freshly merged nodes and would DELETE the re-extracted content (#1178 is moot
# now that replace — not the dedup pass — reconciles changed files).
prune = list(deleted) or None
# Use build_merge() — reads graph.json directly without NetworkX round-trip
# so edge direction (calls, implements, imports) is always preserved (#801).
# Pass root= so prune_sources (absolute paths from detect_incremental) are
# relativized to match the graph's relative source_file values; without it
# nothing is pruned and stale nodes accumulate on every update (#1361).
# directed=IS_DIRECTED: replace IS_DIRECTED with True if --directed was given, else
# False. Without it a --directed --update silently rebuilds undirected and collapses
# reciprocal A<->B edges (#1392).
G = build_merge(
[new_extraction],
graph_path='graphify-out/graph.json',
prune_sources=prune,
root='INPUT_PATH',
directed=IS_DIRECTED,
)
print(f'[graphify update] Merged: {G.number_of_nodes()} nodes, {G.number_of_edges()} edges')
# Write merged result back to .graphify_extract.json so Step 4 sees the full graph
merged_out = {
'nodes': [{'id': n, **d} for n, d in G.nodes(data=True)],
'edges': [
# Explicit source/target last so they win over any stale attrs in d.
{**{k: val for k, val in d.items() if k not in ('_src', '_tgt', 'source', 'target')},
'source': d.get('_src', u), 'target': d.get('_tgt', v)}
for u, v, d in G.edges(data=True)
],
# G.graph["hyperedges"] holds hyperedges from both existing graph.json
# and new_extraction (build_merge combines them). Falling back to
# new_extraction only would silently drop prior-run hyperedges (#801).
'hyperedges': list(G.graph.get('hyperedges', [])),
'input_tokens': new_extraction.get('input_tokens', 0),
'output_tokens': new_extraction.get('output_tokens', 0),
}
Path('graphify-out/.graphify_extract.json').write_text(json.dumps(merged_out, ensure_ascii=False), encoding=\"utf-8\")
print(f'[graphify update] Merged extraction written ({len(merged_out[\"nodes\"])} nodes, {len(merged_out[\"edges\"])} edges)')
# Save manifest so next --update diffs against today's state, not the
# prior run's baseline (prevents ghost-node reports on subsequent updates).
# root= matches the build_merge call above so the manifest keys stay relative to
# the scan root — portable across clones/machines, so --update keeps matching
# cached files instead of missing every one after a move (#1417).
#
# Only stamp semantic files (docs/papers/images) that ACTUALLY produced output
# THIS run (new_extraction is this run's fresh extraction, read above before the
# merge overwrote the file): a changed doc whose chunk failed must stay unstamped
# so the next --update re-queues it, otherwise it is marked done and its content
# is lost forever (#2015). Mirrors the library extract path
# (cli._stamped_manifest_files + clear_semantic + scan_corpus).
from graphify.cli import _stamped_manifest_files
_manifest_files = _stamped_manifest_files(incremental['files'], new_extraction, Path('INPUT_PATH'))
# Changed semantic files dispatched this run but NOT stamped had their chunk fail
# or be omitted; clear any stale semantic_hash so they are re-queued (#1948).
_sem_types = ('document', 'paper', 'image')
_dispatched = {f for t, fl in incremental.get('new_files', {}).items() if t in _sem_types for f in fl}
_stamped = {f for fl in _manifest_files.values() for f in fl}
_cleared = _dispatched - _stamped
# scan_corpus = the RAW full corpus so in-root files newly excluded since last run
# are dropped rather than masquerading as deletions; untouched rows preserved (#1908).
_scan = {f for fl in incremental['files'].values() for f in fl}
save_manifest(_manifest_files, root='INPUT_PATH', scan_corpus=_scan, clear_semantic=_cleared or None)
print('[graphify update] Manifest saved.')
"
```
Then run Steps 4–8 on the merged graph as normal.
After Step 4, show the graph diff:
```bash
$(cat graphify-out/.graphify_python) -c "
import json
from graphify.analyze import graph_diff
from graphify.build import build_from_json
from graphify.paths import load_node_link_graph
import networkx as nx
from pathlib import Path
# Load old graph (before update) from backup written before merge
old_data = json.loads(Path('graphify-out/.graphify_old.json').read_text(encoding=\"utf-8\")) if Path('graphify-out/.graphify_old.json').exists() else None
new_extract = json.loads(Path('graphify-out/.graphify_extract.json').read_text(encoding=\"utf-8\"))
G_new = build_from_json(new_extract, directed=IS_DIRECTED)
if old_data:
G_old = load_node_link_graph(old_data)
diff = graph_diff(G_old, G_new)
print(diff['summary'])
if diff['new_nodes']:
print('New nodes:', ', '.join(n['label'] for n in diff['new_nodes'][:5]))
if diff['new_edges']:
print('New edges:', len(diff['new_edges']))
"
```
Before the merge step, save the old graph: `cp graphify-out/graph.json graphify-out/.graphify_old.json`
Clean up after: `rm -f graphify-out/.graphify_old.json`
---
## For --cluster-only
Skip Steps 1–3. Re-run clustering on the existing graph:
```bash
graphify cluster-only .
```
`graphify cluster-only .` is **self-contained**: it re-clusters, names communities, and regenerates `GRAPH_REPORT.md`, `graph.json`, and `graph.html` from the existing graph. **Do not re-run Steps 5–9** — they read intermediate files (`.graphify_extract.json`, `.graphify_detect.json`, `.graphify_analysis.json`) that a prior build's cleanup (Step 9) already deleted, so they raise `FileNotFoundError` (#1392). When it finishes, present the refreshed `GRAPH_REPORT.md` summary as usual.
-26
View File
@@ -1,26 +0,0 @@
---
description: Git commit messages and how to split work into commits
alwaysApply: true
---
# Commits
When preparing commits (especially when the user asks to commit):
1. **Prefer multiple commits** over one large commit when changes span distinct concerns (e.g. UI vs docs vs API). One logical unit per commit.
2. **Message format:** `type(scope): short imperative subject` (lowercase subject after the colon; no trailing period).
- **Types:** `feat`, `fix`, `docs`, `style`, `refactor`, `test`, `chore`, `perf` (use what fits).
- **Scope:** optional but encouraged — e.g. `ui`, `api`, `profiles`, `presets`, `esp32`.
3. **Subject line:** ~50 characters or less; describe *what* changed, not the ticket number alone.
4. **Body:** only when needed (breaking change, non-obvious rationale, or multiple bullets). Otherwise subject is enough.
**Examples**
- `feat(ui): gate profile delete to edit mode`
- `docs: document run vs edit in API`
- `fix(api): resolve preset delete route argument clash`
**Do not**
- Squash unrelated fixes and doc tweaks into one commit unless the user explicitly wants a single commit.
- Use vague messages like `update`, `fixes`, or `wip`.
-45
View File
@@ -1,45 +0,0 @@
---
description: led-driver — MicroPython ESP32: mpremote, imports, layout, I/O, no pycache in src
globs: led-driver/**
alwaysApply: false
---
# led-driver (MicroPython / ESP32)
## Device and tests
1. Validate **MicroPython behaviour** under **`led-driver/`** with **`mpremote connect <PORT> …`** on the chip. Host **`python3`** does **not** prove the firmware build.
2. **Execution target is fixed:** treat **`led-driver/`** code as firmware that runs **only on MicroPython ESP32 devices**. Do **not** run `led-driver/src/main.py` (or other firmware modules) with host CPython as a normal execution path.
3. **Flow:** `mpremote connect <PORT> cp <local> :<on-flash>` then `run <script>.py`. Inline commands only — no **`.sh`** wrappers unless the user asks. Default serial placeholder: **`/dev/ttyACM0`**.
4. Checks that **import and run** code from **`led-driver/src/`** belong in **`led-driver/tests/`** and run with **`mpremote run …`**. **Do not** add **`pytest`** under **`led-controller/tests/`** that **`sys.path`**-loads **`led-driver/src`** and runs those modules on CPython.
## Import layout
4. **No** **`sys.path.insert`**, **`__file__`** path stitching, or other import-path hacks under **`led-driver/`**. Use device flash search path, or host **`PYTHONPATH`** / layout you control.
5. **No** “import fixer” code — fix copy order, flash paths, or env instead.
## Imports (fail loudly)
6. If a dependency does not load, **crash** and fix deployment or filesystem. **Do not** catch **`ImportError`** / **`ModuleNotFoundError`** around **`import`** / **`from … import`** for app/firmware modules (`settings`, `utils`, `network`, `machine`, …).
7. **Allowed — stdlib name pairs only** (MicroPython vs CPython): one **`except ImportError`**, then **one** fallback import, **no** extra logic in **`except`**:
- `uos` → `os`
- `ubinascii` → `binascii`
- `utime` → `time`
Not for “maybe the file exists on flash” — only different **stdlib** names.
8. **No** large inline reimplementations after **`except ImportError`** — deploy the real module.
## I/O
9. Non-blocking **recv** / **accept**: use plain **`except OSError:`** (or **break** on empty). **No** errno / EAGAIN / EWOULDBLOCK tables or **`getattr(errno, …)`** unless fixing a **documented** target bug.
10. Minimal **`try` / `except OSError`** around optional socket options (e.g. **`SO_REUSEADDR`**) is fine.
## Host Python and `src/`
11. **Do not** leave **`__pycache__/`** or **`.pyc`** under **`led-driver/src/`** from host runs. Remove if created; **`.gitignore`** already ignores it. Prefer **`PYTHONDONTWRITEBYTECODE=1`** or **`-B`** when host Python must touch **`led-driver/src/`**.
-12
View File
@@ -1,12 +0,0 @@
---
description: Require test pattern, pattern metadata, and test preset for new patterns
alwaysApply: true
---
# Pattern workflow requirements
1. When creating a new pattern under `led-driver/src/patterns/`, also add/update a corresponding test file in `led-driver/tests/patterns/`.
2. When adding a new pattern, ensure led-controller has `db/pattern.json`; if it does not exist, create it. Add the new pattern metadata and parameter mappings there.
3. When adding a new pattern, add at least one test preset entry in `db/preset.json` in led-controller that uses the new pattern.
-18
View File
@@ -1,18 +0,0 @@
---
description: Fix only the issue or task the user gave; no refactors unless requested
alwaysApply: true
---
# Scoped fixes (no overscoping)
1. **Change only what is needed** to satisfy the user’s *current* request (bug, error, feature, or explicit follow-up). Prefer the smallest diff that fixes it.
2. **Refactors:** Do **not** refactor (restructure, rename, extract functions, change abstractions, or “make it nicer”) **unless the user explicitly asked for a refactor**. A bug fix may touch nearby lines only as much as required to correct the bug.
3. **Do not** rename, reformat, or “clean up” unrelated code; do not add extra error handling, logging, or features you were not asked for.
4. **Related issues:** If you spot other problems (missing functions, wrong types elsewhere, style), you may **mention them in prose** — do **not** fix them unless the user explicitly asks.
5. **Tests and docs:** Add or change tests or documentation **only** when the user asked for them or they are strictly required to verify the requested fix.
6. **Multiple distinct fixes:** If the user reported one error (e.g. a single `TypeError`), fix **that** cause first. Offer to tackle follow-ups separately rather than bundling.
-10
View File
@@ -1,10 +0,0 @@
---
description: British spelling for user-facing text; technical identifiers stay as-is
alwaysApply: true
---
# Spelling: colour
- **User-facing strings** (Help modal, button labels, README prose, `docs/`, error messages shown in the UI): use **British English** — **colour**, **favour**, **behaviour**, etc., unless quoting existing product names.
- **Do not rename** existing code for spelling: **identifiers**, file names, URL paths, JSON keys, CSS properties (`color`), HTML attributes (`type="color"`), and API field names stay as they are (`color`, `colors`, `palette`, etc.) so nothing breaks.
- **New** UI copy and docs should follow **colour** in prose; new code symbols may still use `color` when matching surrounding APIs or conventions.
-16
View File
@@ -1,16 +0,0 @@
---
description: enforce strict user-scoped changes only
alwaysApply: true
---
# Strict User Scope
1. Only implement exactly what the user asked for in the current message.
2. Do not add extra refactors, cleanups, renames, architecture changes, or behavioural changes unless the user explicitly asked for them.
3. If a potential improvement is noticed, mention it briefly and ask before changing code.
4. For revert/undo requests, perform the narrowest possible revert and do not modify anything else.
5. Keep edits minimal and local to the requested area.
+1 -12
View File
@@ -1,7 +1,5 @@
# Python
__pycache__/
# led-driver/src is MicroPython source — never keep host __pycache__ there (see .cursor/rules/led-driver.mdc)
led-driver/src/__pycache__/
*.py[cod]
*$py.class
*.so
@@ -25,16 +23,7 @@ ENV/
Thumbs.db
# Project specific
scripts/.led-controller-venv
docs/.help-print.html
settings.json
*.log
*.db
*.sqlite
.pytest_cache/
.ropeproject/
build/
sdkconfig
sdkconfig.old
managed_components/
www_dist/
-9
View File
@@ -1,9 +0,0 @@
[submodule "led-driver"]
path = led-driver
url = git@git.technical.kiwi:technicalkiwi/led-driver.git
[submodule "led-tool"]
path = led-tool
url = git@git.technical.kiwi:technicalkiwi/led-tool.git
[submodule "led-simulator"]
path = led-simulator
url = git@git.technical.kiwi:technicalkiwi/led-simulator.git
-10
View File
@@ -1,10 +0,0 @@
## graphify
This project has a knowledge graph at graphify-out/ with god nodes, community structure, and cross-file relationships.
Rules:
- When graphify-out/graph.json exists, run `graphify query "<question>"` before your first grep, search or source-file read for a codebase question, and put this rule in every subagent prompt that explores code. Read raw files only for lines the graph or an earlier read already located. Use `graphify path "<A>" "<B>"` for relationships and `graphify explain "<concept>"` for focused concepts. These return a scoped subgraph, usually much smaller than GRAPH_REPORT.md or raw grep output.
- If graphify-out/wiki/index.md exists, use it for broad navigation instead of raw source browsing.
- Read graphify-out/GRAPH_REPORT.md only for broad architecture review or when query/path/explain do not surface enough context.
- After modifying code, run `graphify update .` to keep the graph current (AST-only, no API cost).
- A committed graphify-out/graph.json is rewritten whole on every build, so a large diff to it in a pull request is expected. Do not flag it as churn or suggest skipping the graph rebuild or its hooks.
-3
View File
@@ -1,3 +0,0 @@
cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(led_controller)
-148
View File
@@ -1,148 +0,0 @@
# Build, flash and monitor the ESP32-S3 controller (ESP-IDF in Docker).
#
# make build, flash, then monitor (same as: make all)
# make help list the targets
# make build minify the web UI, then build the firmware
# make flash flash the last build to the S3 (does not build)
# make monitor serial console (Ctrl-] to quit)
# make flash-monitor
#
# Override on the command line, e.g. make flash PORT=/dev/ttyACM1
PORT ?= /dev/ttyACM0
IDF_IMAGE ?= espressif/idf:v5.5.5
SECS ?= 10
DOCKER_RUN = docker run --rm -v "$(CURDIR)":/project -w /project
DEVICE = --device=$(PORT)
# Interactive terminal only when there is one (monitor needs it, CI does not have it)
TTY := $(shell [ -t 0 ] && echo -it)
# Rootless Docker maps container root to you, so files must end up owned by uid 0 inside; with a
# normal daemon they must be owned by you.
OWNER := $(shell docker info --format '{{.SecurityOptions}}' 2>/dev/null | grep -q rootless && echo 0:0 || echo $$(id -u):$$(id -g))
FIX_OWNER = chown -R $(OWNER) /project
.PHONY: all help web build flash ota ota-drivers monitor flash-monitor log size menuconfig clean fullclean erase test test-driver test-envelope test-api test-browser sim-build sim sim-web test-sim
# Default target: build, flash, then open the console (run in order, so not with make -j)
all: build flash monitor
help:
@echo "LED controller (ESP32-S3):"
@echo " make [all] build, flash, then open the console"
@echo " make build minify + gzip the web UI, then build the firmware"
@echo " make flash flash the last build (firmware and web UI) to PORT ($(PORT)); does not build"
@echo " make ota [HOST=ip] build, then upload the firmware (web UI included) over Ethernet (no USB);"
@echo " HOST defaults to led-controller.local"
@echo " make ota-drivers HOST=ip [MAC=aabbccddeeff] [BROADCAST=1]"
@echo " push changed led-driver .py files over ESP-NOW (all drivers without MAC)"
@echo " make monitor serial console on PORT (Ctrl-] to quit)"
@echo " make flash-monitor flash the last build, then open the console"
@echo " make log [SECS=10] print the console for SECS seconds and exit (no terminal needed)"
@echo " make web only rebuild the web UI (needs node/npx)"
@echo " make size memory use of the last build"
@echo " make menuconfig change the ESP-NOW channel, marker pin, W5500 pins, ..."
@echo " make erase erase the whole flash (loses the stored data)"
@echo " make clean remove the build directory (keeps sdkconfig)"
@echo " make fullclean also remove sdkconfig and the web UI output"
@echo " make test driver unit tests + C/Python envelope cross-check"
@echo " make test-api HOST=ip HTTP API tests against a running controller (data restored afterwards)"
@echo " make test-browser HOST=ip Selenium UI tests against a running controller (needs selenium + chromedriver)"
@echo "Simulated rig (no hardware): the controller built for linux + led-simulator's 16 drivers over a UDP bridge"
@echo " make sim-build build the controller for the host (sim-controller/build/led_controller_sim.elf)"
@echo " make sim build, then run the headless rig and the controller (http://localhost:8080/)"
@echo " make sim-web build, then run the browser rig (http://localhost:8765/) and the controller"
@echo " make test-sim rig tests (groups, field patterns, sequences) + the API tests against make sim"
@echo "variables: PORT=$(PORT) IDF_IMAGE=$(IDF_IMAGE)"
# --- web UI ---------------------------------------------------------------
web:
tools/build_web.sh
# --- firmware -------------------------------------------------------------
# The build time in the image comes from esp_app_desc.c, which nothing else recompiles (a web-only
# change just relinks), so drop its object and every build gets the current time.
APP_DESC_OBJ = build/esp-idf/esp_app_format/CMakeFiles/__idf_esp_app_format.dir/esp_app_desc.c.obj
build: web
$(DOCKER_RUN) $(IDF_IMAGE) bash -c 'rm -f $(APP_DESC_OBJ); idf.py build; rc=$$?; $(FIX_OWNER); exit $$rc'
flash:
$(DOCKER_RUN) $(DEVICE) $(IDF_IMAGE) bash -c 'idf.py -p $(PORT) flash; rc=$$?; $(FIX_OWNER); exit $$rc'
ota: HOST ?= led-controller.local
ota: build
python3 tools/ota.py $(HOST)
ota-drivers:
@test -n "$(HOST)" || { echo "usage: make ota-drivers HOST=<controller ip> [MAC=...] [BROADCAST=1]"; exit 1; }
python3 tools/driver_ota.py $(HOST) $(if $(MAC),--mac $(MAC),--all) $(if $(BROADCAST),--broadcast)
monitor:
$(DOCKER_RUN) $(TTY) $(DEVICE) $(IDF_IMAGE) idf.py -p $(PORT) monitor
flash-monitor: flash monitor
# Non-interactive: reset the board and print what it says for SECS seconds
log:
python3 tools/serial_log.py $(PORT) $(SECS)
size:
$(DOCKER_RUN) $(IDF_IMAGE) bash -c 'idf.py size; rc=$$?; $(FIX_OWNER); exit $$rc'
menuconfig:
$(DOCKER_RUN) -it $(IDF_IMAGE) bash -c 'idf.py menuconfig; rc=$$?; $(FIX_OWNER); exit $$rc'
erase:
$(DOCKER_RUN) $(DEVICE) $(IDF_IMAGE) idf.py -p $(PORT) erase-flash
clean:
rm -rf build
fullclean: clean
rm -rf sdkconfig sdkconfig.old www_dist
# --- tests ----------------------------------------------------------------
test: test-driver test-envelope
# Host-side unit tests for the driver's link layer and beat sync (pure Python)
test-driver:
python3 tools/run_driver_tests.py
# HTTP API tests (ported from v1) against a running controller; v1 features v2 lacks are xfail
test-api:
@test -n "$(HOST)" || { echo "usage: make test-api HOST=<controller ip>"; exit 1; }
python3 -m pytest test/api -q --host $(HOST)
# Selenium UI tests (ported from v1); they change the controller's data and do not restore it
test-browser:
@test -n "$(HOST)" || { echo "usage: make test-browser HOST=<controller ip>"; exit 1; }
LED_CONTROLLER_RUN_BROWSER_TESTS=1 LED_HOST=$(HOST) python3 -m pytest test/browser -q
# The C envelope packer must produce the same bytes as test/binary_envelope.py
test-envelope:
@tmp=$$(mktemp -d); \
(cd test && python3 env_check.py) > $$tmp/py.txt; \
docker run --rm -v "$(CURDIR)":/project -w /project/test $(IDF_IMAGE) bash -c \
'gcc -Wall -I/opt/esp/idf/components/json/cJSON env_host.c ../main/envelope.c /opt/esp/idf/components/json/cJSON/cJSON.c -o /tmp/t -lm && /tmp/t' 2>&1 | tail -4 | head -3 > $$tmp/c.txt; \
if diff -q $$tmp/py.txt $$tmp/c.txt >/dev/null; then echo "envelope: C and Python agree"; rm -rf $$tmp; \
else echo "envelope: MISMATCH"; diff $$tmp/py.txt $$tmp/c.txt; rm -rf $$tmp; exit 1; fi
# --- simulated rig --------------------------------------------------------
# The firmware built for ESP-IDF's linux target runs on this computer; its ESP-NOW frames go over UDP to
# led-simulator (bridge_sim.py headless, or server.py in the browser), whose drivers run led-driver/src.
SIM_DB ?= $(CURDIR)/sim-controller/data
SIM_RUN = mkdir -p $(SIM_DB) && LED_SIM_DB=$(SIM_DB) LED_SIM_BRIDGE=127.0.0.1:8766 sim-controller/build/led_controller_sim.elf
sim-build: web
$(DOCKER_RUN) $(IDF_IMAGE) bash -c 'cd sim-controller && idf.py build; rc=$$?; $(FIX_OWNER); exit $$rc'
sim: sim-build
@trap 'kill 0' INT TERM EXIT; python3 led-simulator/bridge_sim.py & $(SIM_RUN)
sim-web: sim-build
@trap 'kill 0' INT TERM EXIT; python3 led-simulator/server.py & $(SIM_RUN)
test-sim:
python3 -m pytest test/api -q --host localhost:8080
+24
View File
@@ -0,0 +1,24 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
mpremote = "*"
pyserial = "*"
esptool = "*"
pyjwt = "*"
watchfiles = "*"
requests = "*"
selenium = "*"
adafruit-ampy = "*"
[dev-packages]
[requires]
python_version = "3.12"
[scripts]
web = "python /home/pi/led-controller/tests/web.py"
watch = "python -m watchfiles 'python tests/web.py' src tests"
install = "pipenv install"
Generated
+926
View File
@@ -0,0 +1,926 @@
{
"_meta": {
"hash": {
"sha256": "c963cd52164ac13fda5e6f3c5975bc14db6cea03ad4973de02ad91a0ab10d2ea"
},
"pipfile-spec": 6,
"requires": {
"python_version": "3.12"
},
"sources": [
{
"name": "pypi",
"url": "https://pypi.org/simple",
"verify_ssl": true
}
]
},
"default": {
"adafruit-ampy": {
"hashes": [
"sha256:4a74812226e53c17d01eb828633424bc4f4fe76b9499a7b35eba6fc2532635b7",
"sha256:f4cba36f564096f2aafd173f7fbabb845365cc3bb3f41c37541edf98b58d3976"
],
"index": "pypi",
"version": "==1.1.0"
},
"anyio": {
"hashes": [
"sha256:41cfcc3a4c85d3f05c932da7c26d0201ac36f72abd4435ba90d0464a3ffed703",
"sha256:d405828884fc140aa80a3c667b8beed277f1dfedec42ba031bd6ac3db606ab6c"
],
"markers": "python_version >= '3.9'",
"version": "==4.12.1"
},
"async-generator": {
"hashes": [
"sha256:01c7bf666359b4967d2cda0000cc2e4af16a0ae098cbffcb8472fb9e8ad6585b",
"sha256:6ebb3d106c12920aaae42ccb6f787ef5eefdcdd166ea3d628fa8476abe712144"
],
"markers": "python_version >= '3.5'",
"version": "==1.10"
},
"attrs": {
"hashes": [
"sha256:16d5969b87f0859ef33a48b35d55ac1be6e42ae49d5e853b597db70c35c57e11",
"sha256:adcf7e2a1fb3b36ac48d97835bb6d8ade15b8dcce26aba8bf1d14847b57a3373"
],
"markers": "python_version >= '3.9'",
"version": "==25.4.0"
},
"bitarray": {
"hashes": [
"sha256:004d518fa410e6da43386d20e07b576a41eb417ac67abf9f30fa75e125697199",
"sha256:014df8a9430276862392ac5d471697de042367996c49f32d0008585d2c60755a",
"sha256:01c5f0dc080b0ebb432f7a68ee1e88a76bd34f6d89c9568fcec65fb16ed71f0e",
"sha256:025d133bf4ca8cf75f904eeb8ea946228d7c043231866143f31946a6f4dd0bf3",
"sha256:0ca70ccf789446a6dfde40b482ec21d28067172cd1f8efd50d5548159fccad9e",
"sha256:0df69d26f21a9d2f1b20266f6737fa43f08aa5015c99900fb69f255fbe4dabb4",
"sha256:0f8069a807a3e6e3c361ce302ece4bf1c3b49962c1726d1d56587e8f48682861",
"sha256:15a2eff91f54d2b1f573cca8ca6fb58763ce8fea80e7899ab028f3987ef71cd5",
"sha256:15e8d0597cc6e8496de6f4dea2a6880c57e1251502a7072f5631108a1aa28521",
"sha256:165052a0e61c880f7093808a0c524ce1b3555bfa114c0dfb5c809cd07918a60d",
"sha256:178c5a4c7fdfb5cd79e372ae7f675390e670f3732e5bc68d327e01a5b3ff8d55",
"sha256:18214bac86341f1cc413772e66447d6cca10981e2880b70ecaf4e826c04f95e9",
"sha256:1a54d7e7999735faacdcbe8128e30207abc2caf9f9fd7102d180b32f1b78bfce",
"sha256:1a926fa554870642607fd10e66ee25b75fdd9a7ca4bbffa93d424e4ae2bf734a",
"sha256:1c8f2a5d8006db5a555e06f9437e76bf52537d3dfd130cb8ae2b30866aca32c9",
"sha256:21ca6a47bf20db9e7ad74ca04b3d479e4d76109b68333eb23535553d2705339e",
"sha256:22c540ed20167d3dbb1e2d868ca935180247d620c40eace90efa774504a40e3b",
"sha256:239578587b9c29469ab61149dda40a2fe714a6a4eca0f8ff9ea9439ec4b7bc30",
"sha256:25b9cff6c9856bc396232e2f609ea0c5ec1a8a24c500cee4cca96ba8a3cd50b6",
"sha256:26714898eb0d847aac8af94c4441c9cb50387847d0fe6b9fc4217c086cd68b80",
"sha256:28a85b056c0eb7f5d864c0ceef07034117e8ebfca756f50648c71950a568ba11",
"sha256:2a3d1b05ffdd3e95687942ae7b13c63689f85d3f15c39b33329e3cb9ce6c015f",
"sha256:2c3bb96b6026643ce24677650889b09073f60b9860a71765f843c99f9ab38b25",
"sha256:2fa23fdb3beab313950bbb49674e8a161e61449332d3997089fe3944953f1b77",
"sha256:2fe8c54b15a9cd4f93bc2aaceab354ec65af93370aa1496ba2f9c537a4855ee0",
"sha256:30989a2451b693c3f9359d91098a744992b5431a0be4858f1fdf0ec76b457125",
"sha256:31a4ad2b730128e273f1c22300da3e3631f125703e4fee0ac44d385abfb15671",
"sha256:337c8cd46a4c6568d367ed676cbf2d7de16f890bb31dbb54c44c1d6bb6d4a1de",
"sha256:33af25c4ff7723363cb8404dfc2eefeab4110b654f6c98d26aba8a08c745d860",
"sha256:3ea52df96566457735314794422274bd1962066bfb609e7eea9113d70cf04ffe",
"sha256:3eae38daffd77c9621ae80c16932eea3fb3a4af141fb7cc724d4ad93eff9210d",
"sha256:41b53711f89008ba2de62e4c2d2260a8b357072fd4f18e1351b28955db2719dc",
"sha256:451f9958850ea98440d542278368c8d1e1ea821e2494b204570ba34a340759df",
"sha256:46cf239856b87fe1c86dfbb3d459d840a8b1649e7922b1e0bfb6b6464692644a",
"sha256:4779f356083c62e29b4198d290b7b17a39a69702d150678b7efff0fdddf494a8",
"sha256:4902f4ecd5fcb6a5f482d7b0ae1c16c21f26fc5279b3b6127363d13ad8e7a9d9",
"sha256:4d73d4948dcc5591d880db8933004e01f1dd2296df9de815354d53469beb26fe",
"sha256:4d9984017314da772f5f7460add7a0301a4ffc06c72c2998bb16c300a6253607",
"sha256:4f298daaaea58d45e245a132d6d2bdfb6f856da50dc03d75ebb761439fb626cf",
"sha256:50ddbe3a7b4b6ab96812f5a4d570f401a2cdb95642fd04c062f98939610bbeee",
"sha256:5338a313f998e1be7267191b7caaae82563b4a2b42b393561055412a34042caa",
"sha256:5591daf81313096909d973fb2612fccd87528fdfdd39f6478bdce54543178954",
"sha256:56896ceeffe25946c4010320629e2d858ca763cd8ded273c81672a5edbcb1e0a",
"sha256:58a01ea34057463f7a98a4d6ff40160f65f945e924fec08a5b39e327e372875d",
"sha256:5bfac7f236ba1a4d402644bdce47fb9db02a7cf3214a1f637d3a88390f9e5428",
"sha256:5c5a8a83df95e51f7a7c2b083eaea134cbed39fc42c6aeb2e764ddb7ccccd43e",
"sha256:5f2fb10518f6b365f5b720e43a529c3b2324ca02932f609631a44edb347d8d54",
"sha256:64af877116edf051375b45f0bda648143176a017b13803ec7b3a3111dc05f4c5",
"sha256:6d70fa9c6d2e955bde8cd327ffc11f2cc34bc21944e5571a46ca501e7eadef24",
"sha256:6d79f659965290af60d6acc8e2716341865fe74609a7ede2a33c2f86ad893b8f",
"sha256:720963fee259291a88348ae9735d9deb5d334e84a016244f61c89f5a49aa400a",
"sha256:75a3b6e9c695a6570ea488db75b84bb592ff70a944957efa1c655867c575018b",
"sha256:792462abfeeca6cc8c6c1e6d27e14319682f0182f6b0ba37befe911af794db70",
"sha256:79ec4498a545733ecace48d780d22407411b07403a2e08b9a4d7596c0b97ebd7",
"sha256:7f14d6b303e55bd7d19b28309ef8014370e84a3806c5e452e078e7df7344d97a",
"sha256:7f65bd5d4cdb396295b6aa07f84ca659ac65c5c68b53956a6d95219e304b0ada",
"sha256:81c6b4a6c1af800d52a6fa32389ef8f4281583f4f99dc1a40f2bb47667281541",
"sha256:82a07de83dce09b4fa1bccbdc8bde8f188b131666af0dc9048ba0a0e448d8a3b",
"sha256:847c7f61964225fc489fe1d49eda7e0e0d253e98862c012cecf845f9ad45cdf4",
"sha256:84b52b2cf77bb7f703d16c4007b021078dbbe6cf8ffb57abe81a7bacfc175ef2",
"sha256:86685fa04067f7175f9718489ae755f6acde03593a1a9ca89305554af40e14fd",
"sha256:8a9c962c64a4c08def58b9799333e33af94ec53038cf151d36edacdb41f81646",
"sha256:8cbd4bfc933b33b85c43ef4c1f4d5e3e9d91975ea6368acf5fbac02bac06ea89",
"sha256:8ffe660e963ae711cb9e2b8d8461c9b1ad6167823837fc17d59d5e539fb898fa",
"sha256:94652da1a4ca7cfb69c15dd6986b205e0bd9c63a05029c3b48b4201085f527bd",
"sha256:969fd67de8c42affdb47b38b80f1eaa79ac0ef17d65407cdd931db1675315af1",
"sha256:9858dcbc23ba7eaadcd319786b982278a1a2b2020720b19db43e309579ff76fb",
"sha256:99d25aff3745c54e61ab340b98400c52ebec04290a62078155e0d7eb30380220",
"sha256:99f55e14e7c56f4fafe1343480c32b110ef03836c21ff7c48bae7add6818f77c",
"sha256:9d35d8f8a1c9ed4e2b08187b513f8a3c71958600129db3aa26d85ea3abfd1310",
"sha256:a2ba92f59e30ce915e9e79af37649432e3a212ddddf416d4d686b1b4825bcdb2",
"sha256:a2cb35a6efaa0e3623d8272471371a12c7e07b51a33e5efce9b58f655d864b4e",
"sha256:a358277122456666a8b2a0b9aa04f1b89d34e8aa41d08a6557d693e6abb6667c",
"sha256:a60da2f9efbed355edb35a1fb6829148676786c829fad708bb6bb47211b3593a",
"sha256:aa7dec53c25f1949513457ef8b0ea1fb40e76c672cc4d2daa8ad3c8d6b73491a",
"sha256:b1572ee0eb1967e71787af636bb7d1eb9c6735d5337762c450650e7f51844594",
"sha256:b4f10d3f304be7183fac79bf2cd997f82e16aa9a9f37343d76c026c6e435a8a8",
"sha256:bbbbfbb7d039b20d289ce56b1beb46138d65769d04af50c199c6ac4cb6054d52",
"sha256:c394a3f055b49f92626f83c1a0b6d6cd2c628f1ccd72481c3e3c6aa4695f3b20",
"sha256:c396358023b876cff547ce87f4e8ff8a2280598873a137e8cc69e115262260b8",
"sha256:c5ba07e58fd98c9782201e79eb8dd4225733d212a5a3700f9a84d329bd0463a6",
"sha256:c764fb167411d5afaef88138542a4bfa28bd5e5ded5e8e42df87cef965efd6e9",
"sha256:cbba763d99de0255a3e4938f25a8579930ac8aa089233cb2fb2ed7d04d4aff02",
"sha256:cbd1660fb48827381ce3a621a4fdc237959e1cd4e98b098952a8f624a0726425",
"sha256:cd761d158f67e288fd0ebe00c3b158095ce80a4bc7c32b60c7121224003ba70d",
"sha256:cdfbb27f2c46bb5bbdcee147530cbc5ca8ab858d7693924e88e30ada21b2c5e2",
"sha256:d2dbe8a3baf2d842e342e8acb06ae3844765d38df67687c144cdeb71f1bcb5d7",
"sha256:d5c931ec1c03111718cabf85f6012bb2815fa0ce578175567fa8d6f2cc15d3b4",
"sha256:df6d7bf3e15b7e6e202a16ff4948a51759354016026deb04ab9b5acbbe35e096",
"sha256:dfbe2aa45b273f49e715c5345d94874cb65a28482bf231af408891c260601b8d",
"sha256:e12769d3adcc419e65860de946df8d2ed274932177ac1cdb05186e498aaa9149",
"sha256:e5aed4754895942ae15ffa48c52d181e1c1463236fda68d2dba29c03aa61786b",
"sha256:e645b4c365d6f1f9e0799380ad6395268f3c3b898244a650aaeb8d9d27b74c35",
"sha256:ed3493a369fe849cce98542d7405c88030b355e4d2e113887cb7ecc86c205773",
"sha256:f08342dc8d19214faa7ef99574dea6c37a2790d6d04a9793ef8fa76c188dc08d",
"sha256:f0a55cf02d2cdd739b40ce10c09bbdd520e141217696add7a48b56e67bdfdfe6",
"sha256:f0ce9d9e07c75da8027c62b4c9f45771d1d8aae7dc9ad7fb606c6a5aedbe9741",
"sha256:f1f723e260c35e1c7c57a09d3a6ebe681bd56c83e1208ae3ce1869b7c0d10d4f",
"sha256:f2fcbe9b3a5996b417e030aa33a562e7e20dfc86271e53d7e841fc5df16268b8",
"sha256:f3fd8df63c41ff6a676d031956aebf68ebbc687b47c507da25501eb22eec341f",
"sha256:f8d3417db5e14a6789073b21ae44439a755289477901901bae378a57b905e148",
"sha256:fbf05678c2ae0064fb1b8de7e9e8f0fc30621b73c8477786dd0fb3868044a8c8",
"sha256:fc98ff43abad61f00515ad9a06213b7716699146e46eabd256cdfe7cb522bd97",
"sha256:ff1863f037dad765ef5963efc2e37d399ac023e192a6f2bb394e2377d023cefe"
],
"version": "==3.8.0"
},
"bitstring": {
"hashes": [
"sha256:69d1587f0ac18dc7d93fc7e80d5f447161a33e57027e726dc18a0a8bacf1711a",
"sha256:a08bc09d3857216d4c0f412a1611056f1cc2b64fd254fb1e8a0afba7cfa1a95a"
],
"markers": "python_version >= '3.8'",
"version": "==4.3.1"
},
"certifi": {
"hashes": [
"sha256:9943707519e4add1115f44c2bc244f782c0249876bf51b6599fee1ffbedd685c",
"sha256:ac726dd470482006e014ad384921ed6438c457018f4b3d204aea4281258b2120"
],
"markers": "python_version >= '3.7'",
"version": "==2026.1.4"
},
"cffi": {
"hashes": [
"sha256:00bdf7acc5f795150faa6957054fbbca2439db2f775ce831222b66f192f03beb",
"sha256:07b271772c100085dd28b74fa0cd81c8fb1a3ba18b21e03d7c27f3436a10606b",
"sha256:087067fa8953339c723661eda6b54bc98c5625757ea62e95eb4898ad5e776e9f",
"sha256:0a1527a803f0a659de1af2e1fd700213caba79377e27e4693648c2923da066f9",
"sha256:0cf2d91ecc3fcc0625c2c530fe004f82c110405f101548512cce44322fa8ac44",
"sha256:0f6084a0ea23d05d20c3edcda20c3d006f9b6f3fefeac38f59262e10cef47ee2",
"sha256:12873ca6cb9b0f0d3a0da705d6086fe911591737a59f28b7936bdfed27c0d47c",
"sha256:19f705ada2530c1167abacb171925dd886168931e0a7b78f5bffcae5c6b5be75",
"sha256:1cd13c99ce269b3ed80b417dcd591415d3372bcac067009b6e0f59c7d4015e65",
"sha256:1e3a615586f05fc4065a8b22b8152f0c1b00cdbc60596d187c2a74f9e3036e4e",
"sha256:1f72fb8906754ac8a2cc3f9f5aaa298070652a0ffae577e0ea9bd480dc3c931a",
"sha256:1fc9ea04857caf665289b7a75923f2c6ed559b8298a1b8c49e59f7dd95c8481e",
"sha256:203a48d1fb583fc7d78a4c6655692963b860a417c0528492a6bc21f1aaefab25",
"sha256:2081580ebb843f759b9f617314a24ed5738c51d2aee65d31e02f6f7a2b97707a",
"sha256:21d1152871b019407d8ac3985f6775c079416c282e431a4da6afe7aefd2bccbe",
"sha256:24b6f81f1983e6df8db3adc38562c83f7d4a0c36162885ec7f7b77c7dcbec97b",
"sha256:256f80b80ca3853f90c21b23ee78cd008713787b1b1e93eae9f3d6a7134abd91",
"sha256:28a3a209b96630bca57cce802da70c266eb08c6e97e5afd61a75611ee6c64592",
"sha256:2c8f814d84194c9ea681642fd164267891702542f028a15fc97d4674b6206187",
"sha256:2de9a304e27f7596cd03d16f1b7c72219bd944e99cc52b84d0145aefb07cbd3c",
"sha256:38100abb9d1b1435bc4cc340bb4489635dc2f0da7456590877030c9b3d40b0c1",
"sha256:3925dd22fa2b7699ed2617149842d2e6adde22b262fcbfada50e3d195e4b3a94",
"sha256:3e17ed538242334bf70832644a32a7aae3d83b57567f9fd60a26257e992b79ba",
"sha256:3e837e369566884707ddaf85fc1744b47575005c0a229de3327f8f9a20f4efeb",
"sha256:3f4d46d8b35698056ec29bca21546e1551a205058ae1a181d871e278b0b28165",
"sha256:44d1b5909021139fe36001ae048dbdde8214afa20200eda0f64c068cac5d5529",
"sha256:45d5e886156860dc35862657e1494b9bae8dfa63bf56796f2fb56e1679fc0bca",
"sha256:4647afc2f90d1ddd33441e5b0e85b16b12ddec4fca55f0d9671fef036ecca27c",
"sha256:4671d9dd5ec934cb9a73e7ee9676f9362aba54f7f34910956b84d727b0d73fb6",
"sha256:53f77cbe57044e88bbd5ed26ac1d0514d2acf0591dd6bb02a3ae37f76811b80c",
"sha256:5eda85d6d1879e692d546a078b44251cdd08dd1cfb98dfb77b670c97cee49ea0",
"sha256:5fed36fccc0612a53f1d4d9a816b50a36702c28a2aa880cb8a122b3466638743",
"sha256:61d028e90346df14fedc3d1e5441df818d095f3b87d286825dfcbd6459b7ef63",
"sha256:66f011380d0e49ed280c789fbd08ff0d40968ee7b665575489afa95c98196ab5",
"sha256:6824f87845e3396029f3820c206e459ccc91760e8fa24422f8b0c3d1731cbec5",
"sha256:6c6c373cfc5c83a975506110d17457138c8c63016b563cc9ed6e056a82f13ce4",
"sha256:6d02d6655b0e54f54c4ef0b94eb6be0607b70853c45ce98bd278dc7de718be5d",
"sha256:6d50360be4546678fc1b79ffe7a66265e28667840010348dd69a314145807a1b",
"sha256:730cacb21e1bdff3ce90babf007d0a0917cc3e6492f336c2f0134101e0944f93",
"sha256:737fe7d37e1a1bffe70bd5754ea763a62a066dc5913ca57e957824b72a85e205",
"sha256:74a03b9698e198d47562765773b4a8309919089150a0bb17d829ad7b44b60d27",
"sha256:7553fb2090d71822f02c629afe6042c299edf91ba1bf94951165613553984512",
"sha256:7a66c7204d8869299919db4d5069a82f1561581af12b11b3c9f48c584eb8743d",
"sha256:7cc09976e8b56f8cebd752f7113ad07752461f48a58cbba644139015ac24954c",
"sha256:81afed14892743bbe14dacb9e36d9e0e504cd204e0b165062c488942b9718037",
"sha256:8941aaadaf67246224cee8c3803777eed332a19d909b47e29c9842ef1e79ac26",
"sha256:89472c9762729b5ae1ad974b777416bfda4ac5642423fa93bd57a09204712322",
"sha256:8ea985900c5c95ce9db1745f7933eeef5d314f0565b27625d9a10ec9881e1bfb",
"sha256:8eca2a813c1cb7ad4fb74d368c2ffbbb4789d377ee5bb8df98373c2cc0dee76c",
"sha256:92b68146a71df78564e4ef48af17551a5ddd142e5190cdf2c5624d0c3ff5b2e8",
"sha256:9332088d75dc3241c702d852d4671613136d90fa6881da7d770a483fd05248b4",
"sha256:94698a9c5f91f9d138526b48fe26a199609544591f859c870d477351dc7b2414",
"sha256:9a67fc9e8eb39039280526379fb3a70023d77caec1852002b4da7e8b270c4dd9",
"sha256:9de40a7b0323d889cf8d23d1ef214f565ab154443c42737dfe52ff82cf857664",
"sha256:a05d0c237b3349096d3981b727493e22147f934b20f6f125a3eba8f994bec4a9",
"sha256:afb8db5439b81cf9c9d0c80404b60c3cc9c3add93e114dcae767f1477cb53775",
"sha256:b18a3ed7d5b3bd8d9ef7a8cb226502c6bf8308df1525e1cc676c3680e7176739",
"sha256:b1e74d11748e7e98e2f426ab176d4ed720a64412b6a15054378afdb71e0f37dc",
"sha256:b21e08af67b8a103c71a250401c78d5e0893beff75e28c53c98f4de42f774062",
"sha256:b4c854ef3adc177950a8dfc81a86f5115d2abd545751a304c5bcf2c2c7283cfe",
"sha256:b882b3df248017dba09d6b16defe9b5c407fe32fc7c65a9c69798e6175601be9",
"sha256:baf5215e0ab74c16e2dd324e8ec067ef59e41125d3eade2b863d294fd5035c92",
"sha256:c649e3a33450ec82378822b3dad03cc228b8f5963c0c12fc3b1e0ab940f768a5",
"sha256:c654de545946e0db659b3400168c9ad31b5d29593291482c43e3564effbcee13",
"sha256:c6638687455baf640e37344fe26d37c404db8b80d037c3d29f58fe8d1c3b194d",
"sha256:c8d3b5532fc71b7a77c09192b4a5a200ea992702734a2e9279a37f2478236f26",
"sha256:cb527a79772e5ef98fb1d700678fe031e353e765d1ca2d409c92263c6d43e09f",
"sha256:cf364028c016c03078a23b503f02058f1814320a56ad535686f90565636a9495",
"sha256:d48a880098c96020b02d5a1f7d9251308510ce8858940e6fa99ece33f610838b",
"sha256:d68b6cef7827e8641e8ef16f4494edda8b36104d79773a334beaa1e3521430f6",
"sha256:d9b29c1f0ae438d5ee9acb31cadee00a58c46cc9c0b2f9038c6b0b3470877a8c",
"sha256:d9b97165e8aed9272a6bb17c01e3cc5871a594a446ebedc996e2397a1c1ea8ef",
"sha256:da68248800ad6320861f129cd9c1bf96ca849a2771a59e0344e88681905916f5",
"sha256:da902562c3e9c550df360bfa53c035b2f241fed6d9aef119048073680ace4a18",
"sha256:dbd5c7a25a7cb98f5ca55d258b103a2054f859a46ae11aaf23134f9cc0d356ad",
"sha256:dd4f05f54a52fb558f1ba9f528228066954fee3ebe629fc1660d874d040ae5a3",
"sha256:de8dad4425a6ca6e4e5e297b27b5c824ecc7581910bf9aee86cb6835e6812aa7",
"sha256:e11e82b744887154b182fd3e7e8512418446501191994dbf9c9fc1f32cc8efd5",
"sha256:e6e73b9e02893c764e7e8d5bb5ce277f1a009cd5243f8228f75f842bf937c534",
"sha256:f73b96c41e3b2adedc34a7356e64c8eb96e03a3782b535e043a986276ce12a49",
"sha256:f93fd8e5c8c0a4aa1f424d6173f14a892044054871c771f8566e4008eaa359d2",
"sha256:fc33c5141b55ed366cfaad382df24fe7dcbc686de5be719b207bb248e3053dc5",
"sha256:fc7de24befaeae77ba923797c7c87834c73648a05a4bde34b3b7e5588973a453",
"sha256:fe562eb1a64e67dd297ccc4f5addea2501664954f2692b69a76449ec7913ecbf"
],
"markers": "python_full_version >= '3.9' and platform_python_implementation != 'PyPy'",
"version": "==2.0.0"
},
"charset-normalizer": {
"hashes": [
"sha256:027f6de494925c0ab2a55eab46ae5129951638a49a34d87f4c3eda90f696b4ad",
"sha256:077fbb858e903c73f6c9db43374fd213b0b6a778106bc7032446a8e8b5b38b93",
"sha256:0a98e6759f854bd25a58a73fa88833fba3b7c491169f86ce1180c948ab3fd394",
"sha256:0d3d8f15c07f86e9ff82319b3d9ef6f4bf907608f53fe9d92b28ea9ae3d1fd89",
"sha256:0f04b14ffe5fdc8c4933862d8306109a2c51e0704acfa35d51598eb45a1e89fc",
"sha256:11d694519d7f29d6cd09f6ac70028dba10f92f6cdd059096db198c283794ac86",
"sha256:194f08cbb32dc406d6e1aea671a68be0823673db2832b38405deba2fb0d88f63",
"sha256:1bee1e43c28aa63cb16e5c14e582580546b08e535299b8b6158a7c9c768a1f3d",
"sha256:21d142cc6c0ec30d2efee5068ca36c128a30b0f2c53c1c07bd78cb6bc1d3be5f",
"sha256:2437418e20515acec67d86e12bf70056a33abdacb5cb1655042f6538d6b085a8",
"sha256:244bfb999c71b35de57821b8ea746b24e863398194a4014e4c76adc2bbdfeff0",
"sha256:2677acec1a2f8ef614c6888b5b4ae4060cc184174a938ed4e8ef690e15d3e505",
"sha256:277e970e750505ed74c832b4bf75dac7476262ee2a013f5574dd49075879e161",
"sha256:2aaba3b0819274cc41757a1da876f810a3e4d7b6eb25699253a4effef9e8e4af",
"sha256:2b7d8f6c26245217bd2ad053761201e9f9680f8ce52f0fcd8d0755aeae5b2152",
"sha256:2c9d3c380143a1fedbff95a312aa798578371eb29da42106a29019368a475318",
"sha256:3162d5d8ce1bb98dd51af660f2121c55d0fa541b46dff7bb9b9f86ea1d87de72",
"sha256:31fd66405eaf47bb62e8cd575dc621c56c668f27d46a61d975a249930dd5e2a4",
"sha256:362d61fd13843997c1c446760ef36f240cf81d3ebf74ac62652aebaf7838561e",
"sha256:376bec83a63b8021bb5c8ea75e21c4ccb86e7e45ca4eb81146091b56599b80c3",
"sha256:44c2a8734b333e0578090c4cd6b16f275e07aa6614ca8715e6c038e865e70576",
"sha256:47cc91b2f4dd2833fddaedd2893006b0106129d4b94fdb6af1f4ce5a9965577c",
"sha256:4902828217069c3c5c71094537a8e623f5d097858ac6ca8252f7b4d10b7560f1",
"sha256:4bd5d4137d500351a30687c2d3971758aac9a19208fc110ccb9d7188fbe709e8",
"sha256:4fe7859a4e3e8457458e2ff592f15ccb02f3da787fcd31e0183879c3ad4692a1",
"sha256:542d2cee80be6f80247095cc36c418f7bddd14f4a6de45af91dfad36d817bba2",
"sha256:554af85e960429cf30784dd47447d5125aaa3b99a6f0683589dbd27e2f45da44",
"sha256:5833d2c39d8896e4e19b689ffc198f08ea58116bee26dea51e362ecc7cd3ed26",
"sha256:5947809c8a2417be3267efc979c47d76a079758166f7d43ef5ae8e9f92751f88",
"sha256:5ae497466c7901d54b639cf42d5b8c1b6a4fead55215500d2f486d34db48d016",
"sha256:5bd2293095d766545ec1a8f612559f6b40abc0eb18bb2f5d1171872d34036ede",
"sha256:5bfbb1b9acf3334612667b61bd3002196fe2a1eb4dd74d247e0f2a4d50ec9bbf",
"sha256:5cb4d72eea50c8868f5288b7f7f33ed276118325c1dfd3957089f6b519e1382a",
"sha256:5dbe56a36425d26d6cfb40ce79c314a2e4dd6211d51d6d2191c00bed34f354cc",
"sha256:5f819d5fe9234f9f82d75bdfa9aef3a3d72c4d24a6e57aeaebba32a704553aa0",
"sha256:64b55f9dce520635f018f907ff1b0df1fdc31f2795a922fb49dd14fbcdf48c84",
"sha256:6515f3182dbe4ea06ced2d9e8666d97b46ef4c75e326b79bb624110f122551db",
"sha256:65e2befcd84bc6f37095f5961e68a6f077bf44946771354a28ad434c2cce0ae1",
"sha256:6aee717dcfead04c6eb1ce3bd29ac1e22663cdea57f943c87d1eab9a025438d7",
"sha256:6b39f987ae8ccdf0d2642338faf2abb1862340facc796048b604ef14919e55ed",
"sha256:6e1fcf0720908f200cd21aa4e6750a48ff6ce4afe7ff5a79a90d5ed8a08296f8",
"sha256:74018750915ee7ad843a774364e13a3db91682f26142baddf775342c3f5b1133",
"sha256:74664978bb272435107de04e36db5a9735e78232b85b77d45cfb38f758efd33e",
"sha256:74bb723680f9f7a6234dcf67aea57e708ec1fbdf5699fb91dfd6f511b0a320ef",
"sha256:752944c7ffbfdd10c074dc58ec2d5a8a4cd9493b314d367c14d24c17684ddd14",
"sha256:778d2e08eda00f4256d7f672ca9fef386071c9202f5e4607920b86d7803387f2",
"sha256:780236ac706e66881f3b7f2f32dfe90507a09e67d1d454c762cf642e6e1586e0",
"sha256:798d75d81754988d2565bff1b97ba5a44411867c0cf32b77a7e8f8d84796b10d",
"sha256:799a7a5e4fb2d5898c60b640fd4981d6a25f1c11790935a44ce38c54e985f828",
"sha256:7a32c560861a02ff789ad905a2fe94e3f840803362c84fecf1851cb4cf3dc37f",
"sha256:7c308f7e26e4363d79df40ca5b2be1c6ba9f02bdbccfed5abddb7859a6ce72cf",
"sha256:7fa17817dc5625de8a027cb8b26d9fefa3ea28c8253929b8d6649e705d2835b6",
"sha256:81d5eb2a312700f4ecaa977a8235b634ce853200e828fbadf3a9c50bab278328",
"sha256:82004af6c302b5d3ab2cfc4cc5f29db16123b1a8417f2e25f9066f91d4411090",
"sha256:837c2ce8c5a65a2035be9b3569c684358dfbf109fd3b6969630a87535495ceaa",
"sha256:840c25fb618a231545cbab0564a799f101b63b9901f2569faecd6b222ac72381",
"sha256:8a6562c3700cce886c5be75ade4a5db4214fda19fede41d9792d100288d8f94c",
"sha256:8af65f14dc14a79b924524b1e7fffe304517b2bff5a58bf64f30b98bbc5079eb",
"sha256:8ef3c867360f88ac904fd3f5e1f902f13307af9052646963ee08ff4f131adafc",
"sha256:94537985111c35f28720e43603b8e7b43a6ecfb2ce1d3058bbe955b73404e21a",
"sha256:99ae2cffebb06e6c22bdc25801d7b30f503cc87dbd283479e7b606f70aff57ec",
"sha256:9a26f18905b8dd5d685d6d07b0cdf98a79f3c7a918906af7cc143ea2e164c8bc",
"sha256:9b35f4c90079ff2e2edc5b26c0c77925e5d2d255c42c74fdb70fb49b172726ac",
"sha256:9cd98cdc06614a2f768d2b7286d66805f94c48cde050acdbbb7db2600ab3197e",
"sha256:9d1bb833febdff5c8927f922386db610b49db6e0d4f4ee29601d71e7c2694313",
"sha256:9f7fcd74d410a36883701fafa2482a6af2ff5ba96b9a620e9e0721e28ead5569",
"sha256:a59cb51917aa591b1c4e6a43c132f0cdc3c76dbad6155df4e28ee626cc77a0a3",
"sha256:a61900df84c667873b292c3de315a786dd8dac506704dea57bc957bd31e22c7d",
"sha256:a79cfe37875f822425b89a82333404539ae63dbdddf97f84dcbc3d339aae9525",
"sha256:a8a8b89589086a25749f471e6a900d3f662d1d3b6e2e59dcecf787b1cc3a1894",
"sha256:a8bf8d0f749c5757af2142fe7903a9df1d2e8aa3841559b2bad34b08d0e2bcf3",
"sha256:a9768c477b9d7bd54bc0c86dbaebdec6f03306675526c9927c0e8a04e8f94af9",
"sha256:ac1c4a689edcc530fc9d9aa11f5774b9e2f33f9a0c6a57864e90908f5208d30a",
"sha256:af2d8c67d8e573d6de5bc30cdb27e9b95e49115cd9baad5ddbd1a6207aaa82a9",
"sha256:b435cba5f4f750aa6c0a0d92c541fb79f69a387c91e61f1795227e4ed9cece14",
"sha256:b5b290ccc2a263e8d185130284f8501e3e36c5e02750fc6b6bdeb2e9e96f1e25",
"sha256:b5d84d37db046c5ca74ee7bb47dd6cbc13f80665fdde3e8040bdd3fb015ecb50",
"sha256:b7cf1017d601aa35e6bb650b6ad28652c9cd78ee6caff19f3c28d03e1c80acbf",
"sha256:bc7637e2f80d8530ee4a78e878bce464f70087ce73cf7c1caf142416923b98f1",
"sha256:c0463276121fdee9c49b98908b3a89c39be45d86d1dbaa22957e38f6321d4ce3",
"sha256:c4ef880e27901b6cc782f1b95f82da9313c0eb95c3af699103088fa0ac3ce9ac",
"sha256:c8ae8a0f02f57a6e61203a31428fa1d677cbe50c93622b4149d5c0f319c1d19e",
"sha256:ca5862d5b3928c4940729dacc329aa9102900382fea192fc5e52eb69d6093815",
"sha256:cb01158d8b88ee68f15949894ccc6712278243d95f344770fa7593fa2d94410c",
"sha256:cb6254dc36b47a990e59e1068afacdcd02958bdcce30bb50cc1700a8b9d624a6",
"sha256:cc00f04ed596e9dc0da42ed17ac5e596c6ccba999ba6bd92b0e0aef2f170f2d6",
"sha256:cd09d08005f958f370f539f186d10aec3377d55b9eeb0d796025d4886119d76e",
"sha256:cd4b7ca9984e5e7985c12bc60a6f173f3c958eae74f3ef6624bb6b26e2abbae4",
"sha256:ce8a0633f41a967713a59c4139d29110c07e826d131a316b50ce11b1d79b4f84",
"sha256:cead0978fc57397645f12578bfd2d5ea9138ea0fac82b2f63f7f7c6877986a69",
"sha256:d055ec1e26e441f6187acf818b73564e6e6282709e9bcb5b63f5b23068356a15",
"sha256:d1f13550535ad8cff21b8d757a3257963e951d96e20ec82ab44bc64aeb62a191",
"sha256:d9c7f57c3d666a53421049053eaacdd14bbd0a528e2186fcb2e672effd053bb0",
"sha256:d9e45d7faa48ee908174d8fe84854479ef838fc6a705c9315372eacbc2f02897",
"sha256:da3326d9e65ef63a817ecbcc0df6e94463713b754fe293eaa03da99befb9a5bd",
"sha256:de00632ca48df9daf77a2c65a484531649261ec9f25489917f09e455cb09ddb2",
"sha256:e1f185f86a6f3403aa2420e815904c67b2f9ebc443f045edd0de921108345794",
"sha256:e824f1492727fa856dd6eda4f7cee25f8518a12f3c4a56a74e8095695089cf6d",
"sha256:e912091979546adf63357d7e2ccff9b44f026c075aeaf25a52d0e95ad2281074",
"sha256:eaabd426fe94daf8fd157c32e571c85cb12e66692f15516a83a03264b08d06c3",
"sha256:ebf3e58c7ec8a8bed6d66a75d7fb37b55e5015b03ceae72a8e7c74495551e224",
"sha256:ecaae4149d99b1c9e7b88bb03e3221956f68fd6d50be2ef061b2381b61d20838",
"sha256:eecbc200c7fd5ddb9a7f16c7decb07b566c29fa2161a16cf67b8d068bd21690a",
"sha256:f155a433c2ec037d4e8df17d18922c3a0d9b3232a396690f17175d2946f0218d",
"sha256:f1e34719c6ed0b92f418c7c780480b26b5d9c50349e9a9af7d76bf757530350d",
"sha256:f34be2938726fc13801220747472850852fe6b1ea75869a048d6f896838c896f",
"sha256:f820802628d2694cb7e56db99213f930856014862f3fd943d290ea8438d07ca8",
"sha256:f8bf04158c6b607d747e93949aa60618b61312fe647a6369f88ce2ff16043490",
"sha256:f8e160feb2aed042cd657a72acc0b481212ed28b1b9a95c0cee1621b524e1966",
"sha256:f9d332f8c2a2fcbffe1378594431458ddbef721c1769d78e2cbc06280d8155f9",
"sha256:fa09f53c465e532f4d3db095e0c55b615f010ad81803d383195b6b5ca6cbf5f3",
"sha256:faa3a41b2b66b6e50f84ae4a68c64fcd0c44355741c6374813a800cd6695db9e",
"sha256:fd44c878ea55ba351104cb93cc85e74916eb8fa440ca7903e57575e97394f608"
],
"markers": "python_version >= '3.7'",
"version": "==3.4.4"
},
"click": {
"hashes": [
"sha256:12ff4785d337a1bb490bb7e9c2b1ee5da3112e94a8622f26a6c77f5d2fc6842a",
"sha256:981153a64e25f12d547d3426c367a4857371575ee7ad18df2a6183ab0545b2a6"
],
"markers": "python_version >= '3.10'",
"version": "==8.3.1"
},
"cryptography": {
"hashes": [
"sha256:01df4f50f314fbe7009f54046e908d1754f19d0c6d3070df1e6268c5a4af09fa",
"sha256:0563655cb3c6d05fb2afe693340bc050c30f9f34e15763361cf08e94749401fc",
"sha256:078e5f06bd2fa5aea5a324f2a09f914b1484f1d0c2a4d6a8a28c74e72f65f2da",
"sha256:0a9ad24359fee86f131836a9ac3bffc9329e956624a2d379b613f8f8abaf5255",
"sha256:2067461c80271f422ee7bdbe79b9b4be54a5162e90345f86a23445a0cf3fd8a2",
"sha256:281526e865ed4166009e235afadf3a4c4cba6056f99336a99efba65336fd5485",
"sha256:2d08bc22efd73e8854b0b7caff402d735b354862f1145d7be3b9c0f740fef6a0",
"sha256:3c268a3490df22270955966ba236d6bc4a8f9b6e4ffddb78aac535f1a5ea471d",
"sha256:3d425eacbc9aceafd2cb429e42f4e5d5633c6f873f5e567077043ef1b9bbf616",
"sha256:44cc0675b27cadb71bdbb96099cca1fa051cd11d2ade09e5cd3a2edb929ed947",
"sha256:47bcd19517e6389132f76e2d5303ded6cf3f78903da2158a671be8de024f4cd0",
"sha256:485e2b65d25ec0d901bca7bcae0f53b00133bf3173916d8e421f6fddde103908",
"sha256:5aa3e463596b0087b3da0dbe2b2487e9fc261d25da85754e30e3b40637d61f81",
"sha256:5f14fba5bf6f4390d7ff8f086c566454bff0411f6d8aa7af79c88b6f9267aecc",
"sha256:62217ba44bf81b30abaeda1488686a04a702a261e26f87db51ff61d9d3510abd",
"sha256:6225d3ebe26a55dbc8ead5ad1265c0403552a63336499564675b29eb3184c09b",
"sha256:6bb5157bf6a350e5b28aee23beb2d84ae6f5be390b2f8ee7ea179cda077e1019",
"sha256:728fedc529efc1439eb6107b677f7f7558adab4553ef8669f0d02d42d7b959a7",
"sha256:766330cce7416c92b5e90c3bb71b1b79521760cdcfc3a6a1a182d4c9fab23d2b",
"sha256:812815182f6a0c1d49a37893a303b44eaac827d7f0d582cecfc81b6427f22973",
"sha256:829c2b12bbc5428ab02d6b7f7e9bbfd53e33efd6672d21341f2177470171ad8b",
"sha256:82a62483daf20b8134f6e92898da70d04d0ef9a75829d732ea1018678185f4f5",
"sha256:8a15fb869670efa8f83cbffbc8753c1abf236883225aed74cd179b720ac9ec80",
"sha256:8bf75b0259e87fa70bddc0b8b4078b76e7fd512fd9afae6c1193bcf440a4dbef",
"sha256:91627ebf691d1ea3976a031b61fb7bac1ccd745afa03602275dda443e11c8de0",
"sha256:93d8291da8d71024379ab2cb0b5c57915300155ad42e07f76bea6ad838d7e59b",
"sha256:9b34d8ba84454641a6bf4d6762d15847ecbd85c1316c0a7984e6e4e9f748ec2e",
"sha256:9b4d17bc7bd7cdd98e3af40b441feaea4c68225e2eb2341026c84511ad246c0c",
"sha256:9c2da296c8d3415b93e6053f5a728649a87a48ce084a9aaf51d6e46c87c7f2d2",
"sha256:a05177ff6296644ef2876fce50518dffb5bcdf903c85250974fc8bc85d54c0af",
"sha256:a90e43e3ef65e6dcf969dfe3bb40cbf5aef0d523dff95bfa24256be172a845f4",
"sha256:a9556ba711f7c23f77b151d5798f3ac44a13455cc68db7697a1096e6d0563cab",
"sha256:b1de0ebf7587f28f9190b9cb526e901bf448c9e6a99655d2b07fff60e8212a82",
"sha256:be8c01a7d5a55f9a47d1888162b76c8f49d62b234d88f0ff91a9fbebe32ffbc3",
"sha256:bfd019f60f8abc2ed1b9be4ddc21cfef059c841d86d710bb69909a688cbb8f59",
"sha256:c236a44acfb610e70f6b3e1c3ca20ff24459659231ef2f8c48e879e2d32b73da",
"sha256:c411f16275b0dea722d76544a61d6421e2cc829ad76eec79280dbdc9ddf50061",
"sha256:c92010b58a51196a5f41c3795190203ac52edfd5dc3ff99149b4659eba9d2085",
"sha256:d5a45ddc256f492ce42a4e35879c5e5528c09cd9ad12420828c972951d8e016b",
"sha256:daa392191f626d50f1b136c9b4cf08af69ca8279d110ea24f5c2700054d2e263",
"sha256:dc1272e25ef673efe72f2096e92ae39dea1a1a450dd44918b15351f72c5a168e",
"sha256:dce1e4f068f03008da7fa51cc7abc6ddc5e5de3e3d1550334eaf8393982a5829",
"sha256:dd5aba870a2c40f87a3af043e0dee7d9eb02d4aff88a797b48f2b43eff8c3ab4",
"sha256:de0f5f4ec8711ebc555f54735d4c673fc34b65c44283895f1a08c2b49d2fd99c",
"sha256:df4a817fa7138dd0c96c8c8c20f04b8aaa1fac3bbf610913dcad8ea82e1bfd3f",
"sha256:e07ea39c5b048e085f15923511d8121e4a9dc45cee4e3b970ca4f0d338f23095",
"sha256:eeeb2e33d8dbcccc34d64651f00a98cb41b2dc69cef866771a5717e6734dfa32",
"sha256:fa0900b9ef9c49728887d1576fd8d9e7e3ea872fa9b25ef9b64888adc434e976",
"sha256:fdc3daab53b212472f1524d070735b2f0c214239df131903bae1d598016fa822"
],
"markers": "python_version >= '3.8' and python_full_version not in '3.9.0, 3.9.1'",
"version": "==46.0.4"
},
"esptool": {
"hashes": [
"sha256:2ea9bcd7eb263d380a4fe0170856a10e4c65e3f38c757ebdc73584c8dd8322da"
],
"index": "pypi",
"markers": "python_version >= '3.10'",
"version": "==5.1.0"
},
"h11": {
"hashes": [
"sha256:4e35b956cf45792e4caa5885e69fba00bdbc6ffafbfa020300e549b208ee5ff1",
"sha256:63cf8bbe7522de3bf65932fda1d9c2772064ffb3dae62d55932da54b31cb6c86"
],
"markers": "python_version >= '3.8'",
"version": "==0.16.0"
},
"idna": {
"hashes": [
"sha256:771a87f49d9defaf64091e6e6fe9c18d4833f140bd19464795bc32d966ca37ea",
"sha256:795dafcc9c04ed0c1fb032c2aa73654d8e8c5023a7df64a53f39190ada629902"
],
"markers": "python_version >= '3.8'",
"version": "==3.11"
},
"importlib-metadata": {
"hashes": [
"sha256:49fef1ae6440c182052f407c8d34a68f72efc36db9ca90dc0113398f2fdde8bb",
"sha256:5a1f80bf1daa489495071efbb095d75a634cf28a8bc299581244063b53176151"
],
"markers": "python_version >= '3.9'",
"version": "==8.7.1"
},
"intelhex": {
"hashes": [
"sha256:87cc5225657524ec6361354be928adfd56bcf2a3dcc646c40f8f094c39c07db4",
"sha256:892b7361a719f4945237da8ccf754e9513db32f5628852785aea108dcd250093"
],
"version": "==2.3.0"
},
"markdown-it-py": {
"hashes": [
"sha256:87327c59b172c5011896038353a81343b6754500a08cd7a4973bb48c6d578147",
"sha256:cb0a2b4aa34f932c007117b194e945bd74e0ec24133ceb5bac59009cda1cb9f3"
],
"markers": "python_version >= '3.10'",
"version": "==4.0.0"
},
"mdurl": {
"hashes": [
"sha256:84008a41e51615a49fc9966191ff91509e3c40b939176e643fd50a5c2196b8f8",
"sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba"
],
"markers": "python_version >= '3.7'",
"version": "==0.1.2"
},
"mpremote": {
"hashes": [
"sha256:11d134c69b21b487dae3d03eed54c8ccbf84c916c8732a3e069a97cae47be3d4",
"sha256:6bb75774648091dad6833af4f86c5bf6505f8d7aec211380f9e6996c01d23cb5"
],
"index": "pypi",
"markers": "python_version >= '3.4'",
"version": "==1.27.0"
},
"mypy-extensions": {
"hashes": [
"sha256:1be4cccdb0f2482337c4743e60421de3a356cd97508abadd57d47403e94f5505",
"sha256:52e68efc3284861e772bbcd66823fde5ae21fd2fdb51c62a211403730b916558"
],
"markers": "python_version >= '3.8'",
"version": "==1.1.0"
},
"outcome": {
"hashes": [
"sha256:9dcf02e65f2971b80047b377468e72a268e15c0af3cf1238e6ff14f7f91143b8",
"sha256:e771c5ce06d1415e356078d3bdd68523f284b4ce5419828922b6871e65eda82b"
],
"markers": "python_version >= '3.7'",
"version": "==1.3.0.post0"
},
"packaging": {
"hashes": [
"sha256:00243ae351a257117b6a241061796684b084ed1c516a08c48a3f7e147a9d80b4",
"sha256:b36f1fef9334a5588b4166f8bcd26a14e521f2b55e6b9de3aaa80d3ff7a37529"
],
"markers": "python_version >= '3.8'",
"version": "==26.0"
},
"platformdirs": {
"hashes": [
"sha256:61d5cdcc6065745cdd94f0f878977f8de9437be93de97c1c12f853c9c0cdcbda",
"sha256:d03afa3963c806a9bed9d5125c8f4cb2fdaf74a55ab60e5d59b3fde758104d31"
],
"markers": "python_version >= '3.10'",
"version": "==4.5.1"
},
"pycparser": {
"hashes": [
"sha256:600f49d217304a5902ac3c37e1281c9fe94e4d0489de643a9504c5cdfdfc6b29",
"sha256:b727414169a36b7d524c1c3e31839a521725078d7b2ff038656844266160a992"
],
"markers": "implementation_name != 'PyPy'",
"version": "==3.0"
},
"pygments": {
"hashes": [
"sha256:636cb2477cec7f8952536970bc533bc43743542f70392ae026374600add5b887",
"sha256:86540386c03d588bb81d44bc3928634ff26449851e99741617ecb9037ee5ec0b"
],
"markers": "python_version >= '3.8'",
"version": "==2.19.2"
},
"pyjwt": {
"hashes": [
"sha256:35f95c1f0fbe5d5ba6e43f00271c275f7a1a4db1dab27bf708073b75318ea623",
"sha256:94a6bde30eb5c8e04fee991062b534071fd1439ef58d2adc9ccb823e7bcd0469"
],
"index": "pypi",
"markers": "python_version >= '3.9'",
"version": "==2.11.0"
},
"pyserial": {
"hashes": [
"sha256:3c77e014170dfffbd816e6ffc205e9842efb10be9f58ec16d3e8675b4925cddb",
"sha256:c4451db6ba391ca6ca299fb3ec7bae67a5c55dde170964c7a14ceefec02f2cf0"
],
"index": "pypi",
"version": "==3.5"
},
"pysocks": {
"hashes": [
"sha256:08e69f092cc6dbe92a0fdd16eeb9b9ffbc13cadfe5ca4c7bd92ffb078b293299",
"sha256:2725bd0a9925919b9b51739eea5f9e2bae91e83288108a9ad338b2e3a4435ee5",
"sha256:3f8804571ebe159c380ac6de37643bb4685970655d3bba243530d6558b799aa0"
],
"version": "==1.7.1"
},
"python-dotenv": {
"hashes": [
"sha256:42667e897e16ab0d66954af0e60a9caa94f0fd4ecf3aaf6d2d260eec1aa36ad6",
"sha256:b81ee9561e9ca4004139c6cbba3a238c32b03e4894671e181b671e8cb8425d61"
],
"markers": "python_version >= '3.9'",
"version": "==1.2.1"
},
"pyyaml": {
"hashes": [
"sha256:00c4bdeba853cc34e7dd471f16b4114f4162dc03e6b7afcc2128711f0eca823c",
"sha256:0150219816b6a1fa26fb4699fb7daa9caf09eb1999f3b70fb6e786805e80375a",
"sha256:02893d100e99e03eda1c8fd5c441d8c60103fd175728e23e431db1b589cf5ab3",
"sha256:02ea2dfa234451bbb8772601d7b8e426c2bfa197136796224e50e35a78777956",
"sha256:0f29edc409a6392443abf94b9cf89ce99889a1dd5376d94316ae5145dfedd5d6",
"sha256:10892704fc220243f5305762e276552a0395f7beb4dbf9b14ec8fd43b57f126c",
"sha256:16249ee61e95f858e83976573de0f5b2893b3677ba71c9dd36b9cf8be9ac6d65",
"sha256:1d37d57ad971609cf3c53ba6a7e365e40660e3be0e5175fa9f2365a379d6095a",
"sha256:1ebe39cb5fc479422b83de611d14e2c0d3bb2a18bbcb01f229ab3cfbd8fee7a0",
"sha256:214ed4befebe12df36bcc8bc2b64b396ca31be9304b8f59e25c11cf94a4c033b",
"sha256:2283a07e2c21a2aa78d9c4442724ec1eb15f5e42a723b99cb3d822d48f5f7ad1",
"sha256:22ba7cfcad58ef3ecddc7ed1db3409af68d023b7f940da23c6c2a1890976eda6",
"sha256:27c0abcb4a5dac13684a37f76e701e054692a9b2d3064b70f5e4eb54810553d7",
"sha256:28c8d926f98f432f88adc23edf2e6d4921ac26fb084b028c733d01868d19007e",
"sha256:2e71d11abed7344e42a8849600193d15b6def118602c4c176f748e4583246007",
"sha256:34d5fcd24b8445fadc33f9cf348c1047101756fd760b4dacb5c3e99755703310",
"sha256:37503bfbfc9d2c40b344d06b2199cf0e96e97957ab1c1b546fd4f87e53e5d3e4",
"sha256:3c5677e12444c15717b902a5798264fa7909e41153cdf9ef7ad571b704a63dd9",
"sha256:3ff07ec89bae51176c0549bc4c63aa6202991da2d9a6129d7aef7f1407d3f295",
"sha256:41715c910c881bc081f1e8872880d3c650acf13dfa8214bad49ed4cede7c34ea",
"sha256:418cf3f2111bc80e0933b2cd8cd04f286338bb88bdc7bc8e6dd775ebde60b5e0",
"sha256:44edc647873928551a01e7a563d7452ccdebee747728c1080d881d68af7b997e",
"sha256:4a2e8cebe2ff6ab7d1050ecd59c25d4c8bd7e6f400f5f82b96557ac0abafd0ac",
"sha256:4ad1906908f2f5ae4e5a8ddfce73c320c2a1429ec52eafd27138b7f1cbe341c9",
"sha256:501a031947e3a9025ed4405a168e6ef5ae3126c59f90ce0cd6f2bfc477be31b7",
"sha256:5190d403f121660ce8d1d2c1bb2ef1bd05b5f68533fc5c2ea899bd15f4399b35",
"sha256:5498cd1645aa724a7c71c8f378eb29ebe23da2fc0d7a08071d89469bf1d2defb",
"sha256:5cf4e27da7e3fbed4d6c3d8e797387aaad68102272f8f9752883bc32d61cb87b",
"sha256:5e0b74767e5f8c593e8c9b5912019159ed0533c70051e9cce3e8b6aa699fcd69",
"sha256:5ed875a24292240029e4483f9d4a4b8a1ae08843b9c54f43fcc11e404532a8a5",
"sha256:5fcd34e47f6e0b794d17de1b4ff496c00986e1c83f7ab2fb8fcfe9616ff7477b",
"sha256:5fdec68f91a0c6739b380c83b951e2c72ac0197ace422360e6d5a959d8d97b2c",
"sha256:6344df0d5755a2c9a276d4473ae6b90647e216ab4757f8426893b5dd2ac3f369",
"sha256:64386e5e707d03a7e172c0701abfb7e10f0fb753ee1d773128192742712a98fd",
"sha256:652cb6edd41e718550aad172851962662ff2681490a8a711af6a4d288dd96824",
"sha256:66291b10affd76d76f54fad28e22e51719ef9ba22b29e1d7d03d6777a9174198",
"sha256:66e1674c3ef6f541c35191caae2d429b967b99e02040f5ba928632d9a7f0f065",
"sha256:6adc77889b628398debc7b65c073bcb99c4a0237b248cacaf3fe8a557563ef6c",
"sha256:79005a0d97d5ddabfeeea4cf676af11e647e41d81c9a7722a193022accdb6b7c",
"sha256:7c6610def4f163542a622a73fb39f534f8c101d690126992300bf3207eab9764",
"sha256:7f047e29dcae44602496db43be01ad42fc6f1cc0d8cd6c83d342306c32270196",
"sha256:8098f252adfa6c80ab48096053f512f2321f0b998f98150cea9bd23d83e1467b",
"sha256:850774a7879607d3a6f50d36d04f00ee69e7fc816450e5f7e58d7f17f1ae5c00",
"sha256:8d1fab6bb153a416f9aeb4b8763bc0f22a5586065f86f7664fc23339fc1c1fac",
"sha256:8da9669d359f02c0b91ccc01cac4a67f16afec0dac22c2ad09f46bee0697eba8",
"sha256:8dc52c23056b9ddd46818a57b78404882310fb473d63f17b07d5c40421e47f8e",
"sha256:9149cad251584d5fb4981be1ecde53a1ca46c891a79788c0df828d2f166bda28",
"sha256:93dda82c9c22deb0a405ea4dc5f2d0cda384168e466364dec6255b293923b2f3",
"sha256:96b533f0e99f6579b3d4d4995707cf36df9100d67e0c8303a0c55b27b5f99bc5",
"sha256:9c57bb8c96f6d1808c030b1687b9b5fb476abaa47f0db9c0101f5e9f394e97f4",
"sha256:9c7708761fccb9397fe64bbc0395abcae8c4bf7b0eac081e12b809bf47700d0b",
"sha256:9f3bfb4965eb874431221a3ff3fdcddc7e74e3b07799e0e84ca4a0f867d449bf",
"sha256:a33284e20b78bd4a18c8c2282d549d10bc8408a2a7ff57653c0cf0b9be0afce5",
"sha256:a80cb027f6b349846a3bf6d73b5e95e782175e52f22108cfa17876aaeff93702",
"sha256:b30236e45cf30d2b8e7b3e85881719e98507abed1011bf463a8fa23e9c3e98a8",
"sha256:b3bc83488de33889877a0f2543ade9f70c67d66d9ebb4ac959502e12de895788",
"sha256:b865addae83924361678b652338317d1bd7e79b1f4596f96b96c77a5a34b34da",
"sha256:b8bb0864c5a28024fac8a632c443c87c5aa6f215c0b126c449ae1a150412f31d",
"sha256:ba1cc08a7ccde2d2ec775841541641e4548226580ab850948cbfda66a1befcdc",
"sha256:bdb2c67c6c1390b63c6ff89f210c8fd09d9a1217a465701eac7316313c915e4c",
"sha256:c1ff362665ae507275af2853520967820d9124984e0f7466736aea23d8611fba",
"sha256:c2514fceb77bc5e7a2f7adfaa1feb2fb311607c9cb518dbc378688ec73d8292f",
"sha256:c3355370a2c156cffb25e876646f149d5d68f5e0a3ce86a5084dd0b64a994917",
"sha256:c458b6d084f9b935061bc36216e8a69a7e293a2f1e68bf956dcd9e6cbcd143f5",
"sha256:d0eae10f8159e8fdad514efdc92d74fd8d682c933a6dd088030f3834bc8e6b26",
"sha256:d76623373421df22fb4cf8817020cbb7ef15c725b9d5e45f17e189bfc384190f",
"sha256:ebc55a14a21cb14062aa4162f906cd962b28e2e9ea38f9b4391244cd8de4ae0b",
"sha256:eda16858a3cab07b80edaf74336ece1f986ba330fdb8ee0d6c0d68fe82bc96be",
"sha256:ee2922902c45ae8ccada2c5b501ab86c36525b883eff4255313a253a3160861c",
"sha256:efd7b85f94a6f21e4932043973a7ba2613b059c4a000551892ac9f1d11f5baf3",
"sha256:f7057c9a337546edc7973c0d3ba84ddcdf0daa14533c2065749c9075001090e6",
"sha256:fa160448684b4e94d80416c0fa4aac48967a969efe22931448d853ada8baf926",
"sha256:fc09d0aa354569bc501d4e787133afc08552722d3ab34836a80547331bb5d4a0"
],
"markers": "python_version >= '3.8'",
"version": "==6.0.3"
},
"reedsolo": {
"hashes": [
"sha256:2b6a3e402a1ee3e1eea3f932f81e6c0b7bbc615588074dca1dbbcdeb055002bd",
"sha256:c1359f02742751afe0f1c0de9f0772cc113835aa2855d2db420ea24393c87732"
],
"version": "==1.7.0"
},
"requests": {
"hashes": [
"sha256:2462f94637a34fd532264295e186976db0f5d453d1cdd31473c85a6a161affb6",
"sha256:dbba0bac56e100853db0ea71b82b4dfd5fe2bf6d3754a8893c3af500cec7d7cf"
],
"index": "pypi",
"markers": "python_version >= '3.9'",
"version": "==2.32.5"
},
"rich": {
"hashes": [
"sha256:08e67c3e90884651da3239ea668222d19bea7b589149d8014a21c633420dbb69",
"sha256:e712f11c1a562a11843306f5ed999475f09ac31ffb64281f73ab29ffdda8b3b8"
],
"markers": "python_full_version >= '3.8.0'",
"version": "==14.3.2"
},
"rich-click": {
"hashes": [
"sha256:022997c1e30731995bdbc8ec2f82819340d42543237f033a003c7b1f843fc5dc",
"sha256:2f99120fca78f536e07b114d3b60333bc4bb2a0969053b1250869bcdc1b5351b"
],
"markers": "python_version >= '3.8'",
"version": "==1.9.7"
},
"selenium": {
"hashes": [
"sha256:a88f5905d88ad0b84991c2386ea39e2bbde6d6c334be38df5842318ba98eaa8c",
"sha256:c8823fc02e2c771d9ad9a0cf899cee7de1a57a6697e3d0b91f67566129f2b729"
],
"index": "pypi",
"markers": "python_version >= '3.10'",
"version": "==4.40.0"
},
"sniffio": {
"hashes": [
"sha256:2f6da418d1f1e0fddd844478f41680e794e6051915791a034ff65e5f100525a2",
"sha256:f4324edc670a0f49750a81b895f35c3adb843cca46f0530f79fc1babb23789dc"
],
"markers": "python_version >= '3.7'",
"version": "==1.3.1"
},
"sortedcontainers": {
"hashes": [
"sha256:25caa5a06cc30b6b83d11423433f65d1f9d76c4c6a0c90e3379eaa43b9bfdb88",
"sha256:a163dcaede0f1c021485e957a39245190e74249897e2ae4b2aa38595db237ee0"
],
"version": "==2.4.0"
},
"trio": {
"hashes": [
"sha256:150f29ec923bcd51231e1d4c71c7006e65247d68759dd1c19af4ea815a25806b",
"sha256:4ab65984ef8370b79a76659ec87aa3a30c5c7c83ff250b4de88c29a8ab6123c5"
],
"markers": "python_version >= '3.10'",
"version": "==0.32.0"
},
"trio-typing": {
"hashes": [
"sha256:065ee684296d52a8ab0e2374666301aec36ee5747ac0e7a61f230250f8907ac3",
"sha256:6d0e7ec9d837a2fe03591031a172533fbf4a1a95baf369edebfc51d5a49f0264"
],
"version": "==0.10.0"
},
"trio-websocket": {
"hashes": [
"sha256:22c72c436f3d1e264d0910a3951934798dcc5b00ae56fc4ee079d46c7cf20fae",
"sha256:df605665f1db533f4a386c94525870851096a223adcb97f72a07e8b4beba45b6"
],
"markers": "python_version >= '3.8'",
"version": "==0.12.2"
},
"types-certifi": {
"hashes": [
"sha256:72cf7798d165bc0b76e1c10dd1ea3097c7063c42c21d664523b928e88b554a4f",
"sha256:b2d1e325e69f71f7c78e5943d410e650b4707bb0ef32e4ddf3da37f54176e88a"
],
"version": "==2021.10.8.3"
},
"types-urllib3": {
"hashes": [
"sha256:229b7f577c951b8c1b92c1bc2b2fdb0b49847bd2af6d1cc2a2e3dd340f3bda8f",
"sha256:9683bbb7fb72e32bfe9d2be6e04875fbe1b3eeec3cbb4ea231435aa7fd6b4f0e"
],
"version": "==1.26.25.14"
},
"typing-extensions": {
"hashes": [
"sha256:0cea48d173cc12fa28ecabc3b837ea3cf6f38c6d1136f85cbaaf598984861466",
"sha256:f0fa19c6845758ab08074a0cfa8b7aecb71c999ca73d62883bc25cc018c4e548"
],
"markers": "python_version >= '3.9'",
"version": "==4.15.0"
},
"urllib3": {
"extras": [
"socks"
],
"hashes": [
"sha256:1b62b6884944a57dbe321509ab94fd4d3b307075e0c2eae991ac71ee15ad38ed",
"sha256:bf272323e553dfb2e87d9bfd225ca7b0f467b919d7bbd355436d3fd37cb0acd4"
],
"markers": "python_version >= '3.9'",
"version": "==2.6.3"
},
"watchfiles": {
"hashes": [
"sha256:00485f441d183717038ed2e887a7c868154f216877653121068107b227a2f64c",
"sha256:03fa0f5237118a0c5e496185cafa92878568b652a2e9a9382a5151b1a0380a43",
"sha256:04e78dd0b6352db95507fd8cb46f39d185cf8c74e4cf1e4fbad1d3df96faf510",
"sha256:059098c3a429f62fc98e8ec62b982230ef2c8df68c79e826e37b895bc359a9c0",
"sha256:08af70fd77eee58549cd69c25055dc344f918d992ff626068242259f98d598a2",
"sha256:0b495de0bb386df6a12b18335a0285dda90260f51bdb505503c02bcd1ce27a8b",
"sha256:130e4876309e8686a5e37dba7d5e9bc77e6ed908266996ca26572437a5271e18",
"sha256:14e0b1fe858430fc0251737ef3824c54027bedb8c37c38114488b8e131cf8219",
"sha256:17ef139237dfced9da49fb7f2232c86ca9421f666d78c264c7ffca6601d154c3",
"sha256:1a0bb430adb19ef49389e1ad368450193a90038b5b752f4ac089ec6942c4dff4",
"sha256:1db5d7ae38ff20153d542460752ff397fcf5c96090c1230803713cf3147a6803",
"sha256:28475ddbde92df1874b6c5c8aaeb24ad5be47a11f87cde5a28ef3835932e3e94",
"sha256:2edc3553362b1c38d9f06242416a5d8e9fe235c204a4072e988ce2e5bb1f69f6",
"sha256:30f7da3fb3f2844259cba4720c3fc7138eb0f7b659c38f3bfa65084c7fc7abce",
"sha256:311ff15a0bae3714ffb603e6ba6dbfba4065ab60865d15a6ec544133bdb21099",
"sha256:319b27255aacd9923b8a276bb14d21a5f7ff82564c744235fc5eae58d95422ae",
"sha256:35c53bd62a0b885bf653ebf6b700d1bf05debb78ad9292cf2a942b23513dc4c4",
"sha256:36193ed342f5b9842edd3532729a2ad55c4160ffcfa3700e0d54be496b70dd43",
"sha256:39574d6370c4579d7f5d0ad940ce5b20db0e4117444e39b6d8f99db5676c52fd",
"sha256:399600947b170270e80134ac854e21b3ccdefa11a9529a3decc1327088180f10",
"sha256:3a476189be23c3686bc2f4321dd501cb329c0a0469e77b7b534ee10129ae6374",
"sha256:3ad9fe1dae4ab4212d8c91e80b832425e24f421703b5a42ef2e4a1e215aff051",
"sha256:3bc570d6c01c206c46deb6e935a260be44f186a2f05179f52f7fcd2be086a94d",
"sha256:3dbd8cbadd46984f802f6d479b7e3afa86c42d13e8f0f322d669d79722c8ec34",
"sha256:3e6f39af2eab0118338902798b5aa6664f46ff66bc0280de76fca67a7f262a49",
"sha256:3f53fa183d53a1d7a8852277c92b967ae99c2d4dcee2bfacff8868e6e30b15f7",
"sha256:3f6d37644155fb5beca5378feb8c1708d5783145f2a0f1c4d5a061a210254844",
"sha256:3f7eb7da0eb23aa2ba036d4f616d46906013a68caf61b7fdbe42fc8b25132e77",
"sha256:3fa0b59c92278b5a7800d3ee7733da9d096d4aabcfabb9a928918bd276ef9b9b",
"sha256:421e29339983e1bebc281fab40d812742268ad057db4aee8c4d2bce0af43b741",
"sha256:4b943d3668d61cfa528eb949577479d3b077fd25fb83c641235437bc0b5bc60e",
"sha256:526e86aced14a65a5b0ec50827c745597c782ff46b571dbfe46192ab9e0b3c33",
"sha256:52e06553899e11e8074503c8e716d574adeeb7e68913115c4b3653c53f9bae42",
"sha256:544364b2b51a9b0c7000a4b4b02f90e9423d97fbbf7e06689236443ebcad81ab",
"sha256:5524298e3827105b61951a29c3512deb9578586abf3a7c5da4a8069df247cccc",
"sha256:55c7475190662e202c08c6c0f4d9e345a29367438cf8e8037f3155e10a88d5a5",
"sha256:563b116874a9a7ce6f96f87cd0b94f7faf92d08d0021e837796f0a14318ef8da",
"sha256:57ca5281a8b5e27593cb7d82c2ac927ad88a96ed406aa446f6344e4328208e9e",
"sha256:5c85794a4cfa094714fb9c08d4a218375b2b95b8ed1666e8677c349906246c05",
"sha256:5f3bde70f157f84ece3765b42b4a52c6ac1a50334903c6eaf765362f6ccca88a",
"sha256:5f3f58818dc0b07f7d9aa7fe9eb1037aecb9700e63e1f6acfed13e9fef648f5d",
"sha256:5fac835b4ab3c6487b5dbad78c4b3724e26bcc468e886f8ba8cc4306f68f6701",
"sha256:620bae625f4cb18427b1bb1a2d9426dc0dd5a5ba74c7c2cdb9de405f7b129863",
"sha256:672b8adf25b1a0d35c96b5888b7b18699d27d4194bac8beeae75be4b7a3fc9b2",
"sha256:6aae418a8b323732fa89721d86f39ec8f092fc2af67f4217a2b07fd3e93c6101",
"sha256:6c3631058c37e4a0ec440bf583bc53cdbd13e5661bb6f465bc1d88ee9a0a4d02",
"sha256:6c9c9262f454d1c4d8aaa7050121eb4f3aea197360553699520767daebf2180b",
"sha256:6e43d39a741e972bab5d8100b5cdacf69db64e34eb19b6e9af162bccf63c5cc6",
"sha256:7365b92c2e69ee952902e8f70f3ba6360d0d596d9299d55d7d386df84b6941fb",
"sha256:743185e7372b7bc7c389e1badcc606931a827112fbbd37f14c537320fca08620",
"sha256:74472234c8370669850e1c312490f6026d132ca2d396abfad8830b4f1c096957",
"sha256:74d5012b7630714b66be7b7b7a78855ef7ad58e8650c73afc4c076a1f480a8d6",
"sha256:77a13aea58bc2b90173bc69f2a90de8e282648939a00a602e1dc4ee23e26b66d",
"sha256:79ff6c6eadf2e3fc0d7786331362e6ef1e51125892c75f1004bd6b52155fb956",
"sha256:831a62658609f0e5c64178211c942ace999517f5770fe9436be4c2faeba0c0ef",
"sha256:836398932192dae4146c8f6f737d74baeac8b70ce14831a239bdb1ca882fc261",
"sha256:842178b126593addc05acf6fce960d28bc5fae7afbaa2c6c1b3a7b9460e5be02",
"sha256:8526e8f916bb5b9a0a777c8317c23ce65de259422bba5b31325a6fa6029d33af",
"sha256:859e43a1951717cc8de7f4c77674a6d389b106361585951d9e69572823f311d9",
"sha256:88863fbbc1a7312972f1c511f202eb30866370ebb8493aef2812b9ff28156a21",
"sha256:89eef07eee5e9d1fda06e38822ad167a044153457e6fd997f8a858ab7564a336",
"sha256:8c89f9f2f740a6b7dcc753140dd5e1ab9215966f7a3530d0c0705c83b401bd7d",
"sha256:8c91ed27800188c2ae96d16e3149f199d62f86c7af5f5f4d2c61a3ed8cd3666c",
"sha256:8ca65483439f9c791897f7db49202301deb6e15fe9f8fe2fed555bf986d10c31",
"sha256:8fbe85cb3201c7d380d3d0b90e63d520f15d6afe217165d7f98c9c649654db81",
"sha256:91d4c9a823a8c987cce8fa2690923b069966dabb196dd8d137ea2cede885fde9",
"sha256:9bb9f66367023ae783551042d31b1d7fd422e8289eedd91f26754a66f44d5cff",
"sha256:a173cb5c16c4f40ab19cecf48a534c409f7ea983ab8fed0741304a1c0a31b3f2",
"sha256:a36d8efe0f290835fd0f33da35042a1bb5dc0e83cbc092dcf69bce442579e88e",
"sha256:a55f3e9e493158d7bfdb60a1165035f1cf7d320914e7b7ea83fe22c6023b58fc",
"sha256:a625815d4a2bdca61953dbba5a39d60164451ef34c88d751f6c368c3ea73d404",
"sha256:a916a2932da8f8ab582f242c065f5c81bed3462849ca79ee357dd9551b0e9b01",
"sha256:ac3cc5759570cd02662b15fbcd9d917f7ecd47efe0d6b40474eafd246f91ea18",
"sha256:acb08650863767cbc58bca4813b92df4d6c648459dcaa3d4155681962b2aa2d3",
"sha256:aebfd0861a83e6c3d1110b78ad54704486555246e542be3e2bb94195eabb2606",
"sha256:afaeff7696e0ad9f02cbb8f56365ff4686ab205fcf9c4c5b6fdfaaa16549dd04",
"sha256:b27cf2eb1dda37b2089e3907d8ea92922b673c0c427886d4edc6b94d8dfe5db3",
"sha256:b2cd9e04277e756a2e2d2543d65d1e2166d6fd4c9b183f8808634fda23f17b14",
"sha256:b9c4702f29ca48e023ffd9b7ff6b822acdf47cb1ff44cb490a3f1d5ec8987e9c",
"sha256:bbe1ef33d45bc71cf21364df962af171f96ecaeca06bd9e3d0b583efb12aec82",
"sha256:bd404be08018c37350f0d6e34676bd1e2889990117a2b90070b3007f172d0610",
"sha256:bf0a91bfb5574a2f7fc223cf95eeea79abfefa404bf1ea5e339c0c1560ae99a0",
"sha256:bfb5862016acc9b869bb57284e6cb35fdf8e22fe59f7548858e2f971d045f150",
"sha256:bfff9740c69c0e4ed32416f013f3c45e2ae42ccedd1167ef2d805c000b6c71a5",
"sha256:c1f5210f1b8fc91ead1283c6fd89f70e76fb07283ec738056cf34d51e9c1d62c",
"sha256:c2047d0b6cea13b3316bdbafbfa0c4228ae593d995030fda39089d36e64fc03a",
"sha256:c22c776292a23bfc7237a98f791b9ad3144b02116ff10d820829ce62dff46d0b",
"sha256:c755367e51db90e75b19454b680903631d41f9e3607fbd941d296a020c2d752d",
"sha256:c882d69f6903ef6092bedfb7be973d9319940d56b8427ab9187d1ecd73438a70",
"sha256:cb467c999c2eff23a6417e58d75e5828716f42ed8289fe6b77a7e5a91036ca70",
"sha256:cdab464fee731e0884c35ae3588514a9bcf718d0e2c82169c1c4a85cc19c3c7f",
"sha256:ce19e06cbda693e9e7686358af9cd6f5d61312ab8b00488bc36f5aabbaf77e24",
"sha256:ce70f96a46b894b36eba678f153f052967a0d06d5b5a19b336ab0dbbd029f73e",
"sha256:cf57a27fb986c6243d2ee78392c503826056ffe0287e8794503b10fb51b881be",
"sha256:d1715143123baeeaeadec0528bb7441103979a1d5f6fd0e1f915383fea7ea6d5",
"sha256:d6ff426a7cb54f310d51bfe83fe9f2bbe40d540c741dc974ebc30e6aa238f52e",
"sha256:d7e7067c98040d646982daa1f37a33d3544138ea155536c2e0e63e07ff8a7e0f",
"sha256:db476ab59b6765134de1d4fe96a1a9c96ddf091683599be0f26147ea1b2e4b88",
"sha256:dcc5c24523771db3a294c77d94771abcfcb82a0e0ee8efd910c37c59ec1b31bb",
"sha256:de6da501c883f58ad50db3a32ad397b09ad29865b5f26f64c24d3e3281685849",
"sha256:e84087b432b6ac94778de547e08611266f1f8ffad28c0ee4c82e028b0fc5966d",
"sha256:eef58232d32daf2ac67f42dea51a2c80f0d03379075d44a587051e63cc2e368c",
"sha256:f096076119da54a6080e8920cbdaac3dbee667eb91dcc5e5b78840b87415bd44",
"sha256:f0ab1c1af0cb38e3f598244c17919fb1a84d1629cc08355b0074b6d7f53138ac",
"sha256:f27db948078f3823a6bb3b465180db8ebecf26dd5dae6f6180bd87383b6b4428",
"sha256:f537afb3276d12814082a2e9b242bdcf416c2e8fd9f799a737990a1dbe906e5b",
"sha256:f57b396167a2565a4e8b5e56a5a1c537571733992b226f4f1197d79e94cf0ae5",
"sha256:f8979280bdafff686ba5e4d8f97840f929a87ed9cdf133cbbd42f7766774d2aa",
"sha256:f9a2ae5c91cecc9edd47e041a930490c31c3afb1f5e6d71de3dc671bfaca02bf"
],
"index": "pypi",
"markers": "python_version >= '3.9'",
"version": "==1.1.1"
},
"websocket-client": {
"hashes": [
"sha256:9e813624b6eb619999a97dc7958469217c3176312b3a16a4bd1bc7e08a46ec98",
"sha256:af248a825037ef591efbf6ed20cc5faa03d3b47b9e5a2230a529eeee1c1fc3ef"
],
"markers": "python_version >= '3.9'",
"version": "==1.9.0"
},
"wsproto": {
"hashes": [
"sha256:61eea322cdf56e8cc904bd3ad7573359a242ba65688716b0710a5eb12beab584",
"sha256:b86885dcf294e15204919950f666e06ffc6c7c114ca900b060d6e16293528294"
],
"markers": "python_version >= '3.10'",
"version": "==1.3.2"
},
"zipp": {
"hashes": [
"sha256:071652d6115ed432f5ce1d34c336c0adfd6a884660d1e9712a256d3d3bd4b14e",
"sha256:a07157588a12518c9d4034df3fbbee09c814741a33ff63c05fa29d26a2404166"
],
"markers": "python_version >= '3.9'",
"version": "==3.23.0"
}
},
"develop": {}
}
-49
View File
@@ -1,51 +1,2 @@
# led-controller
ESP32-S3 controller for LED drivers: W5500 Ethernet, web UI, I2S microphone beat detection and an ESP-NOW link to the drivers. The firmware is C (ESP-IDF) at the repository root; see [`docs/BENCH_TEST.md`](docs/BENCH_TEST.md) for the bench tests.
It keeps profiles, zones, presets, device groups, sequences, palettes, patterns and outputs in its flash, and serves the web UI and JSON API ([`docs/API.md`](docs/API.md)). Zones play to device groups. Sequences advance on the beats the microphone detects, or on a BPM clock while audio is stopped. Profiles, presets and sequences import and export as JSON bundles.
## Build and flash
```bash
make build # minify the web UI from web/, then build the firmware (ESP-IDF in Docker)
make flash # flash over USB
make ota [HOST=<ip>] # update firmware (web UI included) over Ethernet, no USB (POST /ota); HOST defaults to led-controller.local
make ota-drivers HOST=<ip> [MAC=..] [BROADCAST=1] # push changed led-driver .py files over ESP-NOW (or Settings > Driver in the web UI)
make monitor # serial console
make test # driver unit tests and the C/Python envelope cross-check
make test-api HOST=<ip> # HTTP API tests against a running controller (its data is restored afterwards)
make test-browser HOST=<ip> # Selenium UI tests (needs selenium and chromedriver)
```
`make` lists every target. The web UI sources are in `web/` (`static/`, `templates/`, `audio.html`); `tools/build_web.sh` also packs the led-driver pattern files into the firmware, so the controller can send them to drivers.
## Other directories
- `led-driver/` (submodule): MicroPython firmware for the ESP32 LED drivers.
- `led-tool/` (submodule): `led-cli`, configures drivers over serial and updates the controller over Ethernet (`led-cli --ota HOST`).
- `led-simulator/` (submodule), `espnow-sender/`: test helpers.
- `db/`: the records a controller starts with (the `default` profile and group the firmware seeds at first boot, plus pattern metadata), importable with `PUT /db/<name>`.
- `test/api/`: the API tests (`test/api/README.md`); `test/browser/`: the UI tests.
## Docs
- API reference: `docs/API.md`
- User guide: `docs/help.md` (`scripts/build_help_pdf.sh` regenerates `docs/help.pdf`)
- Specification: `docs/SPECIFICATION.md`
## Network
The controller advertises `<hostname>.local` over mDNS (default `led-controller`, plus an `_http._tcp` service). Both settings below come from `/settings` and apply on reboot.
`static_ips` is a list of networks to try, in order, each time the Ethernet link comes up. The first entry whose gateway answers ARP is used; if none does (or the list is empty) the controller uses DHCP. `netmask` defaults to `255.255.255.0`, `dns` to the gateway.
If DHCP gets no answer within 15 seconds, the controller takes `192.168.4.1/24`. For a cable straight from a PC, give the PC a static IP on that subnet, such as `192.168.4.2/24`, and open `http://192.168.4.1/`. The controller tries DHCP again only when the link next comes up.
```bash
curl -X PUT http://led-controller.local/settings/settings -H 'Content-Type: application/json' -d '{
"hostname": "stage",
"static_ips": [
{"ip": "192.168.1.50", "netmask": "255.255.255.0", "gw": "192.168.1.1"},
{"ip": "10.0.0.50", "netmask": "255.255.255.0", "gw": "10.0.0.1"}
]}'
```
Binary file not shown.
+37
View File
@@ -0,0 +1,37 @@
/* General tab styles */
.tabs {
display: flex;
justify-content: center;
margin-bottom: 20px;
}
.tab {
padding: 10px 20px;
margin: 0 10px;
cursor: pointer;
background-color: #f1f1f1;
border: 1px solid #ccc;
border-radius: 4px;
transition: background-color 0.3s ease;
}
.tab:hover {
background-color: #ddd;
}
.tab.active {
background-color: #ccc;
}
.tab-content {
display: flex;
justify-content: center;
}
.tab-pane {
display: none;
}
.tab-pane.active {
display: block;
}
Binary file not shown.
+2
View File
@@ -0,0 +1,2 @@
#!/usr/bin/env sh
rm -f /home/pi/led-controller/.cursor/debug.log
-6
View File
@@ -1,6 +0,0 @@
{
"enabled": true,
"device": "simulated",
"device_override": "",
"device_select": "simulated"
}
-16
View File
@@ -1,16 +0,0 @@
[
{
"id": "c9ab898d-740",
"label": "bridge1",
"transport": "ip",
"ip": "192.168.4.1",
"ws_port": 80
},
{
"id": "18d85e86-17b",
"label": "bridge2",
"transport": "serial",
"serial_port": "/dev/ttyUSB0",
"serial_baudrate": 115200
}
]
-1
View File
@@ -1 +0,0 @@
{}
+17 -1
View File
@@ -1 +1,17 @@
{"1": {"name": "default", "devices": [], "wifi_driver_display_name": null, "wifi_driver_num_leds": null, "wifi_color_order": null, "wifi_startup_mode": null, "output_brightness": 255, "bridge_id": null, "pattern": "on", "colors": ["000000", "FF0000"], "brightness": 100, "delay": 100, "step_offset": 0, "step_increment": 1, "n1": 0, "n2": 0, "n3": 0, "n4": 0, "n5": 0, "n6": 0, "n7": 0, "n8": 0, "id": "1"}}
{
"1": {
"name": "Main Group",
"devices": [
"1",
"2",
"3"
]
},
"2": {
"name": "Accent Group",
"devices": [
"4",
"5"
]
}
}
-1
View File
@@ -1 +0,0 @@
{}
+12 -1
View File
@@ -1 +1,12 @@
{"1": ["#FF0000", "#00FF00", "#0000FF", "#FFFF00", "#FF00FF", "#00FFFF", "#FFFFFF", "#000000"]}
{
"1": [
"#FF0000",
"#00FF00",
"#0000FF",
"#FFFF00",
"#FF00FF",
"#00FFFF",
"#FFFFFF",
"#000000"
]
}
+54 -1
View File
@@ -1 +1,54 @@
{"on": {"min_delay": 10, "max_delay": 10000, "max_colors": 1}, "off": {"min_delay": 10, "max_delay": 10000, "max_colors": 0}, "rainbow": {"n1": "Step Rate", "min_delay": 10, "max_delay": 10000, "max_colors": 0}, "colour_cycle": {"n1": "Step Rate", "min_delay": 10, "max_delay": 10000, "max_colors": 10}, "transition": {"min_delay": 10, "max_delay": 10000, "max_colors": 10}, "chase": {"n1": "Colour 1 Length", "n2": "Colour 2 Length", "n3": "Step 1", "n4": "Step 2", "min_delay": 10, "max_delay": 10000, "max_colors": 2}, "pulse": {"n1": "Attack", "n2": "Hold", "n3": "Decay", "min_delay": 10, "max_delay": 10000, "max_colors": 10}, "circle": {"n1": "Head Rate", "n2": "Max Length", "n3": "Tail Rate", "n4": "Min Length", "min_delay": 10, "max_delay": 10000, "max_colors": 2}, "blink": {"min_delay": 10, "max_delay": 10000, "max_colors": 10}, "flicker": {"n1": "Min brightness", "min_delay": 10, "max_delay": 10000, "max_colors": 10}, "flame": {"n1": "Min brightness", "n2": "Breath period (ms)", "n3": "Spark gap min (ms, 0=default 10\u201330 s, -1=off)", "n4": "Spark gap max (ms)", "min_delay": 10, "max_delay": 10000, "max_colors": 10}, "twinkle": {"n1": "Twinkle activity (1\u2013255, higher = more changes)", "n2": "Density (0\u2013255, higher = more of the strip lit)", "n3": "Min adjacent LEDs per twinkle (same as max for fixed length)", "n4": "Max adjacent LEDs per twinkle (same as min for fixed length)", "min_delay": 84, "max_delay": 10000, "max_colors": 10}, "radiate": {"n1": "Node spacing (LEDs)", "n2": "Out time (ms)", "n3": "In time (ms)", "min_delay": 10, "max_delay": 10000, "max_colors": 2}, "meteor_rain": {"n1": "Tail length", "n2": "Speed (LEDs per frame)", "n3": "Fade amount (1-255)", "min_delay": 10, "max_delay": 10000, "max_colors": 10}, "scanner": {"n1": "Eye width", "n2": "End pause (frames)", "min_delay": 10, "max_delay": 10000, "max_colors": 10}, "gradient_scroll": {"n1": "Scroll step rate", "min_delay": 10, "max_delay": 10000, "max_colors": 10}, "comet_dual": {"n1": "Tail length", "n2": "Speed", "n3": "Gap", "max_colors": 10, "min_delay": 10, "max_delay": 10000}, "sparkle_trail": {"n1": "Spark density", "n2": "Decay", "max_colors": 10, "min_delay": 10, "max_delay": 10000}, "wave": {"n1": "Wavelength", "n2": "Amplitude", "n3": "Drift speed", "max_colors": 10, "min_delay": 10, "max_delay": 10000}, "plasma": {"n1": "Scale", "n2": "Speed", "n3": "Contrast", "max_colors": 10, "min_delay": 10, "max_delay": 10000}, "segment_chase": {"n1": "Segment size", "n2": "Phase step", "n3": "Segment phase offset", "n4": "Gap per segment", "max_colors": 10, "min_delay": 10, "max_delay": 10000}, "bar_graph": {"n1": "Level percent", "max_colors": 10, "min_delay": 10, "max_delay": 10000}, "breathing_dual": {"n1": "Phase offset", "n2": "Ease", "max_colors": 10, "min_delay": 10, "max_delay": 10000}, "strobe_burst": {"n1": "Burst count", "n2": "Burst gap", "n3": "Cooldown", "max_colors": 10, "min_delay": 10, "max_delay": 10000}, "rain_drops": {"n1": "Drop rate", "n2": "Ripple width", "max_colors": 10, "min_delay": 10, "max_delay": 10000}, "fireflies": {"n1": "Count", "n2": "Twinkle speed", "max_colors": 10, "min_delay": 10, "max_delay": 10000}, "clock_sweep": {"n1": "Hand width", "n2": "Marker interval", "max_colors": 10, "min_delay": 10, "max_delay": 10000}, "marquee": {"n1": "On length", "n2": "Off length", "n3": "Step", "max_colors": 10, "min_delay": 10, "max_delay": 10000}, "aurora": {"n1": "Band count", "n2": "Shimmer", "max_colors": 10, "min_delay": 10, "max_delay": 10000}, "snowfall": {"n1": "Flake density", "n2": "Fall speed", "max_colors": 10, "min_delay": 10, "max_delay": 10000}, "heartbeat": {"n1": "Pulse 1 ms", "n2": "Pulse 2 ms", "n3": "Pause ms", "max_colors": 10, "min_delay": 10, "max_delay": 10000}, "orbit": {"n1": "Orbit count", "n2": "Base speed", "max_colors": 10, "min_delay": 10, "max_delay": 10000}, "palette_morph": {"n1": "Morph ms", "n2": "Warp rate", "n3": "Turbulence", "max_colors": 10, "min_delay": 10, "max_delay": 10000}, "gradient_wipe": {"n1": "Start LED", "n2": "End LED", "min_delay": 10, "max_delay": 10000, "max_colors": 2}}
{
"on": {
"min_delay": 10,
"max_delay": 10000,
"max_colors": 1
},
"off": {
"min_delay": 10,
"max_delay": 10000,
"max_colors": 0
},
"rainbow": {
"n1": "Step Rate",
"min_delay": 10,
"max_delay": 10000,
"max_colors": 0
},
"transition": {
"min_delay": 10,
"max_delay": 10000,
"max_colors": 10
},
"chase": {
"n1": "Colour 1 Length",
"n2": "Colour 2 Length",
"n3": "Step 1",
"n4": "Step 2",
"min_delay": 10,
"max_delay": 10000,
"max_colors": 2
},
"pulse": {
"n1": "Attack",
"n2": "Hold",
"n3": "Decay",
"min_delay": 10,
"max_delay": 10000,
"max_colors": 10
},
"circle": {
"n1": "Head Rate",
"n2": "Max Length",
"n3": "Tail Rate",
"n4": "Min Length",
"min_delay": 10,
"max_delay": 10000,
"max_colors": 2
},
"blink": {
"min_delay": 10,
"max_delay": 10000,
"max_colors": 10
}
}
+276 -1
View File
@@ -1 +1,276 @@
{"1":{"name":"on","pattern":"on","colors":["#FFFFFF"],"brightness":255,"delay":100,"n1":0,"n2":0,"n3":0,"n4":0,"n5":0,"n6":0,"n7":0,"n8":0,"profile_id":"1","auto":true,"id":"1"},"2":{"name":"off","pattern":"off","colors":[],"brightness":0,"delay":100,"n1":0,"n2":0,"n3":0,"n4":0,"n5":0,"n6":0,"n7":0,"n8":0,"profile_id":"1","auto":true,"id":"2"},"3":{"name":"rainbow","pattern":"rainbow","colors":[],"brightness":255,"delay":100,"n1":2,"n2":0,"n3":0,"n4":0,"n5":0,"n6":0,"n7":0,"n8":0,"profile_id":"1","auto":true,"id":"3"},"4":{"name":"Colour Cycle","pattern":"colour_cycle","colors":["#FF0000","#00FF00","#0000FF"],"brightness":255,"delay":100,"n1":1,"n2":0,"n3":0,"n4":0,"n5":0,"n6":0,"n7":0,"n8":0,"profile_id":"1","auto":true,"id":"4"},"5":{"name":"transition","pattern":"transition","colors":["#FF0000","#00FF00","#0000FF"],"brightness":255,"delay":500,"n1":0,"n2":0,"n3":0,"n4":0,"n5":0,"n6":0,"n7":0,"n8":0,"profile_id":"1","auto":true,"id":"5"},"6":{"name":"flicker","pattern":"flicker","colors":["#FFB84D"],"brightness":255,"delay":80,"n1":30,"n2":0,"n3":0,"n4":0,"n5":0,"n6":0,"n7":0,"n8":0,"profile_id":"1","auto":true,"id":"6"},"7":{"name":"flame","pattern":"flame","colors":[],"brightness":255,"delay":50,"n1":35,"n2":2600,"n3":0,"n4":0,"n5":0,"n6":0,"n7":0,"n8":0,"profile_id":"1","auto":true,"id":"7"},"8":{"name":"twinkle","pattern":"twinkle","colors":["#78C8FF","#508CFF","#B478FF","#64DCE8","#A0C8FF"],"brightness":255,"delay":55,"n1":72,"n2":140,"n3":2,"n4":6,"n5":0,"n6":0,"n7":0,"n8":0,"profile_id":"1","auto":true,"id":"8"}}
{
"1": {
"name": "on",
"pattern": "on",
"colors": [
"#FFFFFF"
],
"brightness": 255,
"delay": 100,
"auto": true,
"n1": 0,
"n2": 0,
"n3": 0,
"n4": 0,
"n5": 0,
"n6": 0,
"n7": 0,
"n8": 0,
"profile_id": "1"
},
"2": {
"name": "off",
"pattern": "off",
"colors": [],
"brightness": 0,
"delay": 100,
"auto": true,
"n1": 0,
"n2": 0,
"n3": 0,
"n4": 0,
"n5": 0,
"n6": 0,
"n7": 0,
"n8": 0,
"profile_id": "1"
},
"3": {
"name": "rainbow",
"pattern": "rainbow",
"colors": [],
"brightness": 255,
"delay": 100,
"auto": true,
"n1": 2,
"n2": 0,
"n3": 0,
"n4": 0,
"n5": 0,
"n6": 0,
"n7": 0,
"n8": 0,
"profile_id": "1"
},
"4": {
"name": "transition",
"pattern": "transition",
"colors": [
"#FF0000",
"#00FF00",
"#0000FF"
],
"brightness": 255,
"delay": 500,
"auto": true,
"n1": 0,
"n2": 0,
"n3": 0,
"n4": 0,
"n5": 0,
"n6": 0,
"n7": 0,
"n8": 0,
"profile_id": "1"
},
"5": {
"name": "chase",
"pattern": "chase",
"colors": [
"#FF0000",
"#0000FF"
],
"brightness": 255,
"delay": 200,
"auto": true,
"n1": 5,
"n2": 5,
"n3": 1,
"n4": 1,
"n5": 0,
"n6": 0,
"n7": 0,
"n8": 0,
"profile_id": "1"
},
"6": {
"name": "pulse",
"pattern": "pulse",
"colors": [
"#00FF00"
],
"brightness": 255,
"delay": 500,
"auto": true,
"n1": 1000,
"n2": 500,
"n3": 1000,
"n4": 0,
"n5": 0,
"n6": 0,
"n7": 0,
"n8": 0,
"profile_id": "1"
},
"7": {
"name": "circle",
"pattern": "circle",
"colors": [
"#FFA500",
"#800080"
],
"brightness": 255,
"delay": 200,
"auto": true,
"n1": 2,
"n2": 10,
"n3": 2,
"n4": 5,
"n5": 0,
"n6": 0,
"n7": 0,
"n8": 0,
"profile_id": "1"
},
"8": {
"name": "blink",
"pattern": "blink",
"colors": [
"#FF0000",
"#00FF00",
"#0000FF",
"#FFFF00"
],
"brightness": 255,
"delay": 1000,
"auto": true,
"n1": 0,
"n2": 0,
"n3": 0,
"n4": 0,
"n5": 0,
"n6": 0,
"n7": 0,
"n8": 0,
"profile_id": "1"
},
"9": {
"name": "warm white",
"pattern": "on",
"colors": ["#FFF5E6"],
"brightness": 200,
"delay": 100,
"auto": true,
"n1": 0,
"n2": 0,
"n3": 0,
"n4": 0,
"n5": 0,
"n6": 0,
"n7": 0,
"n8": 0,
"profile_id": "1"
},
"10": {
"name": "cool white",
"pattern": "on",
"colors": ["#E6F2FF"],
"brightness": 200,
"delay": 100,
"auto": true,
"n1": 0,
"n2": 0,
"n3": 0,
"n4": 0,
"n5": 0,
"n6": 0,
"n7": 0,
"n8": 0,
"profile_id": "1"
},
"11": {
"name": "red",
"pattern": "on",
"colors": ["#FF0000"],
"brightness": 255,
"delay": 100,
"auto": true,
"n1": 0,
"n2": 0,
"n3": 0,
"n4": 0,
"n5": 0,
"n6": 0,
"n7": 0,
"n8": 0,
"profile_id": "1"
},
"12": {
"name": "blue",
"pattern": "on",
"colors": ["#0000FF"],
"brightness": 255,
"delay": 100,
"auto": true,
"n1": 0,
"n2": 0,
"n3": 0,
"n4": 0,
"n5": 0,
"n6": 0,
"n7": 0,
"n8": 0,
"profile_id": "1"
},
"13": {
"name": "rainbow slow",
"pattern": "rainbow",
"colors": [],
"brightness": 255,
"delay": 150,
"auto": true,
"n1": 1,
"n2": 0,
"n3": 0,
"n4": 0,
"n5": 0,
"n6": 0,
"n7": 0,
"n8": 0,
"profile_id": "1"
},
"14": {
"name": "pulse slow",
"pattern": "pulse",
"colors": ["#FF6600"],
"brightness": 255,
"delay": 800,
"auto": true,
"n1": 2000,
"n2": 1000,
"n3": 2000,
"n4": 0,
"n5": 0,
"n6": 0,
"n7": 0,
"n8": 0,
"profile_id": "1"
},
"15": {
"name": "blink red green",
"pattern": "blink",
"colors": ["#FF0000", "#00FF00"],
"brightness": 255,
"delay": 500,
"auto": true,
"n1": 0,
"n2": 0,
"n3": 0,
"n4": 0,
"n5": 0,
"n6": 0,
"n7": 0,
"n8": 0,
"profile_id": "1"
}
}
+11 -1
View File
@@ -1 +1,11 @@
{"1": {"name": "default", "type": "zones", "zones": ["1"], "scenes": [], "palette_id": "1", "id": "1"}}
{
"1": {
"name": "default",
"type": "tabs",
"tabs": [
"1"
],
"scenes": [],
"palette_id": "1"
}
}
+22 -1
View File
@@ -1 +1,22 @@
{}
{
"1": {
"name": "Default Scene",
"sequences": [
"1"
],
"groups": [
"1"
]
},
"2": {
"name": "Party Mode",
"sequences": [
"1",
"2"
],
"groups": [
"1",
"2"
]
}
}
+30 -1
View File
@@ -1 +1,30 @@
{}
{
"1": {
"group_name": "Main Group",
"presets": [
"1",
"2"
],
"sequence_duration": 3000,
"sequence_transition": 500,
"sequence_loop": true,
"sequence_repeat_count": 0,
"sequence_active": false,
"sequence_index": 0,
"sequence_start_time": 0
},
"2": {
"group_name": "Accent Group",
"presets": [
"2",
"3"
],
"sequence_duration": 2000,
"sequence_transition": 300,
"sequence_loop": true,
"sequence_repeat_count": 0,
"sequence_active": false,
"sequence_index": 0,
"sequence_start_time": 0
}
}
+27
View File
@@ -0,0 +1,27 @@
{
"1": {
"name": "default",
"names": [
"a","b","c","d","e","f","g","h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"
],
"presets": [
[
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
"13",
"14",
"15"
]
]
}
}
-1
View File
@@ -1 +0,0 @@
{"1": {"name": "default", "names": ["1"], "presets": [["1", "2", "3", "4", "5", "6", "7", "8"]], "presets_flat": ["1", "2", "3", "4", "5", "6", "7", "8"], "default_preset": "1", "id": "1", "group_ids": ["1"], "preset_group_ids": {}, "sequence_ids": [], "content_kind": "presets"}}
-31
View File
@@ -1,31 +0,0 @@
dependencies:
espressif/mdns:
component_hash: ef0766474b37459f6ad22461e453a8713e780e831a7c993b16919d817988dff6
dependencies:
- name: idf
require: private
version: '>=5.0'
source:
registry_url: https://components.espressif.com/
type: service
version: 1.14.1
idf:
source:
type: idf
version: 5.5.5
joltwallet/littlefs:
component_hash: e1a0f4a6adf821759cb34703a91107bbdce5d7ff6f4728f40ab012bb87842974
dependencies:
- name: idf
require: private
version: '>=5.0'
source:
registry_url: https://components.espressif.com/
type: service
version: 1.23.1
direct_dependencies:
- espressif/mdns
- joltwallet/littlefs
manifest_hash: a5329d49f0154685d9701ccb399916a87107b77ddfe802c911aa2bb41ed5bab0
target: esp32s3
version: 2.0.0
Executable
+53
View File
@@ -0,0 +1,53 @@
#!/usr/bin/env python3
import subprocess
import serial
import sys
print(sys.argv)
# Extract port (first arg if it's not a command)
commands = ["src", "lib", "ls", "reset", "follow", "db"]
port = None
if len(sys.argv) > 1 and sys.argv[1] not in commands:
port = sys.argv[1]
for cmd in sys.argv[1:]:
print(cmd)
match cmd:
case "src":
if port:
subprocess.call(["mpremote", "connect", port, "fs", "cp", "-r", ".", ":" ], cwd="src")
else:
print("Error: Port required for 'src' command")
case "lib":
if port:
subprocess.call(["mpremote", "connect", port, "fs", "cp", "-r", "lib", ":" ])
else:
print("Error: Port required for 'lib' command")
case "ls":
if port:
subprocess.call(["mpremote", "connect", port, "fs", "ls", ":" ])
else:
print("Error: Port required for 'ls' command")
case "reset":
if port:
with serial.Serial(port, baudrate=115200) as ser:
ser.write(b'\x03\x03\x04')
else:
print("Error: Port required for 'reset' command")
case "follow":
if port:
with serial.Serial(port, baudrate=115200) as ser:
while True:
if ser.in_waiting > 0: # Check if there is data in the buffer
data = ser.readline().decode('utf-8').strip() # Read and decode the data
print(data)
else:
print("Error: Port required for 'follow' command")
case "db":
if port:
subprocess.call(["mpremote", "connect", port, "fs", "cp", "-r", "db", ":" ])
else:
print("Error: Port required for 'db' command")
+240 -346
View File
@@ -1,369 +1,263 @@
# LED Controller API
# LED Driver ESPNow API Documentation
The controller is an ESP32-S3 on Ethernet (W5500). It serves the web UI and a JSON API on port 80, detects beats from its I2S microphone and talks to the LED drivers over ESP-NOW. This document covers:
1. The HTTP and WebSocket API, by resource.
2. How the controller turns API calls into driver messages, and the message format.
This document describes the ESPNow message format for controlling LED driver devices.
Request and response bodies are JSON (`Content-Type: application/json`) unless noted. Errors come back as `{"error": "..."}` with a 4xx or 5xx status.
## Data and scoping
- **Storage.** Each resource is a collection (`device`, `zone`, `preset`, `profile`, `palette`, `pattern`, `sequence`, `scene`, `group`, `output`, `settings`), stored as one JSON object of id → record on the flash filesystem. New records get the next numeric id (highest + 1), as a string. Devices are keyed by MAC (12 lowercase hex digits, no colons) and patterns by name.
- **Current profile.** `settings.current_profile_id`, set by `POST /profiles/<id>/apply`. When it is unset or names a missing profile, the first profile is current. It is global (the same for every browser).
- **Profile scoping.** Presets and sequences belong to a profile (`profile_id`). The list routes return only the current profile's records, and the single-record routes answer 404 for another profile's. Groups with a `profile_id` are visible only while that profile is current; groups without one are shared.
- **Current zone.** A `current_zone` cookie, set by `POST /zones/<id>/set-current`. Without it, the current profile's first zone.
- **Migration.** At boot, groups, zones and sequences written by older versions get the fields described below.
---
## Pages and static files
| Method | Path | Description |
|--------|------|-------------|
| GET | `/` | Main UI |
| GET | `/settings/page` | Standalone settings page |
| GET | `/audio` | Live audio and beat page (level, tempo, bar position, tap) |
| GET | `/settings/editor` | Driver settings editor: sends a driver settings (`PUT /devices/<id>`) and updates its code (`/drivers/ota`) over ESP-NOW |
| GET | `/static/<path>` | UI scripts and styles |
| GET | `/favicon.ico` | 204 |
Pages and static files are built into the firmware (gzipped, sent with `Content-Encoding: gzip`). They carry `Cache-Control: no-cache` and an `ETag` of the firmware build, so a browser revalidates each load (304 until the next update).
## Controller
| Method | Path | Description |
|--------|------|-------------|
| GET | `/status` | IP, `eth` (ip, mask, gw, up), `ap_ip`, `ap_clients` (`[{mac, ip}]` on the Wi-Fi access point), MAC, uptime, `free_heap`, `free_internal` (internal RAM), mic level, tempo and beat counts, ESP-NOW and link statistics |
| POST | `/reboot` | Replies `{"message":"rebooting"}`, then restarts after 0.5 s |
| GET | `/ota` | Running image: partition, version, build time, IDF version, sha |
| POST | `/ota` | Body: the raw firmware `.bin` (web UI included). Written to the idle slot, made the boot image, then the board reboots. A new image confirms itself after staying up a few seconds; one that crashes on start rolls back. `make ota HOST=<ip>` |
| GET | `/db/<collection>` | Export a whole collection |
| PUT | `/db/<collection>` | Replace a whole collection. Body: the object of id → record. Reply: `{"records": n}` |
**Bench tests** (see `docs/BENCH_TEST.md`):
| Method | Path | Description |
|--------|------|-------------|
| GET, POST | `/test/loss` | Simulated ESP-NOW loss. Body `{"percent": 0–100, "beats": bool}` (whether beat frames are dropped too). Reply: the current setting |
| POST | `/test/beats` | Body `{"bpm": 30–300, "count": n}` (0 = until stopped): synthetic beats to the drivers, with delivery and latency measured from their echoes. The mic's beats are muted meanwhile |
| GET | `/test/beats` | Results so far |
| POST | `/test/beats/stop` | Stop the generator |
## Settings — `/settings`
| Method | Path | Description |
|--------|------|-------------|
| GET | `/settings` | The settings object |
| PUT | `/settings` or `/settings/settings` | Merge keys into the settings. Reply: `{"message": "Settings updated successfully"}` |
Keys with meaning on the controller (others are stored as they are):
| Key | Checked | Meaning |
|-----|---------|---------|
| `ap_enabled` | | Wi-Fi access point (open, SSID = hostname, `192.168.5.1`); default `true`; applies after a restart. Holding the D3 button at boot forces it on |
| `ap_password` | | AP password, 8-63 characters (WPA2); empty (default) is an open network; applies after a restart |
| `bridge` | string under 64 characters | `host:port` (UDP, default port 8766) of led-simulator: every ESP-NOW frame goes there as `dst_mac + packet` instead of over the radio, and frames from it (`src_mac + packet`) count as received. Empty or missing: the radio. Applies after a restart. The host build (`sim-controller/`) always uses a bridge (`LED_SIM_BRIDGE`, default `127.0.0.1:8766`) |
| `hostname` | | mDNS name (`<hostname>.local`, default `led-controller`); applies after a restart |
| `static_ips` | | List of `{ip, netmask?, gw, dns?}` tried in order when the Ethernet link comes up; the first whose gateway answers ARP is used, else DHCP, else `192.168.4.1/24` for a direct PC cable. Applies after a restart |
| `global_brightness` | integer 0–255 | Global factor of each driver's brightness (see Groups). Stored only: the UI pushes each driver its combined value |
| `wifi_channel` | integer 1–11 | Stored for reference. The controller's ESP-NOW channel is set at build time (`make menuconfig`) |
| `audio_simulated_bpm` | clamped to 60–200 | Tempo of the beat clock (default 120) |
| `sequence_switch_wait` | `beat` or `downbeat` | When a newly started sequence takes over from the playing one |
| `audio_beat_phase_ms` | integer 0–500 | Stored for the UI |
| `audio_input_volume` | integer 0–200 | Stored for the UI |
| `current_profile_id` | | Set by profile apply and import |
| `audio_timing` | | Set by `/api/audio/start` and `/stop` |
Defaults filled at boot: `wifi_channel` (the build's ESP-NOW channel) and `global_brightness` (255).
## Profiles — `/profiles`
A profile is `{name, type: "zones", zones: [zone ids], scenes, palette_id}`.
| Method | Path | Description |
|--------|------|-------------|
| GET | `/profiles` | `{"profiles": {...}, "current_profile_id": "<id>"}` |
| GET | `/profiles/current` | `{"id": "<id>", "profile": {...}}`; 404 when there are no profiles |
| GET | `/profiles/<id>` | One profile (`current` works as an id) |
| POST | `/profiles` | Create. Body: `name` and any other fields; optional `seed_dj_zone`. Reply `{"<id>": profile}`, 201. See below |
| PUT | `/profiles/<id>`, `/profiles/current` | Merge fields |
| POST | `/profiles/<id>/apply` | Make it current. Reply `{"message": "Profile applied", "id": "<id>"}` |
| POST | `/profiles/<id>/clone` | Copy with its own palette, zones and presets (preset references in the zones point at the copies). Body: optional `name`. 201 |
| DELETE | `/profiles/<id>` | Delete it with its presets and sequences, and its zones and palette unless another profile lists them |
| GET | `/profiles/<id>/export` | Profile bundle (see Import and export) |
| POST | `/profiles/import` | Body: `{"bundle": {...}, "name"?, "apply"? (default true)}` or the bundle itself. Reply `{"<id>": profile, "id": "<id>"}`, 201 |
A store with no profile gets one at boot, `default`, with the same seed, a starter palette and an empty `default` group that its zone plays to. A new profile gets an empty palette, eight presets (`on`, `off`, `rainbow`, `Colour Cycle`, `transition`, `flicker`, `flame`, `twinkle`) and a zone `default` that lists them and names driver `1`. With `seed_dj_zone` it also gets three `DJ …` presets in a zone `dj` naming driver `dj`.
## Presets — `/presets`
A preset has `name`, `pattern`, `colors` (`#RRGGBB`), `brightness`, `delay`, `n1`–`n8`, `profile_id`, and optionally `auto`, `palette_refs` (palette index per colour slot), `background` / `background_palette_ref`, `mode` (sent as `n6`), `manual_beat_n`, `fade` (0–10000 ms: crossfade from what the strip showed when the preset is selected) and `beat_time` (`true`: the delay and timing parameters of patterns that support it count quarter beats, so the preset follows the tempo). New presets start with every field set and belong to the current profile.
**Animation patterns** (driver patterns, labels in `/patterns`). Each plays once with `auto: false` and holds its end state; with `auto: true` it repeats.
- One-shots: `hit` (flash with attack, hold and decay), `keyframes` (ramp through the colours with easing).
- Field patterns, which span the whole rig using each driver's place from `/devices/layout`: `sweep`, `ripple`, `spin`, `grow`, `field_wave`.
| Method | Path | Description |
|--------|------|-------------|
| GET | `/presets` | The current profile's presets |
| GET | `/presets/<id>` | One preset (404 for another profile's) |
| POST | `/presets` | Create in the current profile. Reply `{"<id>": preset}`, 201 |
| PUT | `/presets/<id>` | Merge fields |
| DELETE | `/presets/<id>` | Delete |
| POST | `/presets/push` | Send driver messages. Body: `{"sequence": [message, ...]}` or `{"payload": message}`, optional `targets` (MACs: acked unicast to each). Without targets, broadcast. Reply `{"message": "Delivered"}`. See Driver messages |
| POST | `/presets/send` | Send stored presets. Body: `preset_ids` (or `ids`), `save` (default true), `default` (startup preset id), `targets` or `destination_mac`. Reply `{"message": "Presets sent", "presets_sent": n}` |
| GET | `/presets/<id>/export` | Preset bundle |
| POST | `/presets/import` | Body: a preset bundle (or `{"bundle": ...}`). New id in the current profile, 201 |
## Zones — `/zones`
A zone has `name`, `names` (driver names, the older way to target drivers), `group_ids` (groups it plays to), `presets` (rows of preset ids), `presets_flat`, `default_preset`, `preset_group_ids`, `sequence_ids`, `animation_ids` (animations shown as one-shot tiles), `content_kind` (`presets` or `sequences`) and `brightness` (0–255, the zone slider).
| Method | Path | Description |
|--------|------|-------------|
| GET | `/zones` | `{"zones": {...all zones}, "zone_order": [current profile's zone ids], "current_zone_id", "profile_id"}` |
| GET | `/zones/current` | `{"zone": {...}, "zone_id": "<id>"}`, or 404 `{"error", "zone": null, "zone_id": null}` |
| GET | `/zones/<id>` | One zone |
| POST | `/zones` | Create (body: `name` required, `names` or `ids`, `group_ids`, `presets`, `content_kind`, ...). Added to the current profile's zone list. 201 |
| PUT | `/zones/<id>` | Merge fields |
| DELETE | `/zones/<id>` | Delete (`current` works as an id) and remove it from every profile. Clears the cookie if it was current |
| POST | `/zones/<id>/set-current` | Set the `current_zone` cookie |
| POST | `/zones/<id>/clone` | Copy into the current profile. Body: optional `name` (default `<name> Copy`). 201 |
| GET | `/zones/<id>/content-fragment` | With `HX-Request`: the zone's tab content (HTML); otherwise the main page |
| POST | `/zones/<id>/play` | Body `{"preset_id", "drivers"?}`: upload the preset to the zone's groups and select it (`drivers: false` skips sending). 404 for an unknown zone or preset |
| POST | `/zones/<id>/stop` | Select `off` on the zone's groups. `{"stopped": bool}` |
| GET | `/zones/engine/status` | Sequence playback status (as `/sequences/status`) |
## Groups — `/groups`
A group lists drivers by MAC (`devices`) and carries `output_brightness` (0–255), driver defaults (`wifi_driver_display_name`, `wifi_driver_num_leds`, `wifi_color_order`, `wifi_startup_mode`) and pattern fields. MACs are normalised to 12 lowercase hex digits. A driver's group membership is every group listing its MAC (see Driver groups), sent to it whenever groups, zones or devices change.
| Method | Path | Description |
|--------|------|-------------|
| GET | `/groups` | Groups visible in the current profile |
| GET | `/groups/<id>` | One group (404 when scoped to another profile) |
| POST | `/groups` | Create with defaults; `profile_scoped: true` ties it to the current profile, `profile_id` may only name the current profile or be null. Reply: the group, 201 |
| PUT | `/groups/<id>` | Merge fields |
| DELETE | `/groups/<id>` | Delete |
| POST | `/groups/<id>/brightness` | Each member gets its combined brightness, saved on the driver. `{"message", "sent", "errors": [{mac, error}]}` |
| POST | `/groups/<id>/driver-config` | Each member gets `device_config` from the group's driver defaults (body fields override for this send). 400 when none is set |
| POST | `/groups/<id>/identify` | All members blink red together for 2 s, then go off. 400 when the group has no devices |
**Combined brightness** for a driver: `round(255 × global/255 × g₁/255 × … × device/255 [× zone/255])`, with one factor per group listing it (`output_brightness`), the device's `output_brightness` and, when given, the zone slider.
## Devices — `/devices`
A device is `{id: MAC, name, type: "led", transport: "espnow" | "wifi", address, default_pattern, zones, output_brightness?}`. ESP-NOW drivers register themselves when they boot (announce) and when they answer a ping. For ESP-NOW devices `address` is the MAC. The controller has no Wi-Fi driver transport: Wi-Fi records are kept, but nothing is sent to them.
| Method | Path | Description |
|--------|------|-------------|
| GET | `/devices` | All devices, each with `connected` (`null` for ESP-NOW, `false` for Wi-Fi) |
| GET | `/devices/<id>` | One device (the id may be written with colons) |
| POST | `/devices` | Create. `name` required; `mac` (or, for ESP-NOW, a MAC in `address`); `transport` `espnow` (default) or `wifi`. Reply `{"<mac>": device}`, 201; 409 for a MAC already registered |
| PUT | `/devices/<id>` | Merge fields. `name` cannot be blank, the MAC cannot change, `output_brightness` 0–255. Changing `name`, `max_brightness`, `num_leds`, `color_order`, `startup_mode` or `reversed` also sends them to the driver as `device_config` |
| DELETE | `/devices/<id>` | Delete |
| GET | `/devices/status` | Per driver: `{"last_ack_ms_ago": ms or -1, "failed_messages": n}` from the acked link |
| POST | `/devices/ping` | Body `{"timeout_s": 0.5–30}` (default 3). Broadcasts a ping and collects replies: `{"ok", "ping_id", "timeout_s", "responses": {mac: {mac, name, rtt_ms}}, "registered": n}`. Drivers that answer are added or renamed |
| POST | `/devices/layout` | Body `{"placements": {mac: {x0, y0, x1, y1} \| null}, "center"?: {x, y}}`: where each bar sits, in any units with y up, and the rig's centre (kept in `settings.rig_center`; without one, the layout's bounding-box centre). `x0,y0` is LED 1, the data-in end; `null` removes a bar. Saved as the device's `placement`. Then every placed ESP-NOW driver gets `device_config.place`: its ends relative to the centre, scaled so the furthest end is 1 from it. Reply `{"updated", "sent", "failed"}`; 400 without `placements` |
| POST | `/devices/groups` | Send every ESP-NOW driver its groups and wait for the acks: `{"ok", "total", "sent", "failed"}` (503 when any failed, 400 with no ESP-NOW devices) |
| POST | `/devices/resolve-brightness` | Body `{"macs": [...], "zone_brightness"?}` → `{"values": {mac: brightness}}` |
| POST | `/devices/<id>/brightness` | Body `{"zone_brightness"?}`: send the combined brightness, saved on the driver. `{"message", "brightness"}` |
| POST | `/devices/<id>/driver-config` | Body: any of `name`, `num_leds` (1–2048), `color_order`, `startup_mode` (`default`, `last`, `off`) |
| POST | `/devices/<id>/identify` | Red 10 Hz blink for 2 s, then off |
## Sequences — `/sequences`
A sequence is `{name, profile_id, kind?, targets?, lanes: [[step, ...], ...], lane_opts?, lanes_group_ids: [[group ids], ...], group_ids, loop (default true), advance_mode: "beats" | "time", steps, step_duration_ms, sequence_transition}`. Every field marked `?` is optional; a sequence without them plays as it always has.
- `kind`: `"sequence"` (default) or `"animation"`: a clip that is fired once over whatever runs (see Animations). Both are stored here.
- `targets`: the drivers the sequence plays to, in order (up to 32): `[{name, group_ids: [group ids], devices: [MACs]}]`. A target reaches every driver in its groups plus each listed driver (by its own group `d<mac>`, see Driver groups). Lanes and steps name targets by index.
- `lane_opts`: one object per lane (same index as `lanes`):
- `mode`: `"beats"` or `"time"`, overriding `advance_mode` for this lane, so beat lanes and time lanes run side by side.
- `offset`: beats (or seconds, time lanes) before the lane starts, on the first pass only. With a copy of a lane this gives a canon or ripple.
- `rate`: 0.25–4, speed multiplier. A 1-beat step at rate 2 lasts half a beat.
- `targets`: indexes into `targets` the lane plays to. Without them the lane's groups come from the older fields: `lanes_group_ids[lane]`, else `group_ids`, else (single lane) the step's `group_ids`, else the zone's groups.
- `chase`: `{order: "forward" | "reverse" | "bounce" | "random", width (default 1), others: "off" (default) | "hold"}`. Each step moves the lit position along the lane's targets (in the order listed in the lane's `targets`). The step's preset goes to `width` targets from there, and the rest go off or keep what they show.
- A step is `{preset_id, beats (default 1, from 0.25), seconds (default 3, 0.1–3600), targets?, others?, rest?, animation_id?, length?, group_ids?}`:
- `beats` / `seconds`: how long it lasts, by its lane's mode.
- `targets`: indexes of the lane's targets this step lights (default: all of the lane's, or the chase position).
- `others: "off"`: the lane's other targets go off for this step.
- `rest: true`: nothing lit; the lane's targets go off.
- `animation_id`: fire that animation instead of a preset. With `length: "animation"` the step lasts as long as the animation (at the current tempo).
| Method | Path | Description |
|--------|------|-------------|
| GET | `/sequences` | The current profile's sequences |
| GET | `/sequences/<id>` | One sequence |
| POST | `/sequences` | Create in the current profile. A non-empty `steps` without lanes becomes lane 0. Reply `{"<id>": sequence}`, 201 |
| PUT | `/sequences/<id>` | Merge fields; stops it when it is playing |
| DELETE | `/sequences/<id>` | Delete; stops it when it is playing |
| POST | `/sequences/<id>/play` | Body `{"zone_id"}` (required). Reply `{"ok": true, "pending": bool, ...}`. 400 for a missing zone, a sequence without steps or one from another profile |
| POST | `/sequences/stop` | Stop playback (and any animation) and clear the presets on the zone's groups. `{"ok": true}` |
| POST | `/sequences/<id>/fire` | Play it once as an animation over whatever runs. Body `{"zone_id"?, "wait"?: "now" (default) \| "beat" \| "downbeat"}`; without `zone_id`, the playing sequence's zone. Reply `{"ok": true, "wait"}`. 404 for another profile's, 400 without a zone or steps |
| POST | `/sequences/overlay/stop` | End the animation now; its drivers go back (as when it ends). `{"ok": true}` |
| POST | `/sequences/sync-phase` | Body `{"mode": "step" | "pass"}`: `step` restarts the current step's beat count, `pass` restarts the sequence. Also makes this beat bar beat 1. 409 when nothing plays |
| GET | `/sequences/status` | Playback status (below) |
| GET | `/sequences/<id>/export` | Sequence bundle (the sequence and its presets) |
| POST | `/sequences/import` | Body: a sequence bundle. The presets are copied into the current profile and the steps point at the copies. 201 |
**Playback.** One sequence plays at a time, in one zone.
- **Start.** Each lane's first preset is uploaded to the lane's groups and selected, then the lane's other presets are uploaded, and every driver in the zone gets its combined brightness with the zone slider.
- **Advancing.** A time lane moves on when its step's `seconds` are up, whatever the beat. When lane 0 is a time lane, the status has `lane0_step_elapsed_ms` and `lane0_step_duration_ms` and `beat_readout` is empty. A beat lane counts quarter beats (the controller ticks between beats from the last beat interval) towards its step's `beats` ÷ `rate`, then moves on. Each step's preset is uploaded to all of the lane's targets (unless already there), then selected on the targets the step lights.
- **End.** Without `loop` the sequence ends after one pass. Its presets are cleared from the zone's groups, and the readout keeps `n/n`.
- **Switching.** Starting another sequence while one plays waits for the next beat. It waits for the next downbeat only when `sequence_switch_wait` is `downbeat` and the mic is timing. The current sequence holds meanwhile.
- **Animations.** `/sequences/<id>/fire` (or a step's `animation_id`) plays a sequence once in a second player over the running one. An animation loops only with `loop: true`.
- While it plays, the sequence keeps time, but its sends leave out the drivers the animation's lanes reach: groups are split into those drivers' own groups.
- When it ends (or `/sequences/overlay/stop`), those drivers get the sequence's current step again. With no sequence playing they get the zone's last played preset, else off.
- Firing another animation replaces the one playing. Drivers the new one doesn't reach go back.
- A sequence that ends while an animation plays clears the zone once the animation is over.
- **Beat source.** Beats come from the mic's beat detector while audio timing is on (`/api/audio/start`) and it has a tempo lock. Otherwise they come from a clock at `audio_simulated_bpm`, whose beats also go to the drivers. Beats closer than 0.3 s (200 BPM) are dropped.
Status: `{"active": false, "beat_readout": "", overlay}` when idle, else `{active, advance_mode, sequence_id, zone_id, num_lanes, total_sequence_steps, lane0_current_step, lane0_lane_length, lane0_beat_in_step, lane0_beats_per_step, lane0_preset_id, lane0_preset_name, sequence_beat_at, sequence_beats_per_pass, sequence_loop_beat, beat_readout, lanes, overlay}`.
- `lanes`: one entry per playing lane, `{step (0-based), steps, mode, started, done, pos? (chase: the target index lit first), beat_in_step and beats_in_step (beat lanes) or elapsed_ms and duration_ms (time lanes)}`.
- `overlay`: `{active, pending, pending_id?}`, plus `{sequence_id, zone_id, drivers, progress (0–1), lanes}` while an animation plays.
## Audio — `/api/audio`
| Method | Path | Description |
|--------|------|-------------|
| GET | `/api/audio/status` | `{"status": {...}}`, see below |
| GET | `/api/audio/events` | Server-sent events, `data: {"type": "status" | "beat", "status": {...}}`: a status event first, one on every detected beat, and a status heartbeat every 0.5 s |
| POST | `/api/audio/start` | Mic beats time sequences and go to the drivers. Saved. `{"ok": true, "status"}` |
| POST | `/api/audio/stop` | The beat clock times sequences instead; the mic's beats stop going to the drivers. Saved |
| POST | `/api/audio/reset` | Forget the tempo and bar position and track again (409 while stopped) |
| POST | `/api/audio/anchor-bar` | Make the last beat bar beat 1 (409 while stopped) |
| GET | `/api/audio/devices` | The single input: `{"devices": [{"id": "i2s", "name", "display_name", "is_default": true}], "diagnostics": {}}` |
| PUT | `/api/audio/device` | Body `{"device_select"}`: stored only (there is one microphone) |
Status fields: `running` (audio timing on), `bpm` (locked tempo, `null` without a lock, the clock's tempo while stopped), `bpm_simulated`, `beat_seq`, `bar_beat`, `beats_per_bar`, `is_downbeat`, `bar_phase_readout`, `phase_confidence`, `input_level`, `last_beat_ts`, `sequence` (playback status), `sequence_pending`, `beat_readout`, `sequence_switch_wait` (in effect) and `sequence_switch_wait_saved`, `audio_simulated_bpm`, `simulated_beat_tick`, `audio_run`, `beat_phase_ms`, `input_volume`.
The `/audio` page uses its own routes:
| Method | Path | Description |
|--------|------|-------------|
| GET | `/audio.wav` | Live microphone audio (16 kHz mono WAV stream; one listener at a time) |
| GET | `/beats` | Server-sent events: `beat` (`bpm`, `n`, `bar`, `meter`, `sure`, `us`), `onset`, and `tempo` every second |
| POST | `/tap` | The user tapped bar beat 1 now |
| GET | `/time` | Board clock (`{"us": ...}`) for the page to line its clock up with |
## Patterns — `/patterns`
Pattern metadata is the `pattern` collection, keyed by name. Pattern sources are the led-driver `src/patterns/*.py` files built into the firmware, plus uploads (stored on the controller, and they take precedence). `on` and `off` are built into the driver and have no file.
| Method | Path | Description |
|--------|------|-------------|
| GET | `/patterns`, `/patterns/definitions` | Metadata, plus `{}` for every pattern file without metadata |
| GET | `/patterns/<name>` | Metadata record |
| POST | `/patterns` | Body `{name, data: {...}, ...}`: `data` and the other keys become the record under `name`. Reply: the record, 201 |
| PUT, DELETE | `/patterns/<name>` | Merge, delete (the file stays) |
| GET | `/patterns/ota/manifest` | `{"files": [{"name": "x.py", "url": "http://<Host>/patterns/ota/file/x.py"}]}` |
| GET | `/patterns/ota/file/<name>.py` | The source (`text/plain`); 400 for `on`/`off`, 404 when missing |
| POST | `/patterns/upload` | Body `{name, code, overwrite?}`: store a source. 409 when it exists and `overwrite` is false. 201 |
| POST | `/patterns/driver` | Body `{name, code, overwrite?, min_delay?, max_delay?, max_colors?, n1?..n8?}`: store the source and its metadata (`n1`–`n8` are parameter labels). The name must be an identifier. 201 |
| POST | `/patterns/<name>/send` | Push the source over ESP-NOW to one driver (`{"device_id"}`) or every ESP-NOW driver, as `patterns/<name>.py`; drivers that wrote it reset to load it. `{"message", "pattern", "device_ids", "sent_count", "results"}`; 503 when none took it |
| POST | `/devices/<id>/patterns/push` | 400: use `/patterns/<name>/send` |
## Palettes — `/palettes`
A palette is a list of colours.
| Method | Path | Description |
|--------|------|-------------|
| GET | `/palettes` | `{id: [colours]}` |
| GET | `/palettes/<id>` | `{"colors": [...], "id": "<id>"}` |
| POST | `/palettes` | Body `{"colors"}`. Reply `{"id", "colors"}`, 201 |
| PUT | `/palettes/<id>` | Body `{"colors"}`: replaces the list |
| DELETE | `/palettes/<id>` | Delete |
## Scenes — `/scenes`
Plain records: GET (list, one), POST (201), PUT (merge), DELETE. Scenes do not play.
## Outputs — `/outputs`
Network pixel fixtures. An output is `{id, name, protocol: "ddp" | "artnet" | "sacn" | "dmx_serial", host, port, universe, channel, serial_port, dmx_mode, pixel_count, pixel_offset, color_order, reverse, brightness, fps, enabled}` with defaults filled in. The checks:
- `ddp` needs a `host`. `dmx_serial` needs a `serial_port`, and its pixels must fit one DMX universe.
- Number ranges: `port` 1–65535, `universe` 0–32767 (sACN 1–63999), `channel` 1–512, `brightness` 0–255, `fps` 1–120.
- `color_order` is one of `rgb rbg grb gbr brg bgr`.
| Method | Path | Description |
|--------|------|-------------|
| GET | `/outputs`, `/outputs/<id>` | List, one |
| POST | `/outputs` | Create (400 with the failed check). Reply: the output, 201 |
| PUT | `/outputs/<id>` | Merge and check again |
| DELETE | `/outputs/<id>` | Delete |
| POST | `/outputs/<id>/test` | Body `{"step_s": 0.1–5}` (default 1): solid red, green, blue and white for `step_s` each at `fps`, then black. `{"message", "status": {name, protocol, kind, pixel_count, frames, packets, bytes, errors, last_error}}`. 503 for `dmx_serial` (no USB-DMX adapter on this board) |
Zones do not render to outputs: only the test pattern is sent.
## WebSocket — `/ws`
On connect the controller sends `{"type": "device_tcp_snapshot", "connected_ips": []}` (there are no Wi-Fi driver sessions). Each text frame is a driver message (JSON object), sent as `/presets/push` would send it: an optional `to` (MAC) addresses one driver, otherwise it is broadcast. A frame that is not a JSON object, or a failed send, gets `{"error": ...}` back. A plain GET gets 426.
## Driver app update — `/drivers/ota`
Pushes led-driver `.py` files to ESP-NOW drivers, one file per request; `tools/driver_ota.py` (`make ota-drivers`) and the editor at `/settings/editor` run a whole session. The firmware embeds the driver files from its build: `/static/driver/manifest.json` lists `{path, sha, size}` and `/static/driver/<path>` serves each. The wire format is in `led-driver/src/espnow_ota.py`. One request runs at a time; another gets 409.
| Method | Path | Description |
|--------|------|-------------|
| POST | `/drivers/ota/file?mac=<macs>&sess=<n>&path=<p>&sha=<64 hex>` | Body: the raw file (up to 65536 bytes). `mac` is a comma-separated list of MACs, or `all` for every ESP-NOW device. `sess` (1–65535) is shared by every file of one update. `path` is the driver path: a root file, `patterns/…` or `lib/…`. Drivers that already have that sha256 skip it. One target gets acked unicast. Several get one broadcast, then each is asked for its missing chunks and repaired. The file is staged until commit. Reply: `{"<mac>": {"result": "same" | "written" | "error", "code"?, "repaired": n}}` |
| POST | `/drivers/ota/commit?mac=<macs>&sess=<n>` | Drivers move their staged files into place, update `file_hashes.json` and reset if anything changed |
| POST | `/drivers/ota/abort?mac=<macs>&sess=<n>` | Drivers delete their staged files |
## Message Format
---
All messages are JSON objects sent via ESPNow with the following structure:
## Driver messages
```json
{
"v": "1",
"presets": { ... },
"select": { ... }
}
```
The UI, `/presets/push`, `/ws` and the controller itself send drivers **v1 messages**: JSON objects with `"v": "1"`. The controller does not send them as they are:
- **Binary envelope.** A message that only carries presets, a select, brightness, `save` and `groups` goes out as a compact binary envelope (`main/envelope.c`, mirrored by `test/binary_envelope.py`).
- Version 2 is the usual frame.
- A frame whose presets use `fade` or `beat_time` is version 3: each preset record is followed by `[ext_len][key, len, value]…`, with key 1 the fade ms (u16) and key 2 the beat timing (u8).
- Drivers skip keys they don't know. Drivers without v3 support ignore v3 frames, so they miss only presets that use the new fields.
- **JSON.** Any other message goes as JSON with short keys, split across several messages when it does not fit one ESP-NOW frame. A preset with a background colour (`bg`) is one of these: the envelope has no field for it.
- **Delivery.** Broadcasts are never acked (envelopes go out twice, JSON once); drivers that miss a state change notice from the state digest and ask to be brought up to date. Messages with `targets` are unicast to each MAC, acked and retried.
### Version Field
### Fields
- **`v`** (required): Message version, must be `"1"`. Messages with other versions are ignored.
## Presets
| Long key | Short | Meaning |
|----------|-------|---------|
| `presets` | `p` | Map of preset id → preset |
| `select` | `s` | `["preset_id"]` or `["preset_id", step]` for every driver addressed; or a map of driver name → that list |
| `groups` | `g` | Only drivers in one of these groups apply the message |
| `set_groups` | `sg` | With `groups`: replace the driver's group list |
| `save` | `sv` | Persist presets, brightness or config on the driver |
| `default` | `df` | Startup preset id |
| `device_config` | `dc` | `name`, `num_leds`, `color_order`, `startup_mode`, `max_brightness`, `reversed`, `place` ([x0, y0, x1, y1] in rig coordinates, see `/devices/layout`; `null` clears it), `usb_log` (per-beat USB log; on reboot). Drivers print nothing over USB unless their `debug` or `usb_log` setting is on: on the ESP32-C3, unread USB output blocks the driver |
| `clear_presets` | `cp` | Drop stored presets |
| `manifest` | `mf` | Pattern files to fetch (Wi-Fi drivers) |
| `b` | | Driver brightness 0–255 |
Presets define LED patterns with their configuration. Each preset has a name and contains pattern-specific settings.
Preset fields: `p`/`pattern`, `c`/`colors` (`#RRGGBB`), `d`/`delay` (ms, default 100), `b`/`brightness` (0–255), `a`/`auto` (`true` runs freely, `false` steps once per beat), `bg`/`background`, `n1`–`n6` (pattern parameters; `n5` is reverse, `n6` the style mode), `f`/`fade`, `tb`/`beat_time`. Other fields (`name`, `manual_beat_n`, …) are dropped on the way out.
### Preset Structure
Sending `select` again with the same preset is a beat for that preset. Selecting `off` resets the step, so the next select starts every driver at step 0 unless a step is given.
```json
{
"presets": {
"preset_name": {
"pattern": "pattern_type",
"colors": ["#RRGGBB", ...],
"delay": 100,
"brightness": 127,
"auto": true,
"n1": 0,
"n2": 0,
"n3": 0,
"n4": 0,
"n5": 0,
"n6": 0
}
}
}
```
### Driver groups
### Preset Fields
A driver keeps a list of group ids and applies a group command (or a message with `groups`) only when it holds one of them. The controller sends each ESP-NOW driver its list whenever groups, zones or devices change, when the driver boots, and when it asks to be brought up to date. A driver that has failed three messages in a row gets these updates at most every 30 s until it answers again. The list holds:
- **`pattern`** (required): Pattern type. Options:
- `"off"` - Turn off all LEDs
- `"on"` - Solid color
- `"blink"` - Blinking pattern
- `"rainbow"` - Rainbow color cycle
- `"pulse"` - Pulse/fade pattern
- `"transition"` - Color transition
- `"chase"` - Chasing pattern
- `"circle"` - Circle loading pattern
- every group (`group` collection) whose `devices` lists the driver's MAC, by group id;
- `z<zone id>` for every zone whose `names` lists the driver's name (zones from before groups);
- its own group `d<mac>` (12 lowercase hex digits), always first, so a sequence target can name a single driver. It doesn't change any other membership.
- **`colors`** (optional): Array of hex color strings (e.g., `"#FF0000"` for red). Default: `["#FFFFFF"]`
- Colors are automatically converted from hex to RGB and reordered based on device color order setting
- Supports multiple colors for patterns that use them
A zone plays to its `group_ids` and, when it names drivers, to `z<zone id>`. A message with `groups` that fits the envelope goes out as one group command per group.
- **`delay`** (optional): Delay in milliseconds between pattern updates. Default: `100`
### Example
- **`brightness`** (optional): Brightness level (0-255). Default: `127`
- **`auto`** (optional): Auto mode flag. Default: `true`
- `true`: Pattern runs continuously
- `false`: Pattern advances one step per beat (manual mode)
- **`n1` through `n6`** (optional): Pattern-specific numeric parameters. Default: `0`
- See pattern-specific documentation below
### Pattern-Specific Parameters
#### Rainbow
- **`n1`**: Step increment (how many color wheel positions to advance per update). Default: `1`
#### Pulse
- **`n1`**: Attack time in milliseconds (fade in)
- **`n2`**: Hold time in milliseconds (full brightness)
- **`n3`**: Decay time in milliseconds (fade out)
- **`delay`**: Delay time in milliseconds (off between pulses)
#### Transition
- **`delay`**: Transition duration in milliseconds
#### Chase
- **`n1`**: Number of LEDs with first color
- **`n2`**: Number of LEDs with second color
- **`n3`**: Movement amount on even steps (can be negative)
- **`n4`**: Movement amount on odd steps (can be negative)
#### Circle
- **`n1`**: Head movement rate (LEDs per second)
- **`n2`**: Maximum length
- **`n3`**: Tail movement rate (LEDs per second)
- **`n4`**: Minimum length
## Select Messages
Select messages control which preset is active on which device. The format uses a list to support step synchronization.
### Select Format
```json
{
"select": {
"device_name": ["preset_name"],
"device_name2": ["preset_name2", step_value]
}
}
```
### Select Fields
- **`select`**: Object mapping device names to selection lists
- **Key**: Device name (as configured in device settings)
- **Value**: List with one or two elements:
- `["preset_name"]` - Select preset (uses default step behavior)
- `["preset_name", step]` - Select preset with explicit step value (for synchronization)
### Step Synchronization
The step value allows precise synchronization across multiple devices:
- **Without step**: `["preset_name"]`
- If switching to different preset: step resets to 0
- If selecting "off" pattern: step resets to 0
- If selecting same preset (beat): step is preserved, pattern restarts
- **With step**: `["preset_name", 10]`
- Explicitly sets step to the specified value
- Useful for synchronizing multiple devices to the same step
### Beat Functionality
Calling `select()` again with the same preset name acts as a "beat" - it restarts the pattern generator:
- **Single-tick patterns** (rainbow, chase in manual mode): Advance one step per beat
- **Multi-tick patterns** (pulse in manual mode): Run through full cycle per beat
Example beat sequence:
```json
// Beat 1
{"select": {"device1": ["rainbow_preset"]}}
// Beat 2 (same preset = beat)
{"select": {"device1": ["rainbow_preset"]}}
// Beat 3
{"select": {"device1": ["rainbow_preset"]}}
```
## Synchronization
### Using "off" Pattern
Selecting the "off" pattern resets the step counter to 0, providing a synchronization point:
```json
{
"select": {
"device1": ["off"],
"device2": ["off"]
}
}
```
After all devices are "off", switching to a pattern ensures they all start from step 0:
```json
{
"select": {
"device1": ["rainbow_preset"],
"device2": ["rainbow_preset"]
}
}
```
### Using Step Parameter
For precise synchronization, use the step parameter:
```json
{
"select": {
"device1": ["rainbow_preset", 10],
"device2": ["rainbow_preset", 10],
"device3": ["rainbow_preset", 10]
}
}
```
All devices will start at step 10 and advance together on subsequent beats.
## Complete Example
```json
{
"v": "1",
"presets": {
"12": {"pattern": "chase", "colors": ["#ff0000", "#0000ff"], "delay": 80, "brightness": 255, "auto": true, "n1": 4, "n2": 4}
"red_blink": {
"pattern": "blink",
"colors": ["#FF0000"],
"delay": 200,
"brightness": 255,
"auto": true
},
"rainbow_manual": {
"pattern": "rainbow",
"delay": 100,
"n1": 2,
"auto": false
},
"pulse_slow": {
"pattern": "pulse",
"colors": ["#00FF00"],
"delay": 500,
"n1": 1000,
"n2": 500,
"n3": 1000,
"auto": false
}
},
"select": ["12"],
"groups": ["3"],
"save": true
"select": {
"device1": ["red_blink"],
"device2": ["rainbow_manual", 0],
"device3": ["pulse_slow"]
}
}
```
Pattern parameters are documented in the led-driver repository.
## Message Processing
1. **Version Check**: Messages with `v != "1"` are rejected
2. **Preset Processing**: Presets are created or updated (upsert behavior)
3. **Color Conversion**: Hex colors are converted to RGB tuples and reordered based on device color order
4. **Selection**: Devices select their assigned preset, optionally with step value
## Best Practices
1. **Always include version**: Set `"v": "1"` in all messages
2. **Use "off" for sync**: Select "off" pattern to synchronize devices before starting patterns
3. **Beats for manual mode**: Send select messages repeatedly with same preset name to advance manual patterns
4. **Step for precision**: Use step parameter when exact synchronization is required
5. **Color format**: Always use hex strings (`"#RRGGBB"`), conversion is automatic
## Error Handling
- Invalid version: Message is ignored
- Missing preset: Selection fails, device keeps current preset
- Invalid pattern: Selection fails, device keeps current preset
- Missing colors: Pattern uses default white color
- Invalid step: Step value is used as-is (may cause unexpected behavior)
## Notes
- Colors are automatically converted from hex strings to RGB tuples
- Color order reordering happens automatically based on device settings
- Step counter wraps around (0-255 for rainbow, unbounded for others)
- Manual mode patterns stop after one step/cycle, waiting for next beat
- Auto mode patterns run continuously until changed
-330
View File
@@ -1,330 +0,0 @@
# Bench test: one S3 controller and one LED driver
This walks one ESP32-S3 controller (W5500 Ethernet, INMP441 mic) and one `led-driver` unit through flashing, a smoke test, a lossy-link test and a beat latency measurement. Nothing here has been run on hardware yet, so treat the expected numbers as targets to check, not results.
## 0. What you need
- Controller: XIAO ESP32-S3 with a W5500 module wired as in `main/Kconfig.projbuild` (SCLK 7, MISO 8, MOSI 9, CS 2, INT 3, RST 1), Ethernet cable to a DHCP network. The mic is optional for this test; the bench generator makes its own beats.
- Driver: one `led-driver` unit (MicroPython, the `p2p` ESP-NOW branch) with a few LEDs. It needs no Wi-Fi network.
- A PC on the same network. Docker with `espressif/idf:v5.5.5` for building.
- For the true latency measurement: a logic analyzer or scope with two channels and a common ground. Optional: the software echo numbers need nothing extra.
**Channel rule.** ESP-NOW only works when both radios use the same channel. The p2p driver uses its `wifi_channel` setting (default 5); the controller's default is now 5 as well (`CONFIG_ESPNOW_CHANNEL` in `sdkconfig.defaults`). If your driver uses another channel, change the controller before building:
```bash
docker run --rm -v "$PWD":/project -w /project espressif/idf:v5.5.5 idf.py menuconfig
```
then *ESP-NOW config → Wi-Fi channel*. Alternatively set `CONFIG_ESPNOW_CHANNEL=<n>` in `sdkconfig.defaults` (delete `sdkconfig` after, so it is regenerated). To use the beat marker pin, also set `CONFIG_BEAT_TEST_GPIO` (for example 44) in the same menu.
## 1. Build and flash the controller
The repository root has a Makefile that wraps all of this: `make build`, `make flash`, `make monitor` (Ctrl-] to quit), `make log` (console for 10 s, no terminal needed), `make test`, and `make help` for the rest; `PORT=/dev/ttyACM1` selects another port. The manual commands below do the same thing.
```bash
tools/build_web.sh
docker run --rm -v "$PWD":/project -w /project espressif/idf:v5.5.5 idf.py build
```
Expect `Project build complete`, the app well under its 2 MB slot, with the web UI embedded (`www_dist/www.pack`). Fix ownership if Docker left it root-owned: `docker run --rm -v "$PWD":/project espressif/idf:v5.5.5 chown -R 0:0 /project`.
Flash with the S3 on USB (check which port it is; `ls /dev/ttyACM*`):
```bash
docker run --rm --device=/dev/ttyACM0 -v "$PWD":/project -w /project espressif/idf:v5.5.5 idf.py -p /dev/ttyACM0 flash
```
This writes the bootloader, partition table and app (the web UI is part of the app). Watch the log:
```bash
docker run --rm -it --device=/dev/ttyACM0 -v "$PWD":/project -w /project espressif/idf:v5.5.5 idf.py -p /dev/ttyACM0 monitor
```
Look for, in order: `store: ... records` lines, `espnow_tx: ESP-NOW up on channel N`, `rel: reliable link up`, `Ethernet Link Up`, `Got IP: x.x.x.x`, `HTTP server started`.
## 2. First checks (replace `$S3` with the IP)
```bash
export S3=192.168.1.50
curl -s http://$S3/status
```
Expect JSON with `uptime_s`, `reset_reason` (why the board last restarted, such as `panic`, `task_watchdog` or `brownout`; opening the USB serial port resets the board and replaces it with `usb`, so read it first), `bpm`, an `espnow` block and a `link` block (`ver` nonzero, `digests` increasing by one about every 1.5 s). If the mic hears music, `bpm` and `beats_sent` move too, which means beats are already being broadcast. Open `http://$S3/` in a browser: the UI should load, and the dev tools network tab should show `Content-Encoding: gzip` on `/static/*.js`.
```bash
curl -s -D - -o /dev/null -H 'Accept-Encoding: gzip' http://$S3/static/presets.js | grep -i -E 'content-encoding|content-type'
```
**Audio and beats.** `http://$S3/audio` is the mic page: live levels, tempo and bar position, a tap button to correct beat 1, and a Listen button for the 16 kHz mono stream. The underlying endpoints are `/audio.wav` (one listener at a time), `/beats` (server-sent events: `beat`, `onset`, `tempo`), `POST /tap` and `/time`. `/status` carries the mic levels (`mic_rms_dbfs`, `mic_spl_db`) and the beat state (`bpm`, `beat_locked`, `meter`, `bar_beat`, `bar_sure`).
## 3. Load data and add a test zone
Import the Pi database (the files hold your real zones and presets, so use a copy if you want a smaller test):
```bash
for n in device zone preset profile palette pattern sequence scene; do
curl -s -X PUT --data-binary @../db/$n.json http://$S3/db/$n; echo " $n"
done
```
The driver registers itself: it broadcasts a hello at boot, the controller adds it to the device list under its MAC and sends it its group list. Check with `curl -s http://$S3/devices/<mac>` once the driver is running (step 4). Zones are the drivers' groups: a zone's `names` must contain the driver's **name** exactly (`led-<mac>` by default, see its `settings.json`).
```bash
curl -s -X POST -d '{"name":"bench","names":["led-aabbccddeeff"]}' http://$S3/zones
curl -s -X POST -d '{"name":"bench red","pattern":"on","colors":["#ff0000"],"delay":100,"brightness":255,"auto":true}' http://$S3/presets
```
Note the returned ids (`<zone>` and `<preset>` below). Creating or changing a zone re-sends group lists to every registered ESP-NOW driver.
## 4. Prepare the driver
The driver runs the `p2p` branch of `led-driver` plus these files from this work: `src/beat_sync.py`, `src/espnow_rx.py`, and changed `src/main.py` and `src/presets.py`. Back up the device's own copies first (`mpremote fs cp :main.py ./main.py.bak`), then copy the new ones (`mpremote fs cp src/main.py :main.py` and so on) and reset.
Optional keys in the driver's `settings.json` for the later tests:
| key | value | meaning |
|---|---|---|
| `bench` | `true` | echo every fired beat to the controller and print stats every 50 beats |
| `beat_pin` | e.g. `5` | GPIO toggled on every fired beat, for the logic analyzer |
| `espnow_loss` | `0` | percent of received frames the driver discards (set later) |
After boot, the controller's `/devices` list should contain the driver's MAC and `/status` should show `link.acked` rising (the group list was acknowledged). `mpremote` interrupts the running program, so reset the driver after using it.
## 5. Smoke test
```bash
curl -s -X POST -d '{"preset_id":"<preset>"}' http://$S3/zones/<zone>/play
```
The driver's console should log the preset and select it received (once each, although the controller sends every state frame twice), and the LEDs should go red within a fraction of a second. Then:
```bash
curl -s -X POST http://$S3/zones/<zone>/stop # LEDs off
curl -s http://$S3/devices/status # last_ack_ms_ago / failed_messages per registered driver
```
Zone play is a group broadcast, so `devices/status` only changes for acked (unicast) traffic. Trigger one with a targeted push:
```bash
curl -s -X POST -d '{"sequence":[{"v":"1","select":{"led-aabbccddeeff":["<preset>"]}}],"targets":["aabbccddeeff"]}' http://$S3/presets/push
curl -s http://$S3/devices/status
```
Expected: `last_ack_ms_ago` is small (tens of ms) and `failed_messages` is 0. `/status` shows `link.acked` increased.
## 6. Lossy-link test
The loss mode discards a percentage of frames before the radio on the controller (all outgoing frames, and incoming acks and echoes). The driver can discard received frames too. This makes the retry, fragment and resync layers do real work without moving antennas.
```bash
# controller: 40% loss, beats included
curl -s -X POST -d '{"percent":40,"beats":true}' http://$S3/test/loss
curl -s http://$S3/status # sim_dropped counts dropped frames
```
Run these and compare with the table:
| test | how | expected |
|---|---|---|
| Acked unicast under loss | repeat the targeted push from step 5 twenty times at 40% (give each a different select step so you can tell them apart on the driver console) | all reach the driver; `link.retransmits` rises. A message needs its data and its ack to both survive, and there are 5 sends in total, so about 1 in 10 is reported as timed out even though the driver usually has it |
| Give up and report | set `percent` to 100, push once, wait 2 s | `link.ack_timeouts` +1 and `devices/status` shows `failed_messages: 1` |
| Lost broadcast, digest recovery | `percent` 100, play a different preset on the zone, then set `percent` 0 | the LEDs do not change at first, then within about 1.5 to 5 s the driver sends a resync and shows the new preset; `link.resyncs` +1 |
| Driver-side loss | set `"espnow_loss": 40` in the driver's `settings.json` (restore it afterwards), controller loss 0, push twenty times | every push is processed once on the driver (retransmissions are de-duplicated); `link.retransmits` rises. Lost acks are covered by the controller-side loss rows above, because that setting also drops incoming acks |
| Multi-message send | `POST /presets/send` with 10+ preset ids, `save: false` and `targets` | the controller packs the presets into a few binary messages (14 presets took 2); all arrive under loss, with retransmits. `save: true` makes the driver write its `presets.json`, so restore that file afterwards. Frame-level fragmentation exists in the link but nothing in the current API produces a message over one frame, so it is only covered by the driver's unit tests |
Set loss back to 0 when done: `curl -s -X POST -d '{"percent":0}' http://$S3/test/loss`.
Reading the numbers: the controller drops a reply with the same probability as a request, so under loss an unicast message needs both the data and the ack to survive. Resync requests are also subject to loss and to the driver's 3 s minimum gap, so recovery may take a few digests.
### Results of the first run (S3 to one p2p driver, channel 5)
| test | result |
|---|---|
| 20 acked pushes, controller loss 40% | 20 of 20 reached the driver; 19 acked, 1 reported timed out (its ack was lost); 19 retransmits; 34 frames dropped by the test mode |
| 1 push, loss 100% | gave up after 2.0 s with 4 retransmits; `failed_messages` 1; driver heard nothing |
| zone play during a 100% outage, then loss back to 0 | driver was untouched during the outage; 1.5 s after the link returned it received its groups, the preset and the select, one resync, and the new state |
| 20 acked pushes, driver-side loss 40% | 20 of 20 processed exactly once; 14 retransmits; 0 timeouts |
| `/presets/send` of 14 presets at driver loss 40% | 2 messages (209 and 217 bytes), both acked, 1 retransmit |
## 7. Beat latency and delivery
### Software numbers (no equipment)
Start synthetic beats with the driver in `bench` mode:
```bash
curl -s -X POST -d '{"bpm":120,"count":200}' http://$S3/test/beats
sleep 105
curl -s http://$S3/test/beats
```
Results include:
- `beats_sent`, `echoes` and `hit_pct_total`: the share of beats each driver fired on and reported. With no loss expect 100%.
- `rtt_minus_lead_min/avg/max_us`: time from the first beat copy going out to the driver's echo coming back, minus the 30 ms the driver deliberately waits (`CONFIG_BEAT_LEAD_MS`). This is out-airtime plus the driver's MicroPython work plus return airtime, so it overstates one-way delay. Expect roughly 2 to 15 ms; the maximum shows the worst case you will see on the LEDs.
- `spread_avg_us` and `spread_max_us`: only meaningful with two or more drivers; shows how far apart they fire for the same beat.
On the driver's serial console every 50 beats you get the true driver-side counts, for example `beat {'fires': 100, 'dups': 100, 'late': 0, 'freerun': 0}`:
- `fires`: beats it acted on.
- `dups`: second copies dropped (with the double send this should be close to `fires`).
- `freerun`: beats it generated itself because both copies were missed. Zero without loss.
- `late`: frames rejected as too soon or old.
### Delivery under loss
Repeat the run with loss on:
```bash
curl -s -X POST -d '{"percent":30,"beats":true}' http://$S3/test/loss
curl -s -X POST -d '{"bpm":120,"count":200}' http://$S3/test/beats
```
Judge delivery from the driver's own `fires` and `freerun` counts: with two copies the chance of missing both is about 9% at 30% loss, and the free-run covers those, so `fires` should stay near `beats_sent` with `freerun` around 9% of it. The controller's `hit_pct_total` is lower because echoes are dropped by the same loss setting; it is a lower bound, roughly `(1 - loss) × delivery`.
### Latency over USB (no extra equipment)
Both boards are on USB, so the PC can timestamp one event line from each and compare them. Settings already applied for this: the driver has `"usb_log": true` in `settings.json`. The controller prints `BT <beat> <microseconds>` for every synthetic beat; the driver prints `FIRE <beat> <ticks_us>` when it fires.
```bash
python3 tools/usb_latency.py --ctrl-port /dev/ttyACM0 --drv-port /dev/ttyACM1 --url http://$S3 --beats 200
```
The script starts the generator, reads both ports, and maps each board's clock onto the PC's by using the fastest USB deliveries per 5 s window (this also removes crystal drift). USB serial delivers in bursts, so single lines arrive up to about 50 ms late; the fastest ones are close to on time, which is what the mapping relies on. The remaining error is the difference between the two ports' fastest delivery, roughly 1 ms, so read results to about a millisecond. The script prints the delivery jitter so you can see how noisy the ports were. The driver's `FIRE` time is when the beat triggers the pattern step; the LED data follows within the same loop pass, and a 119-LED strip takes about 3.6 ms to clock out.
Close any serial monitor first (only one program can hold a port). Do not run long `mpremote exec` commands on the driver during the capture (see Troubleshooting).
### True latency with a logic analyzer
For a measurement that does not depend on USB. Marker pins are set up already: the controller toggles **GPIO44 (D7)** when the first copy of each beat goes out (`CONFIG_BEAT_TEST_GPIO=44`, in `sdkconfig.defaults`) and the driver toggles **GPIO44 (D7)** when it fires (`"beat_pin": 44` in its `settings.json`). Both are XIAO ESP32S3 boards, where D7 is free.
Wiring (3.3 V logic, any 2 or 3 channel analyzer):
| analyzer | connect to |
|---|---|
| GND | GND on the controller **and** GND on the driver (one common ground) |
| channel 0 | controller **D7** |
| channel 1 | driver **D7** |
| channel 2 (optional) | driver **D10** (GPIO9, the LED data line) to see when the LEDs really update |
Steps:
1. Make sure the driver runs a preset that changes on every beat if you use channel 2, for example a `chase` preset with `auto` off, selected on the zone. With the plain `on` preset the LED data line stays quiet.
2. Start a capture: sample rate at least 1 MS/s, length at least 60 s (edges only; it stays small), trigger on any edge of channel 0.
3. Start the beats: `curl -s -X POST -d '{"bpm":120,"count":100}' http://$S3/test/beats`. Both markers toggle on every beat, so you will see edges 500 ms apart.
4. Stop the capture when the generator finishes (about 52 s) and export the digital data as CSV (time in seconds, one column per channel).
5. Analyze: `python3 tools/analyze_edges.py capture.csv --ctrl 0 --drv 1 --time-unit s`. Use `--lead-ms` if you changed `CONFIG_BEAT_LEAD_MS`. It pairs each controller edge with the next driver edge and prints the delay beyond the 30 ms lead, with min, mean, median, p95, max and jitter, plus the count of unmatched beats. On the scope, channel 2 shows the true light delay: the first data burst after the driver edge.
Targets from the plan: under about 10 ms from the controller edge to the driver edge (after subtracting the lead).
Return to normal use by deleting `beat_pin` and `usb_log` from the driver's `settings.json` and setting `CONFIG_BEAT_TEST_GPIO=-1` (the marker pin otherwise toggles on every beat, including live mic beats).
### Results of the first run (software numbers, one driver, channel 5)
Synthetic beats at 120 BPM, 160 beats per run, mic beats muted while the generator runs, driver in `bench` mode.
| | no loss | 30% loss (beats included) |
|---|---|---|
| beats the driver acted on, per beat sent | 1.00 | 1.00 |
| beats the driver invented itself (free-run) | 0% | 11% (theory for two independent copies: 9%) |
| second copies dropped as duplicates | 100% | 47% (theory: 49%) |
| echoes the controller received | 162 of 162 | 96 of 161 (echoes are lost at 30% too, and invented beats do not echo) |
| round trip minus the 30 ms lead, min / avg / max | 9.8 / 15.0 / 25.7 ms | 3.4 / 16.2 / 26.0 ms |
Reading it: the double send plus free-run gave the driver a beat every time, even with 30% of frames lost. The round-trip figure includes the driver's loop and the echo's trip back, so it is an upper bound on the delay the LEDs see; it is not the controller-to-LED latency. The USB and logic analyzer measurements below give the real figure.
Latency over USB (200 beats at 120 BPM, one driver, 119 LEDs): delay beyond the 30 ms lead min 0.49, mean 2.07, median 1.77, p95 4.41, max 7.95 ms (std 1.3 ms; accuracy about 1 ms). 197 of 200 beats matched. Both clocks drifted by 60 to 80 ppm against the PC, and individual USB lines arrived up to 54 ms late, which is why the script uses the fastest deliveries. This is the time from the controller sending a beat to the driver firing, beyond the built-in lead. The logic analyzer run has not been done.
### ESP32-C3 driver compared with the S3 driver
Driver: XIAO ESP32-C3 (MAC 58:8c:81:a3:74:58), MicroPython v1.22.1 stock (no ws2812-dma patch), 160 MHz, about 128 KB free heap, 119 LEDs on pin 10. Same tests as above, same controller.
| | S3 driver, no loss | C3 driver, no loss |
|---|---|---|
| echoes the controller received | 162 of 162 | 160 of 160 |
| round trip minus the 30 ms lead, min / avg / max | 9.8 / 15.0 / 25.7 ms | 2.6 / 4.5 / 17.8 ms |
C3 with 30% loss (160 beats): every beat produced exactly one pattern step, 15 of the 160 (9%, theory 9%) came from free-run, and 68 second copies were dropped as duplicates; the controller got 99 of 160 echoes. That matches the S3 result in the table above.
Reading the free-run counter: after the generator stops, the driver keeps stepping for up to 4 more beats on its last period. A stats window that runs past the end of the test therefore shows 4 extra "free-run" fires even with no loss. They are not missed beats. (My first read of the C3's no-loss run said otherwise; that was wrong.)
Latency over USB, same settings on both boards (`usb_log` only), 200 beats at 120 BPM, delay beyond the 30 ms lead, accuracy about 1 ms:
| | matched | min | mean | median | p95 | max | std |
|---|---|---|---|---|---|---|---|
| S3 driver (240 MHz) | 200 / 200 | -2.4 | 2.15 | 2.03 | 6.03 | 12.3 | 2.5 ms |
| C3 driver (160 MHz) | 200 / 200 | 0.2 | 3.36 | 3.06 | 7.47 | 19.7 | 2.3 ms |
The C3 is about 1.2 ms slower on average and has a longer tail (maximum 19.7 ms against 12.3 ms). With the method's 1 ms accuracy, the mean difference is small and the tail difference is the more telling one. Both are well inside a 120 BPM beat. The echo round trip disagrees with this (S3 15 ms mean, C3 4.5 ms). The S3 echo runs had `usb_log` and a marker pin switched on and the C3 runs did not, and I did not rerun the S3 echo test with identical settings, so treat the echo figures as unexplained and prefer the USB ones.
Pattern frame rate (strip writes per second, 119 LEDs, delay 1 ms, 2 s each; only patterns that wrote anything are shown):
| pattern | C3 (160 MHz, 115 KB free) | S3 (240 MHz, 8 MB free) |
|---|---|---|
| flame | 22 | 33 |
| palette_morph | 21 | 32 |
| circle | 150 | 170 |
The CPU-heavy patterns run about 1.5 times faster on the S3, which is the clock ratio; a light pattern is limited by the strip write and differs by about 13%. `aurora` and `chase` wrote nothing with the parameters I used, so they are not measured.
Groups: the controller sends a driver its group list when the driver announces itself, but now only if the driver is in at least one zone. A driver in no zone keeps the groups it already has (an empty list from the controller used to wipe them). An explicit zone or device edit still re-sends every list, including empty ones.
**Wi-Fi start-up order on the C3.** With the extra link code loaded before Wi-Fi start-up, the C3 failed with `Wifi Unknown Error 0x0101` on about every other cold boot (2 of 4). Starting ESP-NOW before the pattern library and the LED driver claim memory fixed it (6 of 6 boots). `led-driver/src/main.py` now does this.
## 8. Driver app update over ESP-NOW
Pushes the led-driver `.py` files from the PC, through the controller, to the drivers. The drivers need `espnow_ota.py` first, so install the code once over USB (`led-cli -p <port> --all`). After that:
```bash
python3 tools/driver_ota.py $S3 --mac <mac> --dry-run # list the files and drivers, send nothing
python3 tools/driver_ota.py $S3 --mac <mac> # one driver
make ota-drivers HOST=$S3 BROADCAST=1 # every ESP-NOW driver, one broadcast and repairs
```
Each file prints `written`, or nothing when the driver already has it. Drivers that received files reset after the commit, and the script waits for them to ack the link again. `--bad-sha <device path>` sends a wrong hash for one file, to test the abort path.
| Check | Expected |
|---|---|
| Push with nothing changed | every file skipped, no reset |
| Edit one pattern, push | only that file written; the driver resets, comes back and runs the new code; `file_hashes.json` has the new hash |
| `--bad-sha patterns/<file>.py` | `ERROR badhash` and `aborted:`; no `.new` files left on the driver and the old file unchanged |
| Controller loss at 20% (`beats: false`) | still completes, slower, with `+n repaired` on some files |
| `--broadcast` with two or more drivers | each changed file is sent once to all of them; afterwards every driver still acks and fires beats |
### Results of the first run (S3 controller, two C3 drivers with 119 LEDs, channel 5)
| | result |
|---|---|
| 62 files, nothing changed | all skipped in about 7 s (about 110 ms per file, mostly the driver hashing its copy), no reset |
| One changed pattern (7.3 KB) | written and committed; driver reset and acked again; content and manifest checked over USB |
| 60 KB file, unicast | 4.6 s, 12.8 KB/s including both hash checks |
| 60 KB file, unicast, 20% controller loss | 4 of 4 runs completed, 3.8 to 8.3 KB/s |
| Wrong hash | `badhash`, aborted, nothing staged or committed |
| 60 KB file, broadcast to both | 4.2 s, about 14 KB/s per driver (29 KB/s in total), usually no repairs (once 3) |
| 60 KB file, broadcast to both, 20% loss | 2 of 2 completed in about 33 s; 33 to 58 of the 65 chunks needed a repair (each chunk is 4 frames with no radio retries) |
| Beat echo round trip after the change to `esp.irq()`, 177 beats, two drivers | 2.4 / 5.5 / 23.5 ms (min / avg / max) beyond the 30 ms lead, against 9.8 / 15.0 / 25.7 ms when the driver polled; 176 of 177 echoed |
**Broadcast pacing.** With 12 ms between broadcast chunks (about 30 KB/s) the drivers stopped receiving ESP-NOW frames altogether. Their `esp.stats()` receive count froze, with no drops counted, while the controller's unicasts were still acked by the drivers' radios. It lasted until a reset, more than 5 minutes once, and beats stopped too. The likely cause is the C3 writing to flash while the frames keep coming. At 50 ms (`BCAST_GAP_MS` in `main/drv_ota.c`) it did not happen in 5 runs.
## 9. Troubleshooting
- **A board on a USB-serial/JTAG port (C3, and the S3 controller) resets whenever a program opens its port,** and a C3 can land in ROM download mode (`wait usb download`). The old apt `mpremote` 0.4.0 hangs on this. Use the newer one in `~/projects/micropython/micropython/tools/mpremote/mpremote.py`, or `led-tool`, and note that `fs cp -r` fails on drivers that print timestamps (copy named files instead).
- **Only one program can use a board's serial port at a time.** A serial logger left running while `led-cli` uploads corrupts the transfer silently: `led-cli` reports the files uploaded, but the old ones stay on the driver.
- **Running a long `mpremote exec` on the driver resets it:** the driver's watchdog (10 s) keeps running after `mpremote` interrupts `main.py`, so keep REPL experiments under about 8 s and reset the driver afterwards.
- **Driver never reacts, no acks:** channel mismatch. Check `CONFIG_ESPNOW_CHANNEL` against the driver's `wifi_channel`. Neighbouring channels can still work at bench range, so a working link does not prove they match.
- **Zone play logs nothing on the driver:** the driver is not in the zone's group (silent). Check the zone's `names` against the driver's `name`.
- **Devices show `last_ack_ms_ago: -1`:** the device record has no usable 12-character MAC in `address` or as its key.
- **`beats_sent` rises but `echoes` stays 0:** the driver is not in `bench` mode, or it has not yet heard a controller frame (it learns the controller's MAC from the first data or digest frame; wait a few seconds).
- **Resync never triggers:** the driver ignores a digest equal to its own version; confirm with `/status` that `link.ver` changed after the missed play.
- **Web UI is blank:** the web UI was not packed before the build; run `tools/build_web.sh` and build again (`make build` does this).
## 10. Cleanup
```bash
curl -s -X POST -d '{"percent":0}' http://$S3/test/loss
curl -s -X POST http://$S3/test/beats/stop
```
Set the driver's `bench` and `espnow_loss` back to off for normal use.
+46 -81
View File
@@ -1,14 +1,13 @@
# LED Driver System - Specification Document
**Version:** 1.1
**Date:** October 2026
**Version:** 1.0
**Date:** December 2025
**Status:** Draft
## Table of Contents
1. [Overview](#overview)
2. [System Architecture](#system-architecture)
- [Raspberry Pi Controller and Animation Engine](#raspberry-pi-controller-and-animation-engine)
3. [User Interface Specifications](#user-interface-specifications)
4. [Feature Specifications](#feature-specifications)
5. [Preset System](#preset-system)
@@ -45,7 +44,7 @@ The LED Driver system is a MicroPython-based application for controlling LED str
- Pattern configuration and control (patterns run on remote devices)
- Real-time brightness and speed control
- Global brightness setting (system-wide brightness multiplier)
- Multi-colour support with customizable colour palettes
- Multi-color support with customizable color palettes
- Device grouping for synchronized control
- Preset system for saving and loading pattern configurations
- Profile and Scene system for complex lighting setups
@@ -55,11 +54,6 @@ The LED Driver system is a MicroPython-based application for controlling LED str
- Persistent settings storage (usqlite database)
- Web-based configuration interface (Microdot web server)
- SQLite database for presets and event logging
- **Raspberry Pi controller** (`src/`): Microdot web app with JSON-file storage (`db/*.json`) managing profiles, zones, presets, palettes, scenes, sequences and outputs
- **Pi-side animation engine** (`src/engine/`): renders the unchanged driver patterns on the Pi and streams pixels over DDP, Art-Net, sACN (E1.31) or USB-DMX
- **Preset sequencer**: timed preset chains per zone, resumed after restart
- Server-wide global brightness (0-255) pushed to drivers, including on Wi-Fi reconnect
- Search filter in the Devices, Zones and Presets lists
---
@@ -231,29 +225,6 @@ The LED Driver system uses a master/slave architecture where one device acts as
---
## Raspberry Pi Controller and Animation Engine
The current deployment adds a Raspberry Pi running the web app (`src/main.py`, Microdot on CPython). It is the authoritative store and UI host; ESP32 firmware is unchanged. Full route detail is in `docs/API.md`.
**Outbound paths**
- Serial → ESP-NOW bridge (JSON lines over UART).
- Wi-Fi drivers: TCP JSON lines (port 8765 on the Pi; drivers discover the Pi via UDP 8766 broadcast).
- Pixel outputs rendered by the Pi engine (below).
**Data model (`db/*.json`):** profile, zone, preset, palette, pattern, device, scene, sequence, output. A zone's `names` list holds ESP32 device names and/or output names.
### Animation Engine (`src/engine/`)
- **Pixel generator:** loads `led-driver/src/patterns/*.py` unmodified under CPython (`utime` shim plus a NeoPixel-like buffer) and runs one render thread per zone from the same preset JSON the drivers receive. Static frames are re-sent as keepalive.
- **Output drivers:** DDP (UDP 4048), Art-Net (ArtDMX/ArtSync, UDP 6454), sACN/E1.31 (UDP 5568, multicast or unicast), USB-DMX (Enttec DMX USB Pro or Open DMX). 170 RGB pixels per universe, consecutive universes for longer strips. A preset output for our ESP32 drivers (`outputs/driver.py`) reuses the existing preset + `select` path.
- **Output record** (`db/output.json`): `name`, `protocol`, `host`, `port`, `universe`, `serial_port`, `dmx_mode`, `channel`, `pixel_count`, `pixel_offset`, `color_order`, `reverse`, `brightness` (0-255, multiplied by global brightness), `fps` (default 40), `enabled`. CRUD and a test pattern (R, G, B, W, off) at `/outputs`.
- **Zone playback:** `POST /zones/<id>/play` renders a preset on every target and sends `select` to ESP32 drivers; `POST /zones/<id>/stop` blanks pixel outputs. `GET /zones/engine/status` reports per-zone and per-output counters.
- **Sequencer:** a sequence is `{name, zone_id, loop, repeat_count, steps: [{preset_id, duration_s}], active}`. `duration_s` is clamped to 0.5-600 s (default 5); steps are hard cuts; `repeat_count` of 0 loops forever. Deadline-based scheduling, `active` sequences resume after restart, manual preset selection on a zone stops its sequence. Legacy records (`group_name`, `presets`, `sequence_duration` ms) are migrated on load. Scenes start/stop the sequences they list (`/scenes/<id>/play`, `/stop`).
- **CLI:** `python -m engine.cli --output "ddp://host?pixels=300" --test | --preset N | --pattern NAME` (terminal preview when no output is given).
- **UI:** Outputs and Sequences modals (edit mode), preset tiles drive pixel outputs, header brightness slider, list search filters.
---
## User Interface Specifications
### 1. Dashboard (Main Control Panel)
@@ -268,7 +239,7 @@ Primary interface for real-time LED control and monitoring.
- **Grid Layout:** 4-column responsive grid
- Pattern Selection Card
- Brightness & Speed Card
- Colour Selection Card
- Color Selection Card
- Device Status Card
- **Action Bar:** Apply and Save buttons
@@ -302,12 +273,12 @@ Primary interface for real-time LED control and monitoring.
- **Default:** 100ms
- **Step:** 10ms increments
**Colour Selection**
- **Type:** Colour picker inputs (HTML5 colour input)
- **Quantity:** Multiple colours (minimum 2, expandable)
- **Format:** Hex colour codes (e.g., #FF0000)
- **Display:** Large colour swatches (60x60px)
- **Action:** "Add Colour" button for additional colours
**Color Selection**
- **Type:** Color picker inputs (HTML5 color input)
- **Quantity:** Multiple colors (minimum 2, expandable)
- **Format:** Hex color codes (e.g., #FF0000)
- **Display:** Large color swatches (60x60px)
- **Action:** "Add Color" button for additional colors
**Device Status List**
- **Type:** List of connected devices
@@ -324,7 +295,7 @@ Primary interface for real-time LED control and monitoring.
- **Save to Device:** Persist settings to device storage
#### Design Specifications
- **Colour Scheme:** Purple gradient background (#667eea to #764ba2)
- **Color Scheme:** Purple gradient background (#667eea to #764ba2)
- **Cards:** White background, rounded corners (12px), shadow
- **Hover Effects:** Card lift (translateY -2px), increased shadow
- **Typography:** System font stack, 1.25rem headings
@@ -379,10 +350,10 @@ Manage connected devices and create/manage device groups.
#### Layout
- **Header:** Title with "Add Device" button
- **Zones:** Devices and Groups zones (zone buttons / zone strip)
- **Content Area:** Zone-specific content
- **Tabs:** Devices and Groups tabs
- **Content Area:** Tab-specific content
#### Devices Zone
#### Devices Tab
**Device List**
- **Display:** List of all known devices
@@ -404,7 +375,7 @@ Manage connected devices and create/manage device groups.
- **Actions:** Cancel, Save
- **Note:** Only one master device per system. Adding a new master will demote existing master to slave.
#### Groups Zone
#### Groups Tab
**Group List**
- **Display:** List of all device groups
@@ -426,7 +397,7 @@ Manage connected devices and create/manage device groups.
- **Actions:** Cancel, Create
#### Design Specifications
- **Zone Style:** Active zone has purple background, white text
- **Tab Style:** Active tab has purple background, white text
- **List Items:** Bordered cards with hover effects
- **Modal:** Centered overlay with white card, shadow
- **Status Badges:** Colored pills (green for online, red for offline)
@@ -538,7 +509,7 @@ Comprehensive device configuration interface.
- Device Name (text input)
- LED Pin (number input, 0-40)
- Number of LEDs (number input, 1-1000)
- Colour Order (visual selector with 6 options: RGB, RBG, GRB, GBR, BRG, BGR)
- Color Order (visual selector with 6 options: RGB, RBG, GRB, GBR, BRG, BGR)
**2. Pattern Settings**
- Pattern (dropdown selection)
@@ -606,16 +577,16 @@ Comprehensive device configuration interface.
- Range: Slider with real-time value display
- Select: Dropdown menu
- Checkbox: Toggle switch
- Colour: HTML5 colour picker
- Color: HTML5 color picker
**Colour Order Selector**
**Color Order Selector**
- **Type:** Visual button grid
- **Options:** RGB, RBG, GRB, GBR, BRG, BGR
- **Display:** Colour boxes showing order (R=red, G=green, B=blue)
- **Display:** Color boxes showing order (R=red, G=green, B=blue)
- **Selection:** Single selection with visual feedback
#### Design Specifications
- **Section Headers:** Purple colour (#667eea), 1.5rem font, bottom border
- **Section Headers:** Purple color (#667eea), 1.5rem font, bottom border
- **Form Groups:** 24px spacing between fields
- **Labels:** Bold, 500 weight, dark gray (#333)
- **Help Text:** Small gray text below inputs
@@ -640,7 +611,7 @@ Save, load, and manage preset configurations for quick pattern switching.
Each preset card displays:
- **Name:** Preset name (bold, 1.25rem)
- **Pattern Badge:** Current pattern type
- **Colour Preview:** Swatches showing preset colours
- **Color Preview:** Swatches showing preset colors
- **Quick Info:** Delay and brightness values
- **Actions:** Apply, Edit, Delete buttons
@@ -649,7 +620,7 @@ Each preset card displays:
**Fields:**
- Preset Name (text input, required)
- Pattern (dropdown selection)
- Colours (multiple colour pickers, minimum 2)
- Colors (multiple color pickers, minimum 2)
- Delay (slider, 10-1000ms)
- Step Offset (number input, optional, default: 0)
- Tooltip: "Step offset for group synchronization. Applied per device when preset is used in a group."
@@ -696,7 +667,7 @@ Each preset card displays:
#### Design Specifications
- **Card Style:** White background, rounded corners, shadow
- **Pattern Badge:** Colored pill with pattern name
- **Colour Swatches:** 40x40px squares in card header
- **Color Swatches:** 40x40px squares in card header
- **Hover Effect:** Card lift, border highlight
- **Selected State:** Purple border, subtle background tint
@@ -710,7 +681,7 @@ Patterns are configured on the controller and sent to remote devices for executi
- **Pattern Type:** Identifier for the pattern (e.g., "on", "off", "blink", "chase", "pulse", "rainbow", etc.)
- **Pattern Parameters:** Numeric parameters (N1-N8) that configure pattern-specific behavior
- **Colours:** Colour palette for the pattern
- **Colors:** Color palette for the pattern
- **Timing:** Delay and speed settings
**Note:** Pattern execution happens on the remote devices. The controller sends configuration commands to devices.
@@ -727,7 +698,7 @@ Pattern-specific numeric parameters:
#### Overview
Presets allow users to save complete pattern configurations for quick recall and application. A preset encapsulates all pattern settings including pattern type, colours, timing, and all pattern parameters.
Presets allow users to save complete pattern configurations for quick recall and application. A preset encapsulates all pattern settings including pattern type, colors, timing, and all pattern parameters.
**Note:** Presets are optional. Devices can be controlled directly without presets.
@@ -737,7 +708,7 @@ A preset contains the following fields:
- **name** (string, required): Unique identifier for the preset
- **pattern** (string, required): Pattern type identifier (sent to remote devices)
- **colours** (array of strings, required): Array of hex colour codes (minimum 2 colours)
- **colors** (array of strings, required): Array of hex color codes (minimum 2 colors)
- **delay** (integer, required): Delay in milliseconds (10-1000)
- **n1** (integer, optional): Pattern parameter 1 (0-255, default: 0)
- **n2** (integer, optional): Pattern parameter 2 (0-255, default: 0)
@@ -918,7 +889,7 @@ A preset contains the following fields:
#### Group Properties
- **Name:** Unique group identifier
- **Devices:** List of device names (can include master and/or slaves)
- **Settings:** Pattern, delay, colours
- **Settings:** Pattern, delay, colors
- **Step Offset:** Per-device step offset sent to devices for synchronized patterns (integer, can be negative)
- Each device in group can receive different step offset
- Creates wave/chase effect across multiple LED strips
@@ -982,7 +953,7 @@ Byte 1: Flags (bit 0: names, bit 1: groups, bit 2: settings, bit 3: save)
|-----|------|-------------|--------------|
| `pt` | string | Pattern type | on, off, blink, chase, circle, pulse, rainbow, transition |
| `pm` | string | Pattern mode | auto, single_shot |
| `cl` | array | Colours (hex strings) | Array of hex colour codes |
| `cl` | array | Colors (hex strings) | Array of hex color codes |
| `br` | int | Global brightness | 0-100 |
| `dl` | int | Delay (ms) | 10-1000 |
| `n1` | int | Parameter 1 | 0-255 |
@@ -995,7 +966,7 @@ Byte 1: Flags (bit 0: names, bit 1: groups, bit 2: settings, bit 3: save)
| `n8` | int | Parameter 8 | 0-255 |
| `led_pin` | int | GPIO pin | 0-40 |
| `num_leds` | int | LED count | 1-1000 |
| `color_order` | string | Colour order | rgb, rbg, grb, gbr, brg, bgr |
| `color_order` | string | Color order | rgb, rbg, grb, gbr, brg, bgr |
| `name` | string | Device name | Any string |
| `brightness` | int | Global brightness | 0-100 |
| `delay` | int | Delay | 10-1000 |
@@ -1276,7 +1247,7 @@ CREATE TABLE IF NOT EXISTS presets (
**Preset Fields:**
- `name` (string, required): Unique preset identifier
- `pattern` (string, required): Pattern type
- `colors` (array of strings, required): Hex colour codes (minimum 2)
- `colors` (array of strings, required): Hex color codes (minimum 2)
- `delay` (integer, required): Delay in milliseconds (10-1000)
- `n1` through `n8` (integer, optional): Pattern parameters (0-255, default: 0)
@@ -1318,7 +1289,7 @@ CREATE TABLE IF NOT EXISTS presets (
**POST /api/presets**
- Create a new preset
- Body: Preset object (name, pattern, colours, delay, n1-n8)
- Body: Preset object (name, pattern, colors, delay, n1-n8)
- Response: Created preset object
**GET /api/presets/{name}**
@@ -1524,7 +1495,7 @@ peak_mem = usqlite.mem_peak()
### Flow 2: Create Device Group
1. User navigates to Device Management → Groups zone
1. User navigates to Device Management → Groups tab
2. User clicks "Create Group", enters name, selects pattern/settings
3. User selects devices to add (can include master), clicks "Create"
4. Group appears in list
@@ -1535,7 +1506,7 @@ peak_mem = usqlite.mem_peak()
1. User navigates to Settings page
2. User modifies settings in sections:
- Basic Settings (pin, LED count, colour order)
- Basic Settings (pin, LED count, color order)
- Pattern Settings (pattern, delay)
- Global Brightness
- Advanced Settings (N1-N8 parameters)
@@ -1548,7 +1519,7 @@ peak_mem = usqlite.mem_peak()
### Flow 4: Multi-Device Control
1. User selects multiple devices or a group
2. User changes pattern/colours/global brightness
2. User changes pattern/colors/global brightness
3. User clicks "Apply Settings"
4. System sends message targeting selected devices/groups
5. All targeted devices update simultaneously
@@ -1604,19 +1575,17 @@ peak_mem = usqlite.mem_peak()
### Flow 8: Sequence Between Presets
*(Implemented by the Pi-side sequencer; see Animation Engine.)*
1. User plays a sequence (or a scene that lists it) on a zone
2. Pi applies the first step: renders it to the zone's pixel outputs and sends the preset + `select` to its ESP32 drivers
3. After `duration_s` expires, the sequencer hard-cuts to the next step
4. Process repeats for all steps; loops forever or for `repeat_count` passes
5. Continues until stopped, the zone is played manually, or the app restarts (active sequences then resume)
1. Scene activated with group having multiple presets
2. Master applies first preset to itself (if in group), sends to slaves
3. After duration expires, master transitions to next preset with fade effect
4. Process repeats for all presets, loops if enabled
5. Continues until scene changes or manual stop
---
## Design Guidelines
### Colour Palette
### Color Palette
- **Primary:** Purple gradient `#667eea` to `#764ba2`, Light gradient `#f5f7fa` to `#c3cfe2`
- **UI:** Primary `#667eea`, Hover `#5568d3`, Secondary `#e0e0e0`
@@ -1643,8 +1612,8 @@ peak_mem = usqlite.mem_peak()
- Disabled: 50% opacity, no pointer events
**Inputs:**
- Focus: Border colour changes to primary purple
- Hover: Slight border colour change
- Focus: Border color changes to primary purple
- Hover: Slight border color change
- Error: Red border
**Cards:**
@@ -1680,10 +1649,6 @@ peak_mem = usqlite.mem_peak()
- Any length (1-1000 LEDs supported)
- 5V power supply (external)
**Raspberry Pi (controller):**
- Python 3.x, runs the web app and animation engine
- Optional: Wi-Fi/Ethernet to DDP, Art-Net or sACN fixtures; USB-DMX adapter (Enttec DMX USB Pro / Open DMX)
**Host Computer:**
- Python 3.x
- pipenv for dependency management
@@ -1773,7 +1738,7 @@ peak_mem = usqlite.mem_peak()
- Validation
**Preset Management:**
- Preset creation with all fields (name, pattern, colours, delay, n1-n8)
- Preset creation with all fields (name, pattern, colors, delay, n1-n8)
- Preset loading and application
- Preset editing and deletion
- Name uniqueness validation
@@ -1793,7 +1758,7 @@ peak_mem = usqlite.mem_peak()
- Configuration parameters are properly formatted
**Preset Application:**
- Preset loads all parameters correctly (pattern, colours, delay, n1-n8)
- Preset loads all parameters correctly (pattern, colors, delay, n1-n8)
- Preset applies to single device
- Preset applies to device group
- Preset values match saved configuration
@@ -1809,7 +1774,7 @@ peak_mem = usqlite.mem_peak()
- Buttons respond to clicks
- Sliders update values
- Modals open/close
- Zone buttons switch correctly
- Tabs switch correctly
- Preset selector works
- Preset creation form validates input
- Preset cards display correctly
-118
View File
@@ -1,118 +0,0 @@
# LED controller — user guide
This page describes the web UI served by the controller (an ESP32-S3 on Ethernet). It covers profiles, zones, presets, device groups, sequences and audio. The controller reaches the LED drivers over ESP-NOW itself, so there is no bridge to set up.
For HTTP routes and the driver message format, see **[API.md](API.md)**. For building and flashing, see the project **README**.
Figures below are **schematic** (layout and ideas), not pixel-perfect screenshots.
---
## Run mode and Edit mode
**Edit mode** is in the header and **Run mode** is in the **Menu** (on narrow screens, both are in the Menu). The **label on the button is the mode you switch to**.
![Schematic: zone buttons on the left; Profiles, Help and Menu on the right.](images/help/header-toolbar.svg)
| Mode | Purpose |
|------|--------|
| **Run mode** | Day-to-day control: choose a zone, tap presets, apply profiles. The setup actions are hidden. |
| **Edit mode** | Full setup from the **Menu**: devices, groups, outputs, sequences, zones, presets, patterns, colour palette, audio and settings, plus per-tile **Edit** on the strip. |
On narrow screens, **Menu** also holds the header actions, so it is there in Run mode too.
---
## Zones
- **Select a zone**: click its button in the top bar. The main area shows the zone's preset strip.
- **Zones** (Edit mode): create and manage zones. A zone lists **device groups**, presets and sequences; presets and sequences can share a zone. **Right-click** a zone button for its settings.
- A zone plays to its device groups. Zones made before groups list drivers by **name** instead, and still work.
- **Brightness slider**: sets the brightness for the current zone. Each driver gets one value: global × its groups × the device × the zone.
- **Search**: the Devices, Zones and Presets lists have a search box that hides rows that do not match as you type.
![Schematic: zone title, brightness slider, and a row of preset tiles; Edit mode adds an Edit control and drag handles.](images/help/tab-preset-strip.svg)
Click the coloured part of a preset tile to select that preset on every driver in the zone. In Edit mode, drag tiles to reorder them, and use **Edit** and **Remove** on each tile.
---
## Presets
The **Presets** button (Edit mode) opens the profile's presets: **Add**, **Edit**, **Send**, **Delete**, plus **Import** and **Export** (a preset as a JSON file).
![Schematic: preset editor with name, pattern, colour swatches (one with a P badge for palette-linked), and action buttons.](images/help/preset-editor.svg)
The preset editor:
- **Pattern** and its **n1–n8** parameters, colours, background, brightness and delay.
- **Manual** presets step once per beat instead of running freely.
- **From Palette** inserts a colour linked to the profile's palette (badge **P**). It follows the palette when the palette changes.
- **Try** previews on the current zone without saving on the drivers.
- **Save** stores the preset on the controller; **Send** pushes it to the drivers with save.
- **Remove from zone** (when opened from a zone) removes it from that zone only.
---
## Profiles
- **Apply** makes a profile current. Zones, presets and sequences you see belong to it.
- **Create** (Edit mode) gives a new profile a palette and a **default** zone with starter presets. Optionally tick **DJ zone** for a starter `dj` zone.
- **Clone** copies a profile with its own zones, presets and palette. **Delete** removes it with its presets and sequences.
- **Export** saves a profile with its zones, presets, sequences and palette as a JSON file. **Import** loads one as a new profile and applies it.
---
## Devices and groups
- **Devices** (Edit mode) lists the LED drivers by name; **Edit** shows a driver's MAC. Drivers appear by themselves when they boot or answer a ping; you can also add them by hand.
- **Ping drivers** checks which drivers answer (green dot with the round-trip time) and adds new ones.
- **Identify** blinks a driver red for two seconds.
- **Update groups** sends every driver its group membership.
- **Edit** a device for its name, brightness, driver settings (LED count, colour order, power-on pattern) and the groups it is in.
- **Groups** (Edit mode): put drivers in a group, set the group's brightness and driver defaults once, then attach the group to zones and sequence lanes.
- Groups are shared by every profile unless you tick **this profile only**.
- **Identify** on a device, in the group or in the list to add from, blinks just that driver; **Identify devices in group** blinks all members together.
---
## Sequences
**Sequences** (Edit mode) are shows of presets in one or more **lanes**. Each lane plays to its own device group.
- **Steps.** A step is a preset and a number of beats. When a step's beats have passed, the lane moves to its next step. A sequence loops unless you turn looping off.
- **Playing.** Attach a sequence to a zone in the zone editor, then play it from the zone. One sequence plays at a time. Stopping a sequence clears its presets from the zone's drivers.
- **Switching.** Starting another sequence waits for the next beat, or the next downbeat when the header toggle says **Downbeat** and the microphone is timing.
- **Syncing.** Press **S** (or the BPM button) on a downbeat to line the sequence up with the music.
---
## Audio
- The controller listens through its microphone and detects the tempo and the bar.
- **Audio** is in the Menu in Edit mode. While it is started, the microphone's beats time sequences and go to the drivers, so manual presets step on the music.
- While it is stopped, a clock at the **simulated BPM** does both instead.
- **Reset detector** forgets a stuck tempo. The **/audio** page has a full readout, a tap for beat 1 and a live listen.
---
## Patterns, outputs and palette
- **Patterns** (Edit mode) lists the patterns and their typical delays. **Send** pushes a pattern file to the drivers over ESP-NOW; they reset to load it. **Create pattern** uploads your own pattern file.
- **Outputs** (Edit mode) lists network pixel fixtures (DDP, Art-Net, sACN). **Test** flashes red, green, blue and white, then black. Zones do not drive outputs on this controller.
- **Colour Palette** (Edit mode) edits the current profile's swatches. Preset colours linked with **From Palette** update with it.
![Schematic: palette modal with a row of swatches for the current profile.](images/help/colour-palette.svg)
---
## Settings
**Settings** (Edit mode) holds the controller's name, the ESP-NOW channel (for reference: the controller's channel is set at build time), a **Wi-Fi access point** switch (on by default; network named after the hostname, with an optional WPA2 password, controller at `192.168.5.1`; holding the button on D3 at boot forces it on), its mDNS **hostname** and the **static IPs** it tries on the Ethernet link (DHCP when none answers). With no DHCP server, as on a cable straight to a PC, the controller is at `192.168.4.1`; give the PC a static IP such as `192.168.4.2`. Network changes apply after a restart. **Driver** in Settings sends a driver its name, LED count, colour order, startup mode, maximum brightness and direction over ESP-NOW, with no cable. **Update code** there sends a driver, or all of them, the led-driver code built into the controller. `led-cli` on a computer edits a driver's whole `settings.json` over USB.
![Schematic: narrow layout with Menu and the same header actions in a dropdown.](images/help/mobile-menu.svg)
---
## Further reading
- **[API.md](API.md)**: HTTP routes, the WebSocket `/ws`, and the driver message format.
- **README**: building, flashing and updating the controller and drivers.
BIN
View File
Binary file not shown.
-14
View File
@@ -1,14 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 480 140" width="480" height="140">
<title>Colour Palette modal (concept)</title>
<rect width="480" height="140" fill="#2a2a2a" stroke="#555" stroke-width="1" rx="6"/>
<text x="20" y="28" fill="#fff" font-family="sans-serif" font-size="15" font-weight="600">Colour Palette</text>
<text x="20" y="48" fill="#888" font-family="sans-serif" font-size="10">Profile: current profile name</text>
<rect x="20" y="58" width="44" height="44" rx="4" fill="#e53935" stroke="#333"/>
<rect x="72" y="58" width="44" height="44" rx="4" fill="#fdd835" stroke="#333"/>
<rect x="124" y="58" width="44" height="44" rx="4" fill="#43a047" stroke="#333"/>
<rect x="176" y="58" width="44" height="44" rx="4" fill="#1e88e5" stroke="#333"/>
<rect x="228" y="58" width="44" height="44" rx="4" fill="#8e24aa" stroke="#333"/>
<rect x="280" y="70" width="36" height="28" rx="3" fill="#1a1a1a" stroke="#666"/>
<text x="288" y="88" fill="#ccc" font-family="sans-serif" font-size="10">+</text>
<text x="20" y="122" fill="#aaa" font-family="sans-serif" font-size="10">Swatches belong to the profile; preset editor uses them via From Palette.</text>
</svg>

Before

Width:  |  Height:  |  Size: 1.2 KiB

-20
View File
@@ -1,20 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 820 108" width="820" height="108">
<title>Header: tab buttons and action bar</title>
<rect width="820" height="108" fill="#1a1a1a"/>
<rect x="0" y="106" width="820" height="2" fill="#4a4a4a"/>
<text x="16" y="28" fill="#888" font-family="sans-serif" font-size="11">Tabs</text>
<rect x="16" y="40" width="72" height="36" rx="4" fill="#333" stroke="#666" stroke-width="1"/>
<text x="34" y="63" fill="#ccc" font-family="sans-serif" font-size="13">default</text>
<rect x="96" y="40" width="88" height="36" rx="4" fill="#2a4a7a" stroke="#5a8fd4" stroke-width="2"/>
<text x="108" y="63" fill="#fff" font-family="sans-serif" font-size="13">lounge</text>
<rect x="192" y="40" width="56" height="36" rx="4" fill="#333" stroke="#666" stroke-width="1"/>
<text x="204" y="63" fill="#ccc" font-family="sans-serif" font-size="13">dj</text>
<text x="380" y="28" fill="#888" font-family="sans-serif" font-size="11">Actions (Edit mode)</text>
<rect x="380" y="40" width="72" height="30" rx="3" fill="#3d3d3d" stroke="#555" stroke-width="1"/>
<text x="396" y="59" fill="#e0e0e0" font-family="sans-serif" font-size="11">Profiles</text>
<rect x="458" y="40" width="52" height="30" rx="3" fill="#3d3d3d" stroke="#555" stroke-width="1"/>
<text x="470" y="59" fill="#e0e0e0" font-family="sans-serif" font-size="11">Help</text>
<rect x="516" y="40" width="60" height="30" rx="3" fill="#3d3d3d" stroke="#555" stroke-width="1"/>
<text x="530" y="59" fill="#e0e0e0" font-family="sans-serif" font-size="11">Menu</text>
<text x="16" y="98" fill="#aaa" font-family="sans-serif" font-size="10">Active tab highlighted. Run mode is in the Menu.</text>
</svg>

Before

Width:  |  Height:  |  Size: 1.7 KiB

-26
View File
@@ -1,26 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 340" width="300" height="340" role="img" aria-labelledby="t">
<title id="t">Narrow screen: Menu aggregates header actions</title>
<rect width="300" height="340" fill="#2e2e2e"/>
<rect x="0" y="0" width="300" height="52" fill="#1a1a1a"/>
<rect x="12" y="12" width="56" height="28" rx="4" fill="#3d3d3d" stroke="#555" stroke-width="1"/>
<text x="22" y="30" fill="#eee" font-family="DejaVu Sans, Liberation Sans, Arial, sans-serif" font-size="12">Menu �</text>
<rect x="76" y="14" width="52" height="24" rx="4" fill="#333" stroke="#666" stroke-width="1"/>
<text x="86" y="30" fill="#ccc" font-family="DejaVu Sans, Liberation Sans, Arial, sans-serif" font-size="11">tab</text>
<rect x="136" y="14" width="52" height="24" rx="4" fill="#2a4a7a" stroke="#5a8fd4" stroke-width="1"/>
<text x="142" y="30" fill="#fff" font-family="DejaVu Sans, Liberation Sans, Arial, sans-serif" font-size="11">tab</text>
<rect x="12" y="60" width="276" height="168" rx="4" fill="#252525" stroke="#4a4a4a" stroke-width="1"/>
<text x="24" y="84" fill="#888" font-family="DejaVu Sans, Liberation Sans, Arial, sans-serif" font-size="10">Dropdown (same actions as desktop header)</text>
<g font-family="DejaVu Sans, Liberation Sans, Arial, sans-serif" font-size="12" fill="#e8e8e8">
<text x="24" y="108">Run mode</text>
<text x="24" y="132">Profiles</text>
<text x="24" y="156">Tabs</text>
<text x="24" y="180">Presets</text>
<text x="24" y="204">Help</text>
</g>
<rect x="12" y="240" width="276" height="80" rx="6" fill="#222" stroke="#444" stroke-width="1"/>
<text x="24" y="268" fill="#aaa" font-family="DejaVu Sans, Liberation Sans, Arial, sans-serif" font-size="10">Content area  presets as on desktop</text>
<rect x="24" y="278" width="80" height="32" rx="4" fill="#333" stroke="#555"/>
<text x="36" y="298" fill="#ddd" font-family="DejaVu Sans, Liberation Sans, Arial, sans-serif" font-size="11">preset</text>
<rect x="112" y="278" width="80" height="32" rx="4" fill="#333" stroke="#555"/>
<text x="124" y="298" fill="#ddd" font-family="DejaVu Sans, Liberation Sans, Arial, sans-serif" font-size="11">preset</text>
</svg>

Before

Width:  |  Height:  |  Size: 2.2 KiB

-31
View File
@@ -1,31 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 520 400" width="520" height="400">
<title>Preset editor modal (simplified)</title>
<rect width="520" height="400" fill="#1e1e1e"/>
<rect x="40" y="28" width="440" height="344" rx="8" fill="#2a2a2a" stroke="#555" stroke-width="1"/>
<text x="60" y="58" fill="#fff" font-family="DejaVu Sans,Liberation Sans,Arial,sans-serif" font-size="17" font-weight="600">Preset</text>
<text x="60" y="86" fill="#aaa" font-family="DejaVu Sans,Liberation Sans,Arial,sans-serif" font-size="11">Name</text>
<rect x="60" y="92" width="200" height="28" rx="3" fill="#1a1a1a" stroke="#444" stroke-width="1"/>
<text x="72" y="111" fill="#ddd" font-family="DejaVu Sans,Liberation Sans,Arial,sans-serif" font-size="12">evening glow</text>
<text x="280" y="86" fill="#aaa" font-family="DejaVu Sans,Liberation Sans,Arial,sans-serif" font-size="11">Pattern</text>
<rect x="280" y="92" width="160" height="28" rx="3" fill="#1a1a1a" stroke="#444" stroke-width="1"/>
<text x="292" y="111" fill="#ddd" font-family="DejaVu Sans,Liberation Sans,Arial,sans-serif" font-size="12">pulse</text>
<text x="60" y="148" fill="#aaa" font-family="DejaVu Sans,Liberation Sans,Arial,sans-serif" font-size="11">Colours</text>
<rect x="60" y="156" width="48" height="48" rx="4" fill="#7e57c2" stroke="#333" stroke-width="1"/>
<circle cx="66" cy="162" r="8" fill="#3f51b5" stroke="#fff" stroke-width="1"/>
<text x="63" y="166" fill="#fff" font-family="DejaVu Sans,Liberation Sans,Arial,sans-serif" font-size="7" font-weight="700">P</text>
<rect x="116" y="156" width="48" height="48" rx="4" fill="#26a69a" stroke="#333" stroke-width="1"/>
<text x="176" y="184" fill="#888" font-family="DejaVu Sans,Liberation Sans,Arial,sans-serif" font-size="10">P = palette-linked</text>
<text x="60" y="232" fill="#aaa" font-family="DejaVu Sans,Liberation Sans,Arial,sans-serif" font-size="11">Brightness, delay, n1-n8</text>
<rect x="60" y="238" width="120" height="24" rx="3" fill="#1a1a1a" stroke="#444" stroke-width="1"/>
<text x="68" y="254" fill="#888" font-family="DejaVu Sans,Liberation Sans,Arial,sans-serif" font-size="11">0-255</text>
<text x="60" y="290" fill="#aaa" font-family="DejaVu Sans,Liberation Sans,Arial,sans-serif" font-size="10">Actions</text>
<rect x="60" y="298" width="44" height="26" rx="3" fill="#444" stroke="#666" stroke-width="1"/>
<text x="72" y="315" fill="#eee" font-family="DejaVu Sans,Liberation Sans,Arial,sans-serif" font-size="11">Try</text>
<rect x="112" y="298" width="56" height="26" rx="3" fill="#444" stroke="#666" stroke-width="1"/>
<text x="120" y="315" fill="#eee" font-family="DejaVu Sans,Liberation Sans,Arial,sans-serif" font-size="11">Default</text>
<rect x="176" y="298" width="88" height="26" rx="3" fill="#3d5a80" stroke="#5a7ab8" stroke-width="1"/>
<text x="188" y="315" fill="#fff" font-family="DejaVu Sans,Liberation Sans,Arial,sans-serif" font-size="11">Save+Send</text>
<rect x="272" y="298" width="48" height="26" rx="3" fill="#444" stroke="#666" stroke-width="1"/>
<text x="284" y="315" fill="#eee" font-family="DejaVu Sans,Liberation Sans,Arial,sans-serif" font-size="11">Close</text>
<text x="60" y="352" fill="#888" font-family="DejaVu Sans,Liberation Sans,Arial,sans-serif" font-size="9">Try: preview without device save. Save+Send: store and push with save.</text>
</svg>

Before

Width:  |  Height:  |  Size: 3.3 KiB

-35
View File
@@ -1,35 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 800 220" width="800" height="220">
<title>Main area: brightness and preset tiles</title>
<defs>
<linearGradient id="rg1" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" style="stop-color:#ffd54f"/><stop offset="100%" style="stop-color:#fff8e1"/>
</linearGradient>
<linearGradient id="rg2" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" style="stop-color:#e53935"/><stop offset="33%" style="stop-color:#fdd835"/>
<stop offset="66%" style="stop-color:#43a047"/><stop offset="100%" style="stop-color:#1e88e5"/>
</linearGradient>
<linearGradient id="rg3" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" style="stop-color:#00897b"/><stop offset="100%" style="stop-color:#4db6ac"/>
</linearGradient>
</defs>
<rect width="800" height="220" fill="#2e2e2e"/>
<text x="20" y="32" fill="#fff" font-family="sans-serif" font-size="16" font-weight="600">lounge</text>
<text x="20" y="56" fill="#aaa" font-family="sans-serif" font-size="11">Brightness (global)</text>
<rect x="20" y="64" width="320" height="8" rx="4" fill="#444"/>
<rect x="20" y="64" width="200" height="8" rx="4" fill="#6a9ee2"/>
<circle cx="220" cy="68" r="10" fill="#ccc" stroke="#333" stroke-width="1"/>
<text x="360" y="74" fill="#888" font-family="sans-serif" font-size="11">drag to adjust</text>
<text x="20" y="108" fill="#aaa" font-family="sans-serif" font-size="11">Click tile body to select on tab devices</text>
<rect x="20" y="118" width="200" height="72" rx="6" fill="#252525" stroke="#555" stroke-width="1"/>
<rect x="28" y="128" width="184" height="36" rx="4" fill="url(#rg1)"/>
<text x="32" y="180" fill="#eee" font-family="sans-serif" font-size="13" font-weight="600">warm white</text>
<rect x="232" y="118" width="200" height="72" rx="6" fill="#252525" stroke="#6a9ee2" stroke-width="2"/>
<rect x="240" y="128" width="184" height="36" rx="4" fill="url(#rg2)"/>
<text x="244" y="180" fill="#eee" font-family="sans-serif" font-size="13" font-weight="600">rainbow</text>
<rect x="444" y="118" width="200" height="72" rx="6" fill="#252525" stroke="#555" stroke-width="1"/>
<rect x="452" y="128" width="184" height="36" rx="4" fill="url(#rg3)"/>
<text x="456" y="180" fill="#eee" font-family="sans-serif" font-size="13" font-weight="600">chase</text>
<rect x="656" y="130" width="56" height="48" rx="4" fill="#3d3d3d" stroke="#555" stroke-width="1"/>
<text x="670" y="158" fill="#ddd" font-family="sans-serif" font-size="11">Edit</text>
<text x="656" y="198" fill="#888" font-family="sans-serif" font-size="10">Edit mode: drag tiles to reorder</text>
</svg>

Before

Width:  |  Height:  |  Size: 2.6 KiB

+19 -19
View File
@@ -1,13 +1,13 @@
# Custom Colour Picker Component
# Custom Color Picker Component
A cross-platform, cross-browser colour picker component that provides a consistent user experience across all operating systems and browsers.
A cross-platform, cross-browser color picker component that provides a consistent user experience across all operating systems and browsers.
## Features
✅ **Consistent UI** - Same appearance and behavior on Windows, macOS, Linux, iOS, and Android
✅ **Browser Support** - Works in Chrome, Firefox, Safari, Edge, Opera, and mobile browsers
✅ **Touch Support** - Full touch/gesture support for mobile devices
✅ **HSB Colour Model** - Uses Hue, Saturation, Brightness for intuitive colour selection
✅ **HSB Color Model** - Uses Hue, Saturation, Brightness for intuitive color selection
✅ **Multiple Input Methods** - Hex input, RGB inputs, and visual picker
✅ **Accessible** - Keyboard accessible and screen reader friendly
✅ **Customizable** - Easy to style and integrate
@@ -33,7 +33,7 @@ A cross-platform, cross-browser colour picker component that provides a consiste
<div id="my-color-picker"></div>
```
### 3. Initialize the colour picker
### 3. Initialize the color picker
```javascript
const picker = new ColorPicker('#my-color-picker', {
@@ -57,8 +57,8 @@ new ColorPicker(container, options)
- `options` (object) - Configuration options
**Options:**
- `initialColor` (string) - Initial colour in hex format (default: '#FF0000')
- `onColorChange` (function) - Callback when colour changes (receives hex colour string)
- `initialColor` (string) - Initial color in hex format (default: '#FF0000')
- `onColorChange` (function) - Callback when color changes (receives hex color string)
- `showHexInput` (boolean) - Show hex input field (default: true)
### Methods
@@ -101,7 +101,7 @@ const picker = new ColorPicker('#picker1', {
});
```
### Multiple Colour Pickers
### Multiple Color Pickers
```javascript
const colors = ['#FF0000', '#00FF00', '#0000FF'];
@@ -116,7 +116,7 @@ const pickers = colors.map((color, index) => {
});
```
### Dynamic Colour Picker Creation
### Dynamic Color Picker Creation
```javascript
function addColorPicker(containerId, initialColor = '#000000') {
@@ -139,12 +139,12 @@ addColorPicker('color-2', '#00FF00');
## Styling
The colour picker uses CSS classes that can be customized:
The color picker uses CSS classes that can be customized:
- `.color-picker-container` - Main container
- `.color-picker-preview` - Colour preview button
- `.color-picker-preview` - Color preview button
- `.color-picker-panel` - Dropdown panel
- `.color-picker-main` - Main colour area
- `.color-picker-main` - Main color area
- `.color-picker-hue` - Hue slider
- `.color-picker-controls` - Controls section
@@ -183,20 +183,20 @@ The colour picker uses CSS classes that can be customized:
- ✅ iOS 12+
- ✅ Android 7+
## Colour Format
## Color Format
The colour picker uses **hex colour format** (`#RRGGBB`):
The color picker uses **hex color format** (`#RRGGBB`):
- Always returns uppercase hex strings (e.g., `#FF0000`)
- Accepts both uppercase and lowercase input
- Automatically validates hex format
## Integration with LED Driver Mockups
The colour picker is integrated into:
- `dashboard.html` - Colour selection for patterns
- `presets.html` - Colour selection when creating/editing presets
The color picker is integrated into:
- `dashboard.html` - Color selection for patterns
- `presets.html` - Color selection when creating/editing presets
### Example: Getting Colours from Multiple Pickers
### Example: Getting Colors from Multiple Pickers
```javascript
const colorPickers = [];
@@ -218,7 +218,7 @@ function sendColorsToDevice() {
## Performance
- Lightweight: ~14KB JavaScript, ~4KB CSS
- Fast rendering: Uses Canvas API for colour gradients
- Fast rendering: Uses Canvas API for color gradients
- Smooth interactions: Optimized event handling
- Memory efficient: No external dependencies
@@ -235,5 +235,5 @@ Part of the LED Driver project. Use freely in your projects.
## Demo
See `color-picker-demo.html` for a live demonstration of the colour picker component.
See `color-picker-demo.html` for a live demonstration of the color picker component.
+14 -14
View File
@@ -67,7 +67,7 @@
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.zone {
.tab {
flex: 1;
padding: 12px 24px;
border: none;
@@ -78,16 +78,16 @@
transition: all 0.2s;
}
.zone.active {
.tab.active {
background: #667eea;
color: white;
}
.zone-content {
.tab-content {
display: none;
}
.zone-content.active {
.tab-content.active {
display: block;
}
@@ -249,12 +249,12 @@
</div>
<div class="tabs">
<button class="zone active" onclick="switchTab('devices')">Devices</button>
<button class="zone" onclick="switchTab('groups')">Groups</button>
<button class="tab active" onclick="switchTab('devices')">Devices</button>
<button class="tab" onclick="switchTab('groups')">Groups</button>
</div>
<!-- Devices Zone -->
<div id="devices-zone" class="zone-content active">
<!-- Devices Tab -->
<div id="devices-tab" class="tab-content active">
<div class="card">
<h2>Connected Devices</h2>
<div class="device-item">
@@ -313,8 +313,8 @@
</div>
</div>
<!-- Groups Zone -->
<div id="groups-zone" class="zone-content">
<!-- Groups Tab -->
<div id="groups-tab" class="tab-content">
<div class="card">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
<h2>Groups</h2>
@@ -386,12 +386,12 @@
</div>
<script>
function switchTab(zone) {
document.querySelectorAll('.zone').forEach(t => t.classList.remove('active'));
document.querySelectorAll('.zone-content').forEach(c => c.classList.remove('active'));
function switchTab(tab) {
document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
event.target.classList.add('active');
document.getElementById(zone + '-zone').classList.add('active');
document.getElementById(tab + '-tab').classList.add('active');
}
function showAddDeviceModal() {
+25 -18
View File
@@ -1,23 +1,30 @@
{
"g":{
"df": {
"grps": [
{
"n": "group1",
"pt": "on",
"cl": ["#ff0000"],
"br": 200,
"n1": 10,
"n2": 10,
"n3": 10,
"n4": 10,
"n5": 10,
"n6": 10,
"dl": 100
"cl": [
"000000",
"000000"
],
"br": 100,
"dl": 100,
"n1": 0,
"n2": 0,
"n3": 0,
"n4": 0,
"n5": 0,
"n6": 0
},
"dj": {
"pt": "blink",
"cl": ["#00ff00"],
"dl": 500
{
"n": "group2",
"pt": "on",
"cl": [
"000000",
"000000"
],
"br": 100,
"dl": 100
}
},
"sv": true,
"st": 0
]
}
-7
View File
@@ -1,7 +0,0 @@
# espnow-sender
Minimal MicroPython project for receiving JSON over Microdot WebSocket.
- WebSocket endpoint: `/ws`
- Entry point: `main.py`
- Message template: `msg.json`
-120
View File
@@ -1,120 +0,0 @@
import asyncio
import json
from microdot import Microdot
from microdot.websocket import WebSocketError, with_websocket
import espnow
import network
from util import format_mac, parse_mac
app = Microdot()
_esp = None
_known_peers = set()
_ws_clients = set()
def _init_espnow():
global _esp
sta = network.WLAN(network.STA_IF)
sta.active(True)
_esp = espnow.ESPNow()
_esp.active(True)
def _validate_envelope(obj):
if obj.get("v") != "1":
raise ValueError("message.v must be '1'")
devices = obj["devices"]
for address in devices.keys():
parse_mac(address)
return obj
def _send_espnow(address, payload):
if _esp is None:
raise ValueError("espnow is not initialized")
mac = parse_mac(address)
msg = json.dumps(payload, separators=(",", ":")).encode("utf-8")
if mac not in _known_peers:
_esp.add_peer(mac)
_known_peers.add(mac)
_esp.send(mac, msg)
return mac, len(msg)
async def _broadcast_ws(obj):
text = json.dumps(obj)
dead = []
for client in list(_ws_clients):
try:
await client.send(text)
except Exception:
dead.append(client)
for client in dead:
_ws_clients.discard(client)
async def _espnow_receive_loop():
while True:
host, msg = _esp.recv(0)
if not host:
await asyncio.sleep(0.01)
continue
await _broadcast_ws(
{
"from": format_mac(host),
"payload": msg.decode("utf-8"),
}
)
@app.route("/ws")
@with_websocket
async def ws(request, ws):
_ws_clients.add(ws)
while True:
try:
raw = await ws.receive()
except WebSocketError:
break
if not raw:
break
try:
parsed = json.loads(raw)
env = _validate_envelope(parsed)
sent = []
for address, payload in env["devices"].items():
mac, payload_size = _send_espnow(address, payload)
sent.append(
{
"address": format_mac(mac),
"bytes": payload_size,
}
)
except (ValueError, TypeError) as e:
await ws.send(json.dumps({"ok": False, "error": str(e)}))
continue
await ws.send(
json.dumps(
{
"ok": True,
"sent": sent,
}
)
)
_ws_clients.discard(ws)
async def main(port=80):
_init_espnow()
asyncio.create_task(_espnow_receive_loop())
await app.start_server(host="0.0.0.0", port=port)
if __name__ == "__main__":
asyncio.run(main(port=80))
-24
View File
@@ -1,24 +0,0 @@
{
"v": "1",
"devices": {
"ff:ff:ff:ff:ff:ff": {
"presets": {
"preset_id": {
"pattern": "on",
"colors": ["#FF0000"],
"delay": 100,
"brightness": 255,
"auto": true
}
},
"select": {
"preset": "preset_id",
"step": 0
},
"save": true,
"default": "preset_id",
"b": 255
}
}
}
-12
View File
@@ -1,12 +0,0 @@
def parse_mac(value):
raw = value.strip().lower().replace(":", "").replace("-", "")
if len(raw) != 12:
raise ValueError("address must be 12 hex chars or aa:bb:cc:dd:ee:ff")
try:
return bytes.fromhex(raw)
except ValueError:
raise ValueError("address contains non-hex characters")
def format_mac(mac_bytes):
return ":".join("{:02x}".format(b) for b in mac_bytes)
Executable
+244
View File
@@ -0,0 +1,244 @@
#!/usr/bin/env sh
set -eu
# Environment variables:
# PORT - serial port (default: /dev/ttyUSB0)
# BAUD - baud rate (default: 460800)
# FIRMWARE - local path to firmware .bin
# FW_URL - URL to download firmware if FIRMWARE not provided or missing
PORT=${PORT:-}
BAUD=${BAUD:-460800}
CHIP=${CHIP:-esp32} # esp32 | esp32c3
# Map chip-specific settings
ESPT_CHIP="$CHIP"
FLASH_OFFSET=0x1000
DEFAULT_DOWNLOAD_PAGE="https://micropython.org/download/ESP32/"
BOARD_ID="ESP32_GENERIC"
BOARD_PAGE="https://micropython.org/download/${BOARD_ID}/"
case "$CHIP" in
esp32c3)
ESPT_CHIP="esp32c3"
FLASH_OFFSET=0x0
DEFAULT_DOWNLOAD_PAGE="https://micropython.org/download/ESP32C3/"
BOARD_ID="ESP32_GENERIC_C3"
BOARD_PAGE="https://micropython.org/download/${BOARD_ID}/"
;;
esp32)
ESPT_CHIP="esp32"
FLASH_OFFSET=0x1000
DEFAULT_DOWNLOAD_PAGE="https://micropython.org/download/ESP32/"
BOARD_ID="ESP32_GENERIC"
BOARD_PAGE="https://micropython.org/download/${BOARD_ID}/"
;;
*)
echo "Unsupported CHIP: $CHIP (supported: esp32, esp32c3)" >&2
exit 1
;;
esac
# Download-only mode: fetch the appropriate firmware and exit
if [ -n "${DOWNLOAD_ONLY:-}" ]; then
# Prefer resolving latest if nothing provided
if [ -z "${FIRMWARE:-}" ] && [ -z "${FW_URL:-}" ]; then
LATEST=1
fi
if ! resolve_firmware; then
echo "Failed to resolve firmware for CHIP=$CHIP" >&2
exit 1
fi
echo "$FIRMWARE"
exit 0
fi
# Helper: resolve the latest firmware URL for a given board pattern with multiple fallbacks
resolve_latest_url() {
board_pattern="$1" # e.g., ESP32_GENERIC_C3-.*\.bin
# Candidate pages to try in order
pages="${BOARD_PAGE} ${DOWNLOAD_PAGE:-$DEFAULT_DOWNLOAD_PAGE} https://micropython.org/download/ https://micropython.org/resources/firmware/"
for page in $pages; do
echo "Trying to resolve latest from $page" >&2
html=$(curl -fsSL -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36' -e 'https://micropython.org/download/' "$page" || true)
[ -z "$html" ] && continue
# Prefer matching the board pattern
url=$(printf "%s" "$html" \
| sed -n 's/.*href=\"\([^\"]*\.bin\)\".*/\1/p' \
| grep -E "$board_pattern" \
| head -n1)
if [ -n "$url" ]; then
case "$url" in
http*) echo "$url"; return 0 ;;
/*) echo "https://micropython.org$url"; return 0 ;;
*) echo "$page$url"; return 0 ;;
esac
fi
done
return 1
}
# If LATEST is set and neither FIRMWARE nor FW_URL are provided, auto-detect latest URL
if [ -n "${LATEST:-}" ] && [ -z "${FIRMWARE:-}" ] && [ -z "${FW_URL:-}" ]; then
# Default board identifiers for each chip
case "$CHIP" in
esp32c3) BOARD_ID="ESP32_GENERIC_C3" ;;
esp32) BOARD_ID="ESP32_GENERIC" ;;
*) BOARD_ID="ESP32_GENERIC" ;;
esac
pattern="${BOARD_ID}-.*\\.bin"
echo "Resolving latest firmware for $BOARD_ID"
if FW_URL=$(resolve_latest_url "$pattern"); then
export FW_URL
echo "Latest firmware resolved to: $FW_URL"
else
echo "Failed to resolve latest firmware for pattern $pattern" >&2
exit 1
fi
fi
# Resolve firmware path, downloading if needed
resolve_firmware() {
if [ -z "${FIRMWARE:-}" ]; then
if [ -n "${FW_URL:-}" ] || [ -n "${LATEST:-}" ]; then
# If FW_URL still unset, resolve latest using board-specific pattern
if [ -z "${FW_URL:-}" ]; then
case "$CHIP" in
esp32c3) BOARD_ID="ESP32_GENERIC_C3" ;;
esp32) BOARD_ID="ESP32_GENERIC" ;;
*) BOARD_ID="ESP32_GENERIC" ;;
esac
pattern="${BOARD_ID}-.*\\.bin"
echo "Resolving latest firmware for $BOARD_ID"
if ! FW_URL=$(resolve_latest_url "$pattern"); then
echo "Failed to resolve latest firmware for pattern $pattern" >&2
exit 1
fi
fi
mkdir -p .cache
FIRMWARE=".cache/$(basename "$FW_URL")"
if [ ! -f "$FIRMWARE" ]; then
echo "Downloading firmware from $FW_URL to $FIRMWARE"
curl -L --fail -o "$FIRMWARE" "$FW_URL"
else
echo "Firmware already downloaded at $FIRMWARE"
fi
else
# Default fallback: fetch latest using board-specific pattern
case "$CHIP" in
esp32c3) BOARD_ID="ESP32_GENERIC_C3" ;;
esp32) BOARD_ID="ESP32_GENERIC" ;;
*) BOARD_ID="ESP32_GENERIC" ;;
esac
pattern="${BOARD_ID}-.*\\.bin"
echo "No FIRMWARE or FW_URL specified. Auto-fetching latest for $BOARD_ID"
if ! FW_URL=$(resolve_latest_url "$pattern"); then
echo "Failed to resolve latest firmware for pattern $pattern" >&2
exit 1
fi
mkdir -p .cache
FIRMWARE=".cache/$(basename "$FW_URL")"
if [ ! -f "$FIRMWARE" ]; then
echo "Downloading firmware from $FW_URL to $FIRMWARE"
curl -L --fail -o "$FIRMWARE" "$FW_URL"
else
echo "Firmware already downloaded at $FIRMWARE"
fi
fi
else
if [ ! -f "$FIRMWARE" ]; then
if [ -n "${FW_URL:-}" ]; then
mkdir -p "$(dirname "$FIRMWARE")"
echo "Firmware not found at $FIRMWARE. Downloading from $FW_URL"
curl -L --fail -o "$FIRMWARE" "$FW_URL"
else
echo "Firmware file not found: $FIRMWARE. Provide FW_URL to download automatically." >&2
exit 1
fi
fi
fi
}
# Auto-detect PORT if not specified
if [ -z "$PORT" ]; then
candidates="$(ls /dev/tty/ACM* /dev/tty/USB* 2>/dev/null || true)"
# Some systems expose without /dev/tty/ prefix patterns; try common Linux paths
[ -z "$candidates" ] && candidates="$(ls /dev/ttyACM* /dev/ttyUSB* 2>/dev/null || true)"
# Prefer ACM (often for C3) then USB
PORT=$(printf "%s\n" $candidates | grep -E "/dev/ttyACM[0-9]+" | head -n1 || true)
[ -z "$PORT" ] && PORT=$(printf "%s\n" $candidates | grep -E "/dev/ttyUSB[0-9]+" | head -n1 || true)
if [ -z "$PORT" ]; then
echo "No serial port detected. Connect the board and set PORT=/dev/ttyACM0 (or /dev/ttyUSB0)." >&2
exit 1
fi
echo "Auto-detected PORT=$PORT"
fi
# Preflight: ensure port exists
if [ ! -e "$PORT" ]; then
echo "Port $PORT does not exist. Detected candidates:" >&2
ls /dev/ttyACM* /dev/ttyUSB* 2>/dev/null || true
exit 1
fi
ESPL="python -m esptool"
detect_chip() {
# Try to detect actual connected chip using esptool and override if needed
out=$($ESPL --port "$PORT" --baud "$BAUD" chip_id 2>&1 || true)
case "$out" in
*"ESP32-C3"*) DETECTED_CHIP=esp32c3 ;;
*"ESP32"*) DETECTED_CHIP=esp32 ;;
*) DETECTED_CHIP="" ;;
esac
if [ -n "$DETECTED_CHIP" ] && [ "$DETECTED_CHIP" != "$ESPT_CHIP" ]; then
echo "Detected chip $DETECTED_CHIP differs from requested $ESPT_CHIP. Using detected chip."
ESPT_CHIP="$DETECTED_CHIP"
case "$ESPT_CHIP" in
esp32c3) FLASH_OFFSET=0x0 ;;
esp32) FLASH_OFFSET=0x1000 ;;
esac
fi
}
detect_chip
# Now that we know the actual chip, resolve the correct firmware for it
resolve_firmware
# Validate firmware matches detected chip; if not, auto-correct by fetching the right image
EXPECTED_BOARD_ID="ESP32_GENERIC"
case "$ESPT_CHIP" in
esp32c3) EXPECTED_BOARD_ID="ESP32_GENERIC_C3" ;;
esp32) EXPECTED_BOARD_ID="ESP32_GENERIC" ;;
esac
FW_BASENAME="$(basename "$FIRMWARE")"
case "$FW_BASENAME" in
${EXPECTED_BOARD_ID}-*.bin) : ;; # ok
*)
echo "Firmware $FW_BASENAME does not match detected chip ($ESPT_CHIP). Fetching correct image for $EXPECTED_BOARD_ID..."
pattern="${EXPECTED_BOARD_ID}-.*\\.bin"
if ! FW_URL=$(resolve_latest_url "$pattern"); then
echo "Failed to resolve a firmware matching $EXPECTED_BOARD_ID" >&2
exit 1
fi
mkdir -p .cache
FIRMWARE=".cache/$(basename "$FW_URL")"
if [ ! -f "$FIRMWARE" ]; then
echo "Downloading firmware from $FW_URL to $FIRMWARE"
curl -L --fail -o "$FIRMWARE" "$FW_URL"
else
echo "Firmware already downloaded at $FIRMWARE"
fi
;;
esac
$ESPL --chip "$ESPT_CHIP" --port "$PORT" --baud "$BAUD" erase_flash
echo "Writing firmware $FIRMWARE to $FLASH_OFFSET..."
$ESPL --chip "$ESPT_CHIP" --port "$PORT" --baud "$BAUD" write_flash -z "$FLASH_OFFSET" "$FIRMWARE"
echo "Done."
Executable
+4
View File
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
# Install script - runs pipenv install
pipenv install "$@"
Submodule led-driver deleted from 97df6e3cbe.
Submodule led-simulator deleted from 4fc3345fc9.
Submodule led-tool deleted from 892ccaec71.
-123
View File
@@ -1,123 +0,0 @@
// Parametric LED bar vertical stand socket
// For a bar nominally 14 x 17 mm, 2 m long.
// This part is intended to be screwed to an MDF base.
// -------------------------
// User parameters
// -------------------------
bar_w = 14; // Bar width (mm)
bar_d = 17; // Bar depth (mm)
clearance = 0.4; // Total clearance added to each axis (mm)
socket_height = 36; // Height of printed socket body (mm)
wall = 3.2; // Socket wall thickness (mm)
base_thickness = 5; // Printed bottom plate thickness (mm)
// USB cable/connector side opening
usb_notch_enable = true;
usb_notch_w = 11;
usb_notch_h = 9;
usb_notch_from_bottom = 6;
usb_notch_side = "right"; // "right" or "left"
// Mounting ears for MDF screws
ear_enable = true;
ear_len = 16;
ear_w = 16;
ear_thickness = base_thickness;
screw_hole_d = 4.2; // M4 clearance. Use 3.4 for M3.
screw_hole_edge = 5.5; // Hole center offset from ear outer corner
// Optional clamp lip at top to reduce wobble
top_lip_enable = true;
top_lip_depth = 2.0; // Intrudes into opening on each side
top_lip_height = 3.0;
$fn = 48;
// -------------------------
// Derived
// -------------------------
inner_w = bar_w + clearance;
inner_d = bar_d + clearance;
outer_w = inner_w + wall * 2;
outer_d = inner_d + wall * 2;
outer_h = socket_height;
module screw_hole() {
cylinder(h = ear_thickness + 0.2, d = screw_hole_d);
}
module mounting_ear(sign_y = 1) {
translate([outer_w / 2, sign_y * (outer_d / 2), 0])
cube([ear_len, ear_w, ear_thickness], center = false);
}
module top_lip() {
if (top_lip_enable) {
// Front and back lips at the top of the socket.
translate([wall, wall, outer_h - top_lip_height])
cube([top_lip_depth, inner_d, top_lip_height]);
translate([outer_w - wall - top_lip_depth, wall, outer_h - top_lip_height])
cube([top_lip_depth, inner_d, top_lip_height]);
}
}
difference() {
union() {
// Main body
cube([outer_w, outer_d, outer_h], center = false);
// Base plate under socket for stiffness
translate([0, 0, -base_thickness])
cube([outer_w, outer_d, base_thickness], center = false);
// Mounting ears
if (ear_enable) {
translate([0, 0, -ear_thickness]) {
mounting_ear(1);
mounting_ear(-1);
}
}
top_lip();
}
// Main bar cavity
translate([wall, wall, 0])
cube([inner_w, inner_d, outer_h + 0.2], center = false);
// USB side notch
if (usb_notch_enable) {
if (usb_notch_side == "right") {
translate([outer_w - wall - 0.1, (outer_d - usb_notch_w) / 2, usb_notch_from_bottom])
cube([wall + 0.3, usb_notch_w, usb_notch_h], center = false);
} else {
translate([-0.2, (outer_d - usb_notch_w) / 2, usb_notch_from_bottom])
cube([wall + 0.3, usb_notch_w, usb_notch_h], center = false);
}
}
// Screw holes in ears
if (ear_enable) {
// Upper ear hole
translate([
outer_w / 2 + ear_len - screw_hole_edge,
outer_d / 2 + ear_w - screw_hole_edge,
-ear_thickness - 0.05
]) screw_hole();
// Lower ear hole
translate([
outer_w / 2 + ear_len - screw_hole_edge,
-outer_d / 2 + screw_hole_edge,
-ear_thickness - 0.05
]) screw_hole();
}
}
// Print orientation helper:
// Keep the base/ears on the bed.
// If fit is tight, increase clearance to 0.5 or 0.6.
+2
View File
@@ -0,0 +1,2 @@
from microdot.microdot import Microdot, Request, Response, abort, redirect, \
send_file # noqa: F401
+8
View File
@@ -0,0 +1,8 @@
try:
from functools import wraps
except ImportError: # pragma: no cover
# MicroPython does not currently implement functools.wraps
def wraps(wrapped):
def _(wrapper):
return wrapper
return _
File diff suppressed because it is too large. Load diff
+225
View File
@@ -0,0 +1,225 @@
try:
import jwt
HAS_JWT = True
except ImportError:
HAS_JWT = False
try:
import ubinascii
except ImportError:
import binascii as ubinascii
try:
import uhashlib as hashlib
except ImportError:
import hashlib
try:
import uhmac as hmac
except ImportError:
try:
import hmac
except ImportError:
hmac = None
import json
from microdot.microdot import invoke_handler
from microdot.helpers import wraps
class SessionDict(dict):
"""A session dictionary.
The session dictionary is a standard Python dictionary that has been
extended with convenience ``save()`` and ``delete()`` methods.
"""
def __init__(self, request, session_dict):
super().__init__(session_dict)
self.request = request
def save(self):
"""Update the session cookie."""
self.request.app._session.update(self.request, self)
def delete(self):
"""Delete the session cookie."""
self.request.app._session.delete(self.request)
class Session:
"""Session handling
:param app: The application instance.
:param secret_key: The secret key, as a string or bytes object.
:param cookie_options: A dictionary with cookie options to pass as
arguments to :meth:`Response.set_cookie()
<microdot.Response.set_cookie>`.
"""
secret_key = None
def __init__(self, app=None, secret_key=None, cookie_options=None):
self.secret_key = secret_key
self.cookie_options = cookie_options or {}
if app is not None:
self.initialize(app)
def initialize(self, app, secret_key=None, cookie_options=None):
if secret_key is not None:
self.secret_key = secret_key
if cookie_options is not None:
self.cookie_options = cookie_options
if 'path' not in self.cookie_options:
self.cookie_options['path'] = '/'
if 'http_only' not in self.cookie_options:
self.cookie_options['http_only'] = True
app._session = self
def get(self, request):
"""Retrieve the user session.
:param request: The client request.
The return value is a session dictionary with the data stored in the
user's session, or ``{}`` if the session data is not available or
invalid.
"""
if not self.secret_key:
raise ValueError('The session secret key is not configured')
if hasattr(request.g, '_session'):
return request.g._session
session = request.cookies.get('session')
if session is None:
request.g._session = SessionDict(request, {})
return request.g._session
request.g._session = SessionDict(request, self.decode(session))
return request.g._session
def update(self, request, session):
"""Update the user session.
:param request: The client request.
:param session: A dictionary with the update session data for the user.
Applications would normally not call this method directly, instead they
would use the :meth:`SessionDict.save` method on the session
dictionary, which calls this method. For example::
@app.route('/')
@with_session
def index(request, session):
session['foo'] = 'bar'
session.save()
return 'Hello, World!'
Calling this method adds a cookie with the updated session to the
request currently being processed.
"""
if not self.secret_key:
raise ValueError('The session secret key is not configured')
encoded_session = self.encode(session)
@request.after_request
def _update_session(request, response):
response.set_cookie('session', encoded_session,
**self.cookie_options)
return response
def delete(self, request):
"""Remove the user session.
:param request: The client request.
Applications would normally not call this method directly, instead they
would use the :meth:`SessionDict.delete` method on the session
dictionary, which calls this method. For example::
@app.route('/')
@with_session
def index(request, session):
session.delete()
return 'Hello, World!'
Calling this method adds a cookie removal header to the request
currently being processed.
"""
@request.after_request
def _delete_session(request, response):
response.delete_cookie('session', **self.cookie_options)
return response
def encode(self, payload, secret_key=None):
"""Encode session data using JWT if available, otherwise use simple HMAC."""
if HAS_JWT:
return jwt.encode(payload, secret_key or self.secret_key,
algorithm='HS256')
else:
# Simple encoding for MicroPython: base64(json) + HMAC signature
key = (secret_key or self.secret_key).encode() if isinstance(secret_key or self.secret_key, str) else (secret_key or self.secret_key)
payload_json = json.dumps(payload)
payload_b64 = ubinascii.b2a_base64(payload_json.encode()).decode().strip()
# Create HMAC signature
if hmac:
# Use hmac module if available
h = hmac.new(key, payload_json.encode(), hashlib.sha256)
else:
# Fallback: simple SHA256(key + message)
h = hashlib.sha256(key + payload_json.encode())
signature = ubinascii.b2a_base64(h.digest()).decode().strip()
return f"{payload_b64}.{signature}"
def decode(self, session, secret_key=None):
"""Decode session data using JWT if available, otherwise use simple HMAC."""
if HAS_JWT:
try:
payload = jwt.decode(session, secret_key or self.secret_key,
algorithms=['HS256'])
except jwt.exceptions.PyJWTError: # pragma: no cover
return {}
return payload
else:
try:
# Simple decoding for MicroPython
if '.' not in session:
return {}
payload_b64, signature = session.rsplit('.', 1)
payload_json = ubinascii.a2b_base64(payload_b64).decode()
# Verify HMAC signature
key = (secret_key or self.secret_key).encode() if isinstance(secret_key or self.secret_key, str) else (secret_key or self.secret_key)
if hmac:
# Use hmac module if available
h = hmac.new(key, payload_json.encode(), hashlib.sha256)
else:
# Fallback: simple SHA256(key + message)
h = hashlib.sha256(key + payload_json.encode())
expected_signature = ubinascii.b2a_base64(h.digest()).decode().strip()
if signature != expected_signature:
return {}
return json.loads(payload_json)
except Exception:
return {}
def with_session(f):
"""Decorator that passes the user session to the route handler.
The session dictionary is passed to the decorated function as an argument
after the request object. Example::
@app.route('/')
@with_session
def index(request, session):
return 'Hello, World!'
Note that the decorator does not save the session. To update the session,
call the :func:`session.save() <microdot.session.SessionDict.save>` method.
"""
@wraps(f)
async def wrapper(request, *args, **kwargs):
return await invoke_handler(
f, request, request.app._session.get(request), *args, **kwargs)
return wrapper
+70
View File
@@ -0,0 +1,70 @@
from utemplate import recompile
_loader = None
class Template:
"""A template object.
:param template: The filename of the template to render, relative to the
configured template directory.
"""
@classmethod
def initialize(cls, template_dir='templates',
loader_class=recompile.Loader):
"""Initialize the templating subsystem.
:param template_dir: the directory where templates are stored. This
argument is optional. The default is to load
templates from a *templates* subdirectory.
:param loader_class: the ``utemplate.Loader`` class to use when loading
templates. This argument is optional. The default
is the ``recompile.Loader`` class, which
automatically recompiles templates when they
change.
"""
global _loader
_loader = loader_class(None, template_dir)
def __init__(self, template):
if _loader is None: # pragma: no cover
self.initialize()
#: The name of the template
self.name = template
self.template = _loader.load(template)
def generate(self, *args, **kwargs):
"""Return a generator that renders the template in chunks, with the
given arguments."""
return self.template(*args, **kwargs)
def render(self, *args, **kwargs):
"""Render the template with the given arguments and return it as a
string."""
return ''.join(self.generate(*args, **kwargs))
def generate_async(self, *args, **kwargs):
"""Return an asynchronous generator that renders the template in
chunks, using the given arguments."""
class sync_to_async_iter():
def __init__(self, iter):
self.iter = iter
def __aiter__(self):
return self
async def __anext__(self):
try:
return next(self.iter)
except StopIteration:
raise StopAsyncIteration
return sync_to_async_iter(self.generate(*args, **kwargs))
async def render_async(self, *args, **kwargs):
"""Render the template with the given arguments asynchronously and
return it as a string."""
response = ''
async for chunk in self.generate_async(*args, **kwargs):
response += chunk
return response
+231
View File
@@ -0,0 +1,231 @@
import binascii
import hashlib
from microdot import Request, Response
from microdot.microdot import MUTED_SOCKET_ERRORS, print_exception
from microdot.helpers import wraps
class WebSocketError(Exception):
"""Exception raised when an error occurs in a WebSocket connection."""
pass
class WebSocket:
"""A WebSocket connection object.
An instance of this class is sent to handler functions to manage the
WebSocket connection.
"""
CONT = 0
TEXT = 1
BINARY = 2
CLOSE = 8
PING = 9
PONG = 10
#: Specify the maximum message size that can be received when calling the
#: ``receive()`` method. Messages with payloads that are larger than this
#: size will be rejected and the connection closed. Set to 0 to disable
#: the size check (be aware of potential security issues if you do this),
#: or to -1 to use the value set in
#: ``Request.max_body_length``. The default is -1.
#:
#: Example::
#:
#: WebSocket.max_message_length = 4 * 1024 # up to 4KB messages
max_message_length = -1
def __init__(self, request):
self.request = request
self.closed = False
async def handshake(self):
response = self._handshake_response()
await self.request.sock[1].awrite(
b'HTTP/1.1 101 Switching Protocols\r\n')
await self.request.sock[1].awrite(b'Upgrade: websocket\r\n')
await self.request.sock[1].awrite(b'Connection: Upgrade\r\n')
await self.request.sock[1].awrite(
b'Sec-WebSocket-Accept: ' + response + b'\r\n\r\n')
async def receive(self):
"""Receive a message from the client."""
while True:
opcode, payload = await self._read_frame()
send_opcode, data = self._process_websocket_frame(opcode, payload)
if send_opcode: # pragma: no cover
await self.send(data, send_opcode)
elif data: # pragma: no branch
return data
async def send(self, data, opcode=None):
"""Send a message to the client.
:param data: the data to send, given as a string or bytes.
:param opcode: a custom frame opcode to use. If not given, the opcode
is ``TEXT`` or ``BINARY`` depending on the type of the
data.
"""
frame = self._encode_websocket_frame(
opcode or (self.TEXT if isinstance(data, str) else self.BINARY),
data)
await self.request.sock[1].awrite(frame)
async def close(self):
"""Close the websocket connection."""
if not self.closed: # pragma: no cover
self.closed = True
await self.send(b'', self.CLOSE)
def _handshake_response(self):
connection = False
upgrade = False
websocket_key = None
for header, value in self.request.headers.items():
h = header.lower()
if h == 'connection':
connection = True
if 'upgrade' not in value.lower():
return self.request.app.abort(400)
elif h == 'upgrade':
upgrade = True
if not value.lower() == 'websocket':
return self.request.app.abort(400)
elif h == 'sec-websocket-key':
websocket_key = value
if not connection or not upgrade or not websocket_key:
return self.request.app.abort(400)
d = hashlib.sha1(websocket_key.encode())
d.update(b'258EAFA5-E914-47DA-95CA-C5AB0DC85B11')
return binascii.b2a_base64(d.digest())[:-1]
@classmethod
def _parse_frame_header(cls, header):
fin = header[0] & 0x80
opcode = header[0] & 0x0f
if fin == 0 or opcode == cls.CONT: # pragma: no cover
raise WebSocketError('Continuation frames not supported')
has_mask = header[1] & 0x80
length = header[1] & 0x7f
if length == 126:
length = -2
elif length == 127:
length = -8
return fin, opcode, has_mask, length
def _process_websocket_frame(self, opcode, payload):
if opcode == self.TEXT:
payload = payload.decode()
elif opcode == self.BINARY:
pass
elif opcode == self.CLOSE:
raise WebSocketError('Websocket connection closed')
elif opcode == self.PING:
return self.PONG, payload
elif opcode == self.PONG: # pragma: no branch
return None, None
return None, payload
@classmethod
def _encode_websocket_frame(cls, opcode, payload):
frame = bytearray()
frame.append(0x80 | opcode)
if opcode == cls.TEXT:
payload = payload.encode()
if len(payload) < 126:
frame.append(len(payload))
elif len(payload) < (1 << 16):
frame.append(126)
frame.extend(len(payload).to_bytes(2, 'big'))
else:
frame.append(127)
frame.extend(len(payload).to_bytes(8, 'big'))
frame.extend(payload)
return frame
async def _read_frame(self):
header = await self.request.sock[0].read(2)
if len(header) != 2: # pragma: no cover
raise WebSocketError('Websocket connection closed')
fin, opcode, has_mask, length = self._parse_frame_header(header)
if length == -2:
length = await self.request.sock[0].read(2)
length = int.from_bytes(length, 'big')
elif length == -8:
length = await self.request.sock[0].read(8)
length = int.from_bytes(length, 'big')
max_allowed_length = Request.max_body_length \
if self.max_message_length == -1 else self.max_message_length
if length > max_allowed_length:
raise WebSocketError('Message too large')
if has_mask: # pragma: no cover
mask = await self.request.sock[0].read(4)
payload = await self.request.sock[0].read(length)
if has_mask: # pragma: no cover
payload = bytes(x ^ mask[i % 4] for i, x in enumerate(payload))
return opcode, payload
async def websocket_upgrade(request):
"""Upgrade a request handler to a websocket connection.
This function can be called directly inside a route function to process a
WebSocket upgrade handshake, for example after the user's credentials are
verified. The function returns the websocket object::
@app.route('/echo')
async def echo(request):
if not authenticate_user(request):
abort(401)
ws = await websocket_upgrade(request)
while True:
message = await ws.receive()
await ws.send(message)
"""
ws = WebSocket(request)
await ws.handshake()
@request.after_request
async def after_request(request, response):
return Response.already_handled
return ws
def websocket_wrapper(f, upgrade_function):
@wraps(f)
async def wrapper(request, *args, **kwargs):
ws = await upgrade_function(request)
try:
await f(request, ws, *args, **kwargs)
except OSError as exc:
if exc.errno not in MUTED_SOCKET_ERRORS: # pragma: no cover
raise
except WebSocketError:
pass
except Exception as exc:
print_exception(exc)
finally: # pragma: no cover
try:
await ws.close()
except Exception:
pass
return Response.already_handled
return wrapper
def with_websocket(f):
"""Decorator to make a route a WebSocket endpoint.
This decorator is used to define a route that accepts websocket
connections. The route then receives a websocket object as a second
argument that it can use to send and receive messages::
@app.route('/echo')
@with_websocket
async def echo(request, ws):
while True:
message = await ws.receive()
await ws.send(message)
"""
return websocket_wrapper(f, websocket_upgrade)
View File
Whitespace-only changes.
+14
View File
@@ -0,0 +1,14 @@
class Loader:
def __init__(self, pkg, dir):
if dir == ".":
dir = ""
else:
dir = dir.replace("/", ".") + "."
if pkg and pkg != "__main__":
dir = pkg + "." + dir
self.p = dir
def load(self, name):
name = name.replace(".", "_")
return __import__(self.p + name, None, None, (name,)).render
+21
View File
@@ -0,0 +1,21 @@
# (c) 2014-2020 Paul Sokolovsky. MIT license.
try:
from uos import stat, remove
except:
from os import stat, remove
from . import source
class Loader(source.Loader):
def load(self, name):
o_path = self.pkg_path + self.compiled_path(name)
i_path = self.pkg_path + self.dir + "/" + name
try:
o_stat = stat(o_path)
i_stat = stat(i_path)
if i_stat[8] > o_stat[8]:
# input file is newer, remove output to force recompile
remove(o_path)
finally:
return super().load(name)
+188
View File
@@ -0,0 +1,188 @@
# (c) 2014-2019 Paul Sokolovsky. MIT license.
from . import compiled
class Compiler:
START_CHAR = "{"
STMNT = "%"
STMNT_END = "%}"
EXPR = "{"
EXPR_END = "}}"
def __init__(self, file_in, file_out, indent=0, seq=0, loader=None):
self.file_in = file_in
self.file_out = file_out
self.loader = loader
self.seq = seq
self._indent = indent
self.stack = []
self.in_literal = False
self.flushed_header = False
self.args = "*a, **d"
def indent(self, adjust=0):
if not self.flushed_header:
self.flushed_header = True
self.indent()
self.file_out.write("def render%s(%s):\n" % (str(self.seq) if self.seq else "", self.args))
self.stack.append("def")
self.file_out.write(" " * (len(self.stack) + self._indent + adjust))
def literal(self, s):
if not s:
return
if not self.in_literal:
self.indent()
self.file_out.write('yield """')
self.in_literal = True
self.file_out.write(s.replace('"', '\\"'))
def close_literal(self):
if self.in_literal:
self.file_out.write('"""\n')
self.in_literal = False
def render_expr(self, e):
self.indent()
self.file_out.write('yield str(' + e + ')\n')
def parse_statement(self, stmt):
tokens = stmt.split(None, 1)
if tokens[0] == "args":
if len(tokens) > 1:
self.args = tokens[1]
else:
self.args = ""
elif tokens[0] == "set":
self.indent()
self.file_out.write(stmt[3:].strip() + "\n")
elif tokens[0] == "include":
if not self.flushed_header:
# If there was no other output, we still need a header now
self.indent()
tokens = tokens[1].split(None, 1)
args = ""
if len(tokens) > 1:
args = tokens[1]
if tokens[0][0] == "{":
self.indent()
# "1" as fromlist param is uPy hack
self.file_out.write('_ = __import__(%s.replace(".", "_"), None, None, 1)\n' % tokens[0][2:-2])
self.indent()
self.file_out.write("yield from _.render(%s)\n" % args)
return
with self.loader.input_open(tokens[0][1:-1]) as inc:
self.seq += 1
c = Compiler(inc, self.file_out, len(self.stack) + self._indent, self.seq)
inc_id = self.seq
self.seq = c.compile()
self.indent()
self.file_out.write("yield from render%d(%s)\n" % (inc_id, args))
elif len(tokens) > 1:
if tokens[0] == "elif":
assert self.stack[-1] == "if"
self.indent(-1)
self.file_out.write(stmt + ":\n")
else:
self.indent()
self.file_out.write(stmt + ":\n")
self.stack.append(tokens[0])
else:
if stmt.startswith("end"):
assert self.stack[-1] == stmt[3:]
self.stack.pop(-1)
elif stmt == "else":
assert self.stack[-1] == "if"
self.indent(-1)
self.file_out.write("else:\n")
else:
assert False
def parse_line(self, l):
while l:
start = l.find(self.START_CHAR)
if start == -1:
self.literal(l)
return
self.literal(l[:start])
self.close_literal()
sel = l[start + 1]
#print("*%s=%s=" % (sel, EXPR))
if sel == self.STMNT:
end = l.find(self.STMNT_END)
assert end > 0
stmt = l[start + len(self.START_CHAR + self.STMNT):end].strip()
self.parse_statement(stmt)
end += len(self.STMNT_END)
l = l[end:]
if not self.in_literal and l == "\n":
break
elif sel == self.EXPR:
# print("EXPR")
end = l.find(self.EXPR_END)
assert end > 0
expr = l[start + len(self.START_CHAR + self.EXPR):end].strip()
self.render_expr(expr)
end += len(self.EXPR_END)
l = l[end:]
else:
self.literal(l[start])
l = l[start + 1:]
def header(self):
self.file_out.write("# Autogenerated file\n")
def compile(self):
self.header()
for l in self.file_in:
self.parse_line(l)
self.close_literal()
return self.seq
class Loader(compiled.Loader):
def __init__(self, pkg, dir):
super().__init__(pkg, dir)
self.dir = dir
if pkg == "__main__":
# if pkg isn't really a package, don't bother to use it
# it means we're running from "filesystem directory", not
# from a package.
pkg = None
self.pkg_path = ""
if pkg:
p = __import__(pkg)
if isinstance(p.__path__, str):
# uPy
self.pkg_path = p.__path__
else:
# CPy
self.pkg_path = p.__path__[0]
self.pkg_path += "/"
def input_open(self, template):
path = self.pkg_path + self.dir + "/" + template
return open(path)
def compiled_path(self, template):
return self.dir + "/" + template.replace(".", "_") + ".py"
def load(self, name):
try:
return super().load(name)
except (OSError, ImportError):
pass
compiled_path = self.pkg_path + self.compiled_path(name)
f_in = self.input_open(name)
f_out = open(compiled_path, "w")
c = Compiler(f_in, f_out, loader=self)
c.compile()
f_in.close()
f_out.close()
return super().load(name)
-22
View File
@@ -1,22 +0,0 @@
if(IDF_TARGET STREQUAL "linux")
# Host build for led-simulator (sim-controller/): no Ethernet, Wi-Fi, mic or OTA. The sim
# component has app_main and stands in for main.c, mic.c and ota.c.
idf_component_register(SRCS "beat.c" "beat_dsp.c" "espnow_tx.c" "bridge.c" "store.c" "api.c" "web.c" "envelope.c" "engine.c" "rel.c" "bench.c" "audio.c" "drv_ota.c"
"res_profile.c" "res_misc.c" "res_device.c" "res_group.c" "seqplay.c" "res_bundle.c" "audio_api.c" "patterns.c" "outputs.c" "ws.c"
INCLUDE_DIRS "." "../sim-controller/components/sim/include"
REQUIRES esp_http_server esp_timer esp_event json
PRIV_REQUIRES mbedtls lwip esp_app_format)
else()
idf_component_register(SRCS "main.c" "mic.c" "beat.c" "beat_dsp.c" "espnow_tx.c" "bridge.c" "store.c" "api.c" "web.c" "envelope.c" "engine.c" "rel.c" "bench.c" "audio.c" "ota.c" "drv_ota.c"
"res_profile.c" "res_misc.c" "res_device.c" "res_group.c" "seqplay.c" "res_bundle.c" "audio_api.c" "patterns.c" "outputs.c" "ws.c"
INCLUDE_DIRS "."
REQUIRES esp_eth esp_netif esp_event esp_driver_spi esp_driver_gpio nvs_flash app_update esp_app_format
esp_http_server esp_timer esp_driver_i2s esp_wifi esp_rom json esp_driver_gpio
PRIV_REQUIRES littlefs mdns mbedtls lwip)
endif()
# The gzipped web UI is embedded in the app image (run tools/build_web.sh first)
if(NOT EXISTS ${COMPONENT_DIR}/../www_dist/www.pack)
message(FATAL_ERROR "www_dist/www.pack is missing: run tools/build_web.sh (make build does)")
endif()
target_add_binary_data(${COMPONENT_LIB} ${COMPONENT_DIR}/../www_dist/www.pack BINARY)
-155
View File
@@ -1,155 +0,0 @@
menu "W5500 config"
config W5500_SPI_HOST
int "SPI host number (1=SPI2, 2=SPI3)"
range 1 2
default 1
config W5500_SPI_CLOCK_MHZ
int "SPI clock speed (MHz)"
range 5 80
default 10
config W5500_SCLK_GPIO
int "SCLK GPIO (XIAO D8)"
default 7
config W5500_MISO_GPIO
int "MISO GPIO (XIAO D9)"
default 8
config W5500_MOSI_GPIO
int "MOSI GPIO (XIAO D10)"
default 9
config W5500_CS_GPIO
int "CS GPIO (XIAO D1)"
default 2
config W5500_INT_GPIO
int "INT GPIO (XIAO D2), -1 to poll"
default 3
config W5500_POLL_PERIOD_MS
int "RX poll period (ms) when INT is -1"
default 10
config W5500_RST_GPIO
int "RST GPIO (XIAO D0), -1 if not wired"
default 1
endmenu
menu "INMP441 mic config"
config MIC_SCK_GPIO
int "SCK GPIO (XIAO D4)"
default 5
config MIC_WS_GPIO
int "WS GPIO (XIAO D5)"
default 6
config MIC_SD_GPIO
int "SD GPIO (XIAO D6)"
default 43
config MIC_STREAM_GAIN
int "Digital gain for the audio stream (x)"
range 1 256
default 16
help
The INMP441 is quiet at full scale; x16 (+24 dB) makes speech
audible without clipping at normal distances.
endmenu
menu "Beat detection config"
config BEAT_LED_GPIO
int "Beat LED GPIO (XIAO user LED is 21), -1 for none"
default 21
config BEAT_LED_ACTIVE_LOW
bool "Beat LED lights when the pin is low"
default y
config BEAT_LED_PULSE_MS
int "Beat LED flash length (ms)"
range 10 500
default 60
config BEAT_LED_DOWNBEAT_MS
int "Beat LED flash length on the first beat of a bar (ms)"
range 10 1000
default 200
config BEAT_GATE_DBFS
int "Ignore audio quieter than this (dBFS, before stream gain)"
range -100 -20
default -75
help
The INMP441 self-noise is about -87 dBFS. Background music in a
room can sit around -65 dBFS, so keep this well below that.
config BEAT_LEAD_MS
int "Fire predicted beats this early (ms)"
range 0 200
default 30
help
Beats are predicted from the tempo, so they can be sent early
to cancel the ~30 ms of capture and analysis latency. Raise it
to cover output latency too (e.g. network or lights).
endmenu
menu "AP config"
config AP_BUTTON_GPIO
int "AP button GPIO (XIAO D3), -1 for none"
default 4
help
Active-low push button to ground (internal pull-up). Held while the controller boots, it turns
the Wi-Fi access point on even when the ap_enabled setting is off.
config AP_HOLD_MS
int "Hold time at boot (ms)"
range 100 5000
default 1000
endmenu
menu "ESP-NOW config"
config ESPNOW_CHANNEL
int "Wi-Fi channel shared with the LED drivers"
range 1 13
default 6
config BEAT_TX_COPIES
int "Copies sent of every beat frame"
range 1 4
default 2
help
Each beat is broadcast this many times with the same beat index.
Drivers act on the first copy that arrives and drop the rest.
config BEAT_TX_GAP_US
int "Gap between beat copies (us)"
range 500 10000
default 2000
config BEAT_TEST_GPIO
int "GPIO toggled on every beat sent (-1 = off)"
range -1 48
default -1
help
For latency measurement: a logic analyzer or scope on this pin and on
the driver's beat pin shows the true master-to-LED delay.
config BULK_HOLDOFF_US
int "Hold bulk traffic back after a beat (us)"
range 0 20000
default 3000
endmenu
-585
View File
@@ -1,585 +0,0 @@
#include "api.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "api_util.h"
#include "cJSON.h"
#include "esp_log.h"
#include "esp_timer.h"
#include "bench.h"
#include "engine.h"
#include "espnow_tx.h"
#include "sdkconfig.h"
#include "store.h"
#include "web.h"
static const char *TAG = "api";
#define BODY_MAX (256 * 1024)
// URL resource -> store collection
static const struct {
const char *res;
const char *coll;
} RES[] = {
{ "devices", "device" }, { "zones", "zone" }, { "presets", "preset" },
{ "profiles", "profile" }, { "palettes", "palette" }, { "patterns", "pattern" },
{ "sequences", "sequence" }, { "scenes", "scene" }, { "groups", "group" },
{ "outputs", "output" },
};
/* ---------------------------------------------------------------- helpers */
// Time spent printing JSON and sending the reply for the current request (the httpd task handles
// one request at a time), reported by the LOCKED wrapper's log line
static int64_t s_print_us, s_send_us;
esp_err_t api_json(httpd_req_t *req, const char *status, cJSON *obj, bool own)
{
int64_t t0 = esp_timer_get_time();
char *s = cJSON_PrintUnformatted(obj);
s_print_us += esp_timer_get_time() - t0;
if (own) {
cJSON_Delete(obj);
}
if (!s) {
return httpd_resp_send_500(req);
}
httpd_resp_set_status(req, status);
httpd_resp_set_type(req, "application/json");
int64_t t1 = esp_timer_get_time();
esp_err_t ret = httpd_resp_send(req, s, HTTPD_RESP_USE_STRLEN);
s_send_us += esp_timer_get_time() - t1;
free(s);
return ret;
}
esp_err_t api_error(httpd_req_t *req, const char *status, const char *msg)
{
cJSON *o = cJSON_CreateObject();
cJSON_AddStringToObject(o, "error", msg);
return api_json(req, status, o, true);
}
esp_err_t api_message(httpd_req_t *req, const char *status, const char *msg)
{
cJSON *o = cJSON_CreateObject();
cJSON_AddStringToObject(o, "message", msg);
return api_json(req, status, o, true);
}
esp_err_t api_result(httpd_req_t *req, esp_err_t err, const char *ok_msg)
{
switch (err) {
case ESP_OK:
return api_message(req, "200 OK", ok_msg);
case ESP_ERR_NOT_FOUND:
return api_error(req, "404 Not Found", "not found");
case ESP_ERR_INVALID_SIZE:
return api_error(req, "413 Payload Too Large", "preset too large for one ESP-NOW frame");
default:
return api_error(req, "503 Service Unavailable", "send failed");
}
}
static cJSON *body_impl(httpd_req_t *req, bool optional)
{
if (req->content_len == 0 && optional) {
return cJSON_CreateObject();
}
if (req->content_len == 0 || req->content_len > BODY_MAX) {
api_error(req, "400 Bad Request", req->content_len ? "body too large" : "body required");
return NULL;
}
char *buf = malloc(req->content_len + 1);
if (!buf) {
httpd_resp_send_500(req);
return NULL;
}
size_t got = 0;
while (got < req->content_len) {
int r = httpd_req_recv(req, buf + got, req->content_len - got);
if (r <= 0) {
free(buf);
httpd_resp_send_err(req, HTTPD_408_REQ_TIMEOUT, "read failed");
return NULL;
}
got += r;
}
buf[got] = 0;
cJSON *obj = cJSON_Parse(buf);
free(buf);
if (!cJSON_IsObject(obj)) {
cJSON_Delete(obj);
api_error(req, "400 Bad Request", "JSON object required");
return NULL;
}
return obj;
}
cJSON *api_body(httpd_req_t *req) { return body_impl(req, false); }
cJSON *api_body_opt(httpd_req_t *req) { return body_impl(req, true); }
int api_split(const char *uri, api_seg_t seg)
{
int n = 0;
const char *p = uri;
while (*p == '/' && n < 3) {
p++;
size_t len = strcspn(p, "/?");
if (len == 0 || len >= 64) {
break;
}
memcpy(seg[n], p, len);
seg[n][len] = 0;
n++;
p += len;
}
return n;
}
static const char *coll_for(const char *res)
{
for (size_t i = 0; i < sizeof(RES) / sizeof(RES[0]); i++) {
if (strcmp(RES[i].res, res) == 0) {
return RES[i].coll;
}
}
return NULL;
}
bool api_id(const cJSON *v, char *buf, size_t len)
{
buf[0] = 0;
if (cJSON_IsString(v) && v->valuestring[0]) {
snprintf(buf, len, "%s", v->valuestring);
} else if (cJSON_IsNumber(v)) {
snprintf(buf, len, "%d", (int)v->valuedouble);
}
return buf[0] != 0;
}
const char *api_current_profile(void)
{
cJSON *v = cJSON_GetObjectItem(store_settings(), "current_profile_id");
if (cJSON_IsString(v) && cJSON_GetObjectItem(store_coll("profile"), v->valuestring)) {
return v->valuestring;
}
cJSON *first = store_coll("profile")->child; // fall back to the first profile
return first ? first->string : NULL;
}
bool api_preset_in_profile(const cJSON *rec)
{
const char *cur = api_current_profile();
if (!cur) {
return true;
}
char pid[24];
return api_id(cJSON_GetObjectItem(rec, "profile_id"), pid, sizeof(pid)) && strcmp(pid, cur) == 0;
}
void api_set(cJSON *obj, const char *key, cJSON *val)
{
if (cJSON_GetObjectItem(obj, key)) {
cJSON_ReplaceItemInObject(obj, key, val);
} else {
cJSON_AddItemToObject(obj, key, val);
}
}
void api_merge(cJSON *dst, const cJSON *src)
{
const cJSON *it;
cJSON_ArrayForEach(it, src)
{
if (strcmp(it->string, "id") != 0) {
api_set(dst, it->string, cJSON_Duplicate(it, true));
}
}
}
void api_add(const char *coll, cJSON *rec, char *id, size_t len)
{
store_next_id(coll, id, len);
if (cJSON_IsObject(rec)) {
api_set(rec, "id", cJSON_CreateString(id));
}
cJSON_AddItemToObject(store_coll(coll), id, rec);
}
/* ------------------------------------------------------------ collections */
static bool route(const char *res, httpd_req_t *req, int n, api_seg_t seg, esp_err_t *ret)
{
if (bundles_route(req, n, seg, ret)) { // /<profiles|presets|sequences>/import and /<id>/export
return true;
}
static const struct {
const char *res;
bool (*fn)(httpd_req_t *, int, api_seg_t, esp_err_t *);
} ROUTERS[] = {
{ "profiles", profiles_route }, { "zones", zones_route }, { "presets", presets_route },
{ "palettes", palettes_route }, { "sequences", sequences_route }, { "devices", devices_route },
{ "patterns", patterns_route }, { "outputs", outputs_route }, { "groups", groups_route },
};
for (size_t i = 0; i < sizeof(ROUTERS) / sizeof(ROUTERS[0]); i++) {
if (!strcmp(ROUTERS[i].res, res)) {
return ROUTERS[i].fn(req, n, seg, ret);
}
}
return false;
}
static esp_err_t collection_handler_inner(httpd_req_t *req)
{
api_seg_t seg;
int n = api_split(req->uri, seg);
const char *coll = n ? coll_for(seg[0]) : NULL;
if (!coll) {
return api_error(req, "404 Not Found", "unknown resource");
}
esp_err_t ret;
if (route(seg[0], req, n, seg, &ret)) {
return ret;
}
const bool is_presets = strcmp(coll, "preset") == 0;
const bool is_profiles = strcmp(coll, "profile") == 0;
const bool groups_change = !strcmp(coll, "zone") || !strcmp(coll, "device");
cJSON *all = store_coll(coll);
const int method = req->method;
if (n == 3) {
return api_error(req, "404 Not Found", "unknown action");
}
// "current" profile aliases
const char *id = n == 2 ? seg[1] : NULL;
if (is_profiles && id && strcmp(id, "current") == 0) {
id = api_current_profile();
if (!id) {
return api_error(req, "404 Not Found", "No profile available");
}
if (method == HTTP_GET) {
cJSON *o = cJSON_CreateObject();
cJSON_AddStringToObject(o, "id", id);
cJSON_AddItemReferenceToObject(o, "profile", cJSON_GetObjectItem(all, id));
return api_json(req, "200 OK", o, true);
}
}
if (!id) {
if (method == HTTP_GET) {
if (is_profiles) {
cJSON *o = cJSON_CreateObject();
cJSON_AddItemReferenceToObject(o, "profiles", all);
const char *cur = api_current_profile();
cJSON_AddStringToObject(o, "current_profile_id", cur ? cur : "");
return api_json(req, "200 OK", o, true);
}
if (is_presets) {
cJSON *o = cJSON_CreateObject(), *it;
cJSON_ArrayForEach(it, all)
{
if (api_preset_in_profile(it)) {
cJSON_AddItemReferenceToObject(o, it->string, it);
}
}
return api_json(req, "200 OK", o, true);
}
return api_json(req, "200 OK", all, false);
}
if (method == HTTP_POST) {
cJSON *body = api_body(req);
if (!body) {
return ESP_OK;
}
char nid[16];
api_add(coll, body, nid, sizeof(nid));
store_save(coll);
if (groups_change) {
engine_groups_changed();
}
cJSON *o = cJSON_CreateObject();
cJSON_AddItemReferenceToObject(o, nid, body);
return api_json(req, "201 Created", o, true);
}
return api_error(req, "405 Method Not Allowed", "method not allowed");
}
cJSON *rec = cJSON_GetObjectItem(all, id);
if (!rec || (is_presets && !api_preset_in_profile(rec))) {
return api_error(req, "404 Not Found", "not found");
}
switch (method) {
case HTTP_GET:
return api_json(req, "200 OK", rec, false);
case HTTP_PUT: {
cJSON *body = api_body(req);
if (!body) {
return ESP_OK;
}
api_merge(rec, body);
cJSON_Delete(body);
store_save(coll);
if (groups_change) {
engine_groups_changed();
}
return api_json(req, "200 OK", rec, false);
}
case HTTP_DELETE: {
cJSON_DeleteItemFromObject(all, id);
store_save(coll);
if (groups_change) {
engine_groups_changed();
}
return api_message(req, "200 OK", "Deleted");
}
default:
return api_error(req, "405 Method Not Allowed", "method not allowed");
}
}
/* --------------------------------------------------------------- settings */
// Defaults the v1 app seeded into settings.json
void api_settings_defaults(void)
{
cJSON *st = store_settings();
bool changed = false;
if (!cJSON_IsNumber(cJSON_GetObjectItem(st, "wifi_channel"))) {
api_set(st, "wifi_channel", cJSON_CreateNumber(CONFIG_ESPNOW_CHANNEL));
changed = true;
}
if (!cJSON_IsNumber(cJSON_GetObjectItem(st, "global_brightness"))) {
api_set(st, "global_brightness", cJSON_CreateNumber(255));
changed = true;
}
if (!cJSON_IsBool(cJSON_GetObjectItem(st, "ap_enabled"))) {
api_set(st, "ap_enabled", cJSON_CreateBool(true));
changed = true;
}
if (changed) {
store_save("settings");
}
}
// Integer in [lo, hi], or false
static bool int_in(const cJSON *v, int lo, int hi)
{
return cJSON_IsNumber(v) && v->valuedouble == (int)v->valuedouble && v->valuedouble >= lo && v->valuedouble <= hi;
}
static esp_err_t put_settings(httpd_req_t *req)
{
cJSON *body = api_body(req);
if (!body) {
return ESP_OK;
}
static const struct {
const char *key;
int lo, hi;
const char *err;
} INTS[] = {
{ "wifi_channel", 1, 11, "wifi_channel must be an integer between 1 and 11" },
{ "global_brightness", 0, 255, "global_brightness must be between 0 and 255" },
{ "audio_beat_phase_ms", 0, 500, "audio_beat_phase_ms must be between 0 and 500" },
{ "audio_input_volume", 0, 200, "audio_input_volume must be between 0 and 200" },
};
const char *bad = NULL;
for (size_t i = 0; i < sizeof(INTS) / sizeof(INTS[0]) && !bad; i++) {
const cJSON *v = cJSON_GetObjectItem(body, INTS[i].key);
if (v && !cJSON_IsNull(v) && !int_in(v, INTS[i].lo, INTS[i].hi)) {
bad = INTS[i].err;
}
}
const cJSON *ap = cJSON_GetObjectItem(body, "ap_enabled");
if (ap && !cJSON_IsBool(ap)) {
bad = "ap_enabled must be true or false";
}
const cJSON *pw = cJSON_GetObjectItem(body, "ap_password");
if (!bad && pw && !cJSON_IsNull(pw) &&
!(cJSON_IsString(pw) && (!pw->valuestring[0] || (strlen(pw->valuestring) >= 8 && strlen(pw->valuestring) <= 63)))) {
bad = "ap_password must be empty (open) or 8 to 63 characters";
}
const cJSON *br = cJSON_GetObjectItem(body, "bridge");
if (!bad && br && !cJSON_IsNull(br) && !(cJSON_IsString(br) && strlen(br->valuestring) < 64)) {
bad = "bridge must be \"host:port\", empty or null";
}
const cJSON *sw = cJSON_GetObjectItem(body, "sequence_switch_wait");
if (!bad && sw && !cJSON_IsNull(sw) &&
!(cJSON_IsString(sw) && (!strcasecmp(sw->valuestring, "beat") || !strcasecmp(sw->valuestring, "downbeat")))) {
bad = "sequence_switch_wait must be beat or downbeat";
}
if (bad) {
cJSON_Delete(body);
return api_error(req, "400 Bad Request", bad);
}
const cJSON *bpm = cJSON_GetObjectItem(body, "audio_simulated_bpm");
if (bpm && !cJSON_IsNull(bpm)) { // clamped to the BPM range, like main's clamp_bpm
double v = cJSON_IsNumber(bpm) ? bpm->valuedouble : (cJSON_IsString(bpm) ? strtod(bpm->valuestring, NULL) : 120);
api_set(body, "audio_simulated_bpm", cJSON_CreateNumber((int)(v < 60 ? 60 : (v > 200 ? 200 : v))));
}
// global_brightness is only stored: the UI pushes each driver its combined brightness
// (POST /devices/<id>/brightness, /groups/<id>/brightness)
api_merge(store_settings(), body);
cJSON_Delete(body);
store_save("settings");
return api_message(req, "200 OK", "Settings updated successfully");
}
static esp_err_t settings_handler_inner(httpd_req_t *req)
{
api_seg_t seg;
int n = api_split(req->uri, seg);
if (n == 2 && strcmp(seg[1], "page") == 0 && req->method == HTTP_GET) {
return web_send_page(req, "settings.html");
}
if (n == 2 && strcmp(seg[1], "editor") == 0 && req->method == HTTP_GET) {
return web_send_page(req, "settings_editor.html");
}
if (n == 1 && req->method == HTTP_GET) {
return api_json(req, "200 OK", store_settings(), false);
}
if (req->method == HTTP_PUT && (n == 1 || (n == 2 && strcmp(seg[1], "settings") == 0))) {
return put_settings(req);
}
return api_error(req, "404 Not Found", "unknown settings route");
}
/* --------------------------------------------------------------------- db */
// GET /db/<name> exports a collection, PUT /db/<name> replaces it (import of the Pi's db/*.json)
static esp_err_t db_handler_inner(httpd_req_t *req)
{
api_seg_t seg;
int n = api_split(req->uri, seg);
if (n != 2 || !store_known(seg[1])) {
return api_error(req, "404 Not Found", "unknown collection");
}
if (req->method == HTTP_GET) {
return api_json(req, "200 OK", store_coll(seg[1]), false);
}
if (req->method == HTTP_PUT) {
cJSON *body = api_body(req);
if (!body) {
return ESP_OK;
}
if (store_replace(seg[1], body) != ESP_OK) {
return api_error(req, "500 Internal Server Error", "save failed");
}
cJSON *o = cJSON_CreateObject();
cJSON_AddNumberToObject(o, "records", cJSON_GetArraySize(store_coll(seg[1])));
return api_json(req, "200 OK", o, true);
}
return api_error(req, "405 Method Not Allowed", "method not allowed");
}
static void log_timing(httpd_req_t *req, int64_t lock_us, int64_t handle_us)
{
ESP_LOGI("http", "%s %s: lock %.1f ms, handle %.1f ms = build %.1f + print %.1f + send %.1f",
req->method == HTTP_GET ? "GET" : req->method == HTTP_PUT ? "PUT" : req->method == HTTP_POST ? "POST" : "DEL",
req->uri, lock_us / 1000.0, handle_us / 1000.0, (handle_us - s_print_us - s_send_us) / 1000.0,
s_print_us / 1000.0, s_send_us / 1000.0);
}
// Logs how long each request took: waiting for the store lock, then the handler, split into
// building the data, printing JSON and sending (send includes the radio/TCP hand-off)
#define LOCKED(name) \
static esp_err_t name(httpd_req_t *req) \
{ \
int64_t t0 = esp_timer_get_time(); \
store_lock(); \
int64_t t1 = esp_timer_get_time(); \
s_print_us = s_send_us = 0; \
esp_err_t r = name##_inner(req); \
int64_t t2 = esp_timer_get_time(); \
store_unlock(); \
log_timing(req, t1 - t0, t2 - t1); \
return r; \
}
LOCKED(collection_handler)
LOCKED(settings_handler)
LOCKED(db_handler)
/* ------------------------------------------------------------------ tests */
// Bench tests: /test/loss and /test/beats
static esp_err_t test_handler_inner(httpd_req_t *req)
{
api_seg_t seg;
int n = api_split(req->uri, seg);
if (n >= 2 && !strcmp(seg[1], "loss")) {
if (req->method == HTTP_POST) {
cJSON *b = api_body(req);
if (!b) {
return ESP_OK;
}
const cJSON *p = cJSON_GetObjectItem(b, "percent"), *beats = cJSON_GetObjectItem(b, "beats");
espnow_tx_set_loss(cJSON_IsNumber(p) ? (int)p->valuedouble : 0, !cJSON_IsFalse(beats));
cJSON_Delete(b);
}
bool inc;
int pct = espnow_tx_loss(&inc);
cJSON *o = cJSON_CreateObject();
cJSON_AddNumberToObject(o, "percent", pct);
cJSON_AddBoolToObject(o, "beats", inc);
return api_json(req, "200 OK", o, true);
}
if (n >= 2 && !strcmp(seg[1], "beats")) {
if (req->method == HTTP_POST && n == 3 && !strcmp(seg[2], "stop")) {
bench_stop();
} else if (req->method == HTTP_POST) {
cJSON *b = api_body(req);
if (!b) {
return ESP_OK;
}
const cJSON *bpm = cJSON_GetObjectItem(b, "bpm"), *count = cJSON_GetObjectItem(b, "count");
esp_err_t err = bench_start(cJSON_IsNumber(bpm) ? (float)bpm->valuedouble : 120,
cJSON_IsNumber(count) ? (int)count->valuedouble : 100);
cJSON_Delete(b);
if (err != ESP_OK) {
return api_error(req, "400 Bad Request", "bpm must be 30-300");
}
}
return api_json(req, "200 OK", bench_results(), true);
}
return api_error(req, "404 Not Found", "unknown test");
}
LOCKED(test_handler)
esp_err_t api_register(httpd_handle_t server)
{
store_lock();
api_settings_defaults();
api_seed_defaults();
api_migrate_sequences();
api_migrate_zones();
api_migrate_groups();
store_unlock();
static const char *const ROUTES[] = {
"/devices*", "/zones*", "/presets*", "/profiles*", "/palettes*",
"/patterns*", "/sequences*", "/scenes*", "/groups*", "/outputs*",
};
static const httpd_method_t METHODS[] = { HTTP_GET, HTTP_POST, HTTP_PUT, HTTP_DELETE };
for (size_t r = 0; r < sizeof(ROUTES) / sizeof(ROUTES[0]); r++) {
for (size_t m = 0; m < 4; m++) {
httpd_uri_t u = { .uri = ROUTES[r], .method = METHODS[m], .handler = collection_handler };
ESP_ERROR_CHECK_WITHOUT_ABORT(httpd_register_uri_handler(server, &u));
}
}
for (size_t m = 0; m < 4; m++) {
httpd_uri_t t = { .uri = "/test/*", .method = METHODS[m], .handler = test_handler };
ESP_ERROR_CHECK_WITHOUT_ABORT(httpd_register_uri_handler(server, &t));
}
for (size_t m = 0; m < 4; m++) {
httpd_uri_t s = { .uri = "/settings*", .method = METHODS[m], .handler = settings_handler };
httpd_uri_t d = { .uri = "/db/*", .method = METHODS[m], .handler = db_handler };
ESP_ERROR_CHECK_WITHOUT_ABORT(httpd_register_uri_handler(server, &s));
ESP_ERROR_CHECK_WITHOUT_ABORT(httpd_register_uri_handler(server, &d));
}
ESP_LOGI(TAG, "API registered");
return ESP_OK;
}
-8
View File
@@ -1,8 +0,0 @@
#pragma once
#include "esp_err.h"
#include "esp_http_server.h"
// Register the JSON API (CRUD over the store collections, profiles, settings,
// /db import and export). Actions that need the engine answer 501 for now.
esp_err_t api_register(httpd_handle_t server);
-74
View File
@@ -1,74 +0,0 @@
#pragma once
#include <stdbool.h>
#include <stddef.h>
#include "cJSON.h"
#include "esp_err.h"
#include "esp_http_server.h"
// Helpers shared by the REST handlers (api.c and the res_*.c resource modules)
// Path segments of "/res/id/action?query" (at most three)
typedef char api_seg_t[3][64];
int api_split(const char *uri, api_seg_t seg);
// Send obj as JSON; own=true deletes it afterwards
esp_err_t api_json(httpd_req_t *req, const char *status, cJSON *obj, bool own);
esp_err_t api_error(httpd_req_t *req, const char *status, const char *msg);
esp_err_t api_message(httpd_req_t *req, const char *status, const char *msg);
// 200 {message} for ESP_OK, otherwise a matching error status
esp_err_t api_result(httpd_req_t *req, esp_err_t err, const char *ok_msg);
// Parsed JSON object body, or NULL after an error response has been sent. api_body_opt treats an
// empty body as {}.
cJSON *api_body(httpd_req_t *req);
cJSON *api_body_opt(httpd_req_t *req);
// Shallow merge of src into dst, skipping "id"
void api_merge(cJSON *dst, const cJSON *src);
// Set (replace or add) one key
void api_set(cJSON *obj, const char *key, cJSON *val);
// Record id as text from a string or number value; false (buf empty) otherwise
bool api_id(const cJSON *v, char *buf, size_t len);
// Add rec under the collection's next id (with an "id" field when rec is an object); id gets the key
void api_add(const char *coll, cJSON *rec, char *id, size_t len);
// "aa:bb:..", "AA-BB-.." or "aabb.." -> lowercase 12-hex MAC; false when not a MAC
bool api_mac(const cJSON *v, char out[13]);
// device_config from the fields a request may set (name, num_leds, color_order, startup_mode); NULL when
// none is valid. Caller owns the result.
cJSON *api_driver_config(const cJSON *name, const cJSON *num_leds, const cJSON *color_order, const cJSON *startup);
// Combined 0..255 brightness for a driver: global x its groups x device [x zone_b when >= 0]
int api_effective_brightness(const char *mac, int zone_b);
// Blink every member of a group, then "off"
esp_err_t api_identify_group(const char *group_id);
// New records with every field set (callers merge in the request)
cJSON *api_preset_defaults(const char *profile_id);
cJSON *api_sequence_defaults(void);
// Current profile id (settings.current_profile_id, else the first profile), or NULL
const char *api_current_profile(void);
bool api_preset_in_profile(const cJSON *rec);
// Bring records written by older versions into the current shape (at boot)
void api_migrate_sequences(void);
void api_seed_defaults(void);
// A new group with the defaults, saved; its id in id
void api_add_group(const char *name, char *id, size_t len);
void api_migrate_zones(void);
void api_migrate_groups(void);
// Resource handlers, called with the store locked. Each returns true when it answered the request
// (its result in *ret); false hands the request to the generic collection CRUD.
bool bundles_route(httpd_req_t *req, int n, api_seg_t seg, esp_err_t *ret);
bool profiles_route(httpd_req_t *req, int n, api_seg_t seg, esp_err_t *ret);
bool zones_route(httpd_req_t *req, int n, api_seg_t seg, esp_err_t *ret);
bool presets_route(httpd_req_t *req, int n, api_seg_t seg, esp_err_t *ret);
bool palettes_route(httpd_req_t *req, int n, api_seg_t seg, esp_err_t *ret);
bool sequences_route(httpd_req_t *req, int n, api_seg_t seg, esp_err_t *ret);
bool groups_route(httpd_req_t *req, int n, api_seg_t seg, esp_err_t *ret);
bool devices_route(httpd_req_t *req, int n, api_seg_t seg, esp_err_t *ret);
bool patterns_route(httpd_req_t *req, int n, api_seg_t seg, esp_err_t *ret);
bool outputs_route(httpd_req_t *req, int n, api_seg_t seg, esp_err_t *ret);
-227
View File
@@ -1,227 +0,0 @@
/*
* Live audio and beat endpoints: /audio.wav (16 kHz mono PCM stream), /beats (server-sent events from the
* beat detector), POST /tap (correct the bar position), /time (board clock). Ported from esp32-eth.
*/
#include "audio.h"
#include <stdio.h>
#include <string.h>
#include "beat.h"
#include "esp_log.h"
#include "esp_timer.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "lwip/sockets.h"
#include "mic.h"
static const char *TAG = "audio";
static void wav_header(uint8_t h[44])
{
const uint32_t rate = MIC_SAMPLE_RATE, byte_rate = MIC_SAMPLE_RATE * 2, unknown = 0xFFFFFFFF;
const uint16_t pcm = 1, channels = 1, block_align = 2, bits = 16;
const uint32_t fmt_len = 16;
memcpy(h, "RIFF", 4); memcpy(h + 4, &unknown, 4);
memcpy(h + 8, "WAVEfmt ", 8); memcpy(h + 16, &fmt_len, 4);
memcpy(h + 20, &pcm, 2); memcpy(h + 22, &channels, 2);
memcpy(h + 24, &rate, 4); memcpy(h + 28, &byte_rate, 4);
memcpy(h + 32, &block_align, 2); memcpy(h + 34, &bits, 2);
memcpy(h + 36, "data", 4); memcpy(h + 40, &unknown, 4);
}
// httpd_send may write only part of the buffer; keep going until done
static bool send_all(httpd_req_t *req, const void *data, size_t len)
{
const char *p = data;
while (len > 0) {
int sent = httpd_send(req, p, len);
if (sent <= 0) {
return false;
}
p += sent;
len -= sent;
}
return true;
}
static void audio_stream_task(void *arg)
{
httpd_req_t *req = arg;
httpd_handle_t server = req->handle;
int fd = httpd_req_to_sockfd(req);
static uint8_t buf[1024];
// Send each 20 ms block immediately instead of letting Nagle batch them
int one = 1;
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one));
// Raw (non-chunked) response: chunked encoding splits every block into
// three tiny TCP segments, which fills lwIP's send queue and stalls on
// the client's delayed ACKs. One segment per block avoids that.
static const char http_hdr[] =
"HTTP/1.1 200 OK\r\n"
"Content-Type: audio/wav\r\n"
"Cache-Control: no-store\r\n"
"Connection: close\r\n\r\n";
uint8_t head[sizeof(http_hdr) - 1 + 44];
memcpy(head, http_hdr, sizeof(http_hdr) - 1);
wav_header(head + sizeof(http_hdr) - 1);
bool ok = send_all(req, head, sizeof(head));
ESP_LOGI(TAG, "Audio listener connected");
while (ok) {
size_t n = mic_stream_read(buf, sizeof(buf), pdMS_TO_TICKS(1000));
if (n > 0) {
ok = send_all(req, buf, n);
}
}
mic_stream_close();
ESP_LOGI(TAG, "Audio listener disconnected");
httpd_req_async_handler_complete(req);
httpd_sess_trigger_close(server, fd);
vTaskDelete(NULL);
}
static esp_err_t audio_get_handler(httpd_req_t *req)
{
if (mic_stream_open() != ESP_OK) {
httpd_resp_set_status(req, "409 Conflict");
return httpd_resp_sendstr(req, "Another listener is already connected\n");
}
// Stream from our own task so the server keeps answering /status
httpd_req_t *async_req = NULL;
if (httpd_req_async_handler_begin(req, &async_req) != ESP_OK) {
mic_stream_close();
return ESP_FAIL;
}
if (xTaskCreate(audio_stream_task, "audio_http", 4096, async_req, 5, NULL) != pdPASS) {
mic_stream_close();
httpd_req_async_handler_complete(async_req);
return ESP_FAIL;
}
return ESP_OK;
}
// Board clock for the page to line its own clock up with (esp_timer, us)
static esp_err_t time_get_handler(httpd_req_t *req)
{
char buf[48];
snprintf(buf, sizeof(buf), "{\"us\":%lld}", (long long)esp_timer_get_time());
httpd_resp_set_type(req, "application/json");
httpd_resp_set_hdr(req, "Cache-Control", "no-store");
return httpd_resp_sendstr(req, buf);
}
static esp_err_t tap_post_handler(httpd_req_t *req)
{
beat_tap();
httpd_resp_set_type(req, "application/json");
return httpd_resp_sendstr(req, "{\"ok\":true}");
}
#define BEAT_QUEUE_LEN 16
static void beats_stream_task(void *arg)
{
httpd_req_t *req = arg;
httpd_handle_t server = req->handle;
int fd = httpd_req_to_sockfd(req);
QueueHandle_t q = xQueueCreate(BEAT_QUEUE_LEN, sizeof(beat_event_t));
char msg[160];
int one = 1;
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one));
static const char http_hdr[] =
"HTTP/1.1 200 OK\r\n"
"Content-Type: text/event-stream\r\n"
"Cache-Control: no-store\r\n"
"Connection: close\r\n\r\n";
bool ok = q && beat_subscribe(q) == ESP_OK;
if (!ok) {
static const char busy[] =
"HTTP/1.1 503 Service Unavailable\r\nConnection: close\r\n\r\nToo many beat listeners\n";
send_all(req, busy, sizeof(busy) - 1);
} else {
ok = send_all(req, http_hdr, sizeof(http_hdr) - 1);
ESP_LOGI(TAG, "Beat listener connected");
}
// Tempo goes out once a second even without beats, which also notices
// when the client has gone away
int64_t next_tempo = 0;
while (ok) {
int64_t now = esp_timer_get_time();
if (now >= next_tempo) {
beat_info_t b;
beat_get_info(&b);
int n = snprintf(msg, sizeof(msg),
"event: tempo\ndata: {\"bpm\":%.1f,\"confidence\":%.2f,\"locked\":%s,\"beats\":%lu}\n\n",
b.bpm, b.confidence, b.locked ? "true" : "false", (unsigned long)b.beat_count);
ok = send_all(req, msg, n);
next_tempo = now + 1000000;
continue;
}
beat_event_t ev;
TickType_t wait = pdMS_TO_TICKS((next_tempo - now) / 1000) + 1;
if (xQueueReceive(q, &ev, wait) != pdTRUE) {
continue;
}
int n;
if (ev == BEAT_EVENT_BEAT) {
beat_info_t b;
beat_get_info(&b);
n = snprintf(msg, sizeof(msg),
"event: beat\ndata: {\"bpm\":%.1f,\"n\":%lu,\"bar\":%d,\"meter\":%d,\"sure\":%s,\"us\":%lld}\n\n",
b.bpm, (unsigned long)b.beat_count, b.bar_beat, b.meter, b.bar_sure ? "true" : "false",
(long long)b.last_beat_us);
} else {
n = snprintf(msg, sizeof(msg), "event: onset\ndata: {}\n\n");
}
ok = send_all(req, msg, n);
}
if (q) {
beat_unsubscribe(q);
vQueueDelete(q);
}
ESP_LOGI(TAG, "Beat listener disconnected");
httpd_req_async_handler_complete(req);
httpd_sess_trigger_close(server, fd);
vTaskDelete(NULL);
}
static esp_err_t beats_get_handler(httpd_req_t *req)
{
// Long-lived like /audio.wav, so it gets its own task too
httpd_req_t *async_req = NULL;
if (httpd_req_async_handler_begin(req, &async_req) != ESP_OK) {
return ESP_FAIL;
}
if (xTaskCreate(beats_stream_task, "beats_http", 4096, async_req, 5, NULL) != pdPASS) {
httpd_req_async_handler_complete(async_req);
return ESP_FAIL;
}
return ESP_OK;
}
esp_err_t audio_register(httpd_handle_t server)
{
const httpd_uri_t uris[] = {
{ .uri = "/audio.wav", .method = HTTP_GET, .handler = audio_get_handler },
{ .uri = "/beats", .method = HTTP_GET, .handler = beats_get_handler },
{ .uri = "/tap", .method = HTTP_POST, .handler = tap_post_handler },
{ .uri = "/time", .method = HTTP_GET, .handler = time_get_handler },
};
for (size_t i = 0; i < sizeof(uris) / sizeof(uris[0]); i++) {
esp_err_t err = httpd_register_uri_handler(server, &uris[i]);
if (err != ESP_OK) {
ESP_LOGE(TAG, "register %s: %s", uris[i].uri, esp_err_to_name(err));
return err;
}
}
return ESP_OK;
}
-7
View File
@@ -1,7 +0,0 @@
#pragma once
#include "esp_err.h"
#include "esp_http_server.h"
// Register /audio.wav, /beats, /tap and /time (the page at /audio uses them)
esp_err_t audio_register(httpd_handle_t server);
-303
View File
@@ -1,303 +0,0 @@
// main's /api/audio routes on this board's microphone: status and an event stream in main's shape,
// start/stop (whether mic beats time sequences), tracking reset and bar anchoring. There is one input,
// the I2S microphone, so device selection is stored but changes nothing.
#include "audio_api.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "api_util.h"
#include "beat.h"
#include "cJSON.h"
#include "esp_log.h"
#include "esp_timer.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "lwip/sockets.h"
#include "mic.h"
#include "seqplay.h"
#include "store.h"
static const char *TAG = "audio_api";
#define EVENTS_HEARTBEAT_US 500000
static int setting_int(const char *key, int dflt, int lo, int hi)
{
const cJSON *v = cJSON_GetObjectItem(store_settings(), key);
int x = cJSON_IsNumber(v) ? (int)v->valuedouble : dflt;
return x < lo ? lo : (x > hi ? hi : x);
}
static cJSON *audio_run(void)
{
cJSON *o = cJSON_CreateObject();
cJSON_AddBoolToObject(o, "enabled", seqplay_audio());
const cJSON *sel = cJSON_GetObjectItem(store_settings(), "audio_device_select");
cJSON_AddNullToObject(o, "device");
cJSON_AddStringToObject(o, "device_override", "");
cJSON_AddStringToObject(o, "device_select", cJSON_IsString(sel) ? sel->valuestring : "");
return o;
}
// main's audio_status_payload
static cJSON *status_payload(void)
{
beat_info_t bi;
beat_get_info(&bi);
mic_level_t lv;
mic_get_level(&lv);
bool running = seqplay_audio();
int meter = bi.meter > 0 ? bi.meter : 4;
cJSON *o = cJSON_CreateObject();
store_lock();
int sim_bpm = setting_int("audio_simulated_bpm", 120, 60, 200);
cJSON_AddBoolToObject(o, "running", running);
cJSON_AddStringToObject(o, "device", "i2s");
cJSON_AddNullToObject(o, "error");
if (!running) {
cJSON_AddNumberToObject(o, "bpm", sim_bpm);
} else if (bi.locked && bi.bpm > 0) {
cJSON_AddNumberToObject(o, "bpm", bi.bpm < 60 ? 60 : (bi.bpm > 200 ? 200 : bi.bpm));
} else {
cJSON_AddNullToObject(o, "bpm");
}
cJSON_AddNumberToObject(o, "beat_seq", bi.beat_count);
cJSON_AddNumberToObject(o, "beats_per_bar", meter);
cJSON_AddStringToObject(o, "beat_type", "unknown");
cJSON_AddNumberToObject(o, "beat_type_confidence", 0);
cJSON_AddNumberToObject(o, "input_level", running ? powf(10.0f, lv.rms_dbfs / 20.0f) : 0);
cJSON_AddItemToObject(o, "last_beat_ts", bi.last_beat_us ? cJSON_CreateNumber(bi.last_beat_us / 1e6) : cJSON_CreateNull());
int bar_beat;
double phase_conf;
if (running) {
bar_beat = bi.bar_beat > 0 ? bi.bar_beat : 1;
phase_conf = bi.bar_sure ? 1.0 : 0.0;
} else {
uint32_t tick;
seqplay_clock(&bar_beat, &tick);
phase_conf = 0;
}
char readout[24];
snprintf(readout, sizeof(readout), "%d/%d", bar_beat, running ? meter : 4);
cJSON_AddNumberToObject(o, "bar_beat", bar_beat);
cJSON_AddBoolToObject(o, "is_downbeat", bar_beat == 1);
cJSON_AddStringToObject(o, "bar_phase_readout", readout);
cJSON_AddNumberToObject(o, "phase_confidence", phase_conf);
cJSON *seq = seqplay_status();
const cJSON *ro = cJSON_GetObjectItem(seq, "beat_readout");
if (cJSON_IsString(ro) && ro->valuestring[0]) {
snprintf(readout, sizeof(readout), "%s", ro->valuestring);
} else if (seqplay_done_readout()[0]) {
snprintf(readout, sizeof(readout), "%s", seqplay_done_readout());
} else if (running && bi.beat_count > 0) {
snprintf(readout, sizeof(readout), "%lu", (unsigned long)bi.beat_count);
} else {
readout[0] = 0;
}
cJSON_AddItemToObject(o, "sequence", seq);
cJSON *stride = cJSON_AddObjectToObject(o, "manual_beat_stride");
cJSON_AddFalseToObject(stride, "active"); // drivers step manual presets on the beats themselves
cJSON_AddStringToObject(o, "beat_readout", readout);
cJSON_AddNumberToObject(o, "beat_phase_ms", setting_int("audio_beat_phase_ms", 0, 0, 500));
cJSON_AddNumberToObject(o, "input_volume", setting_int("audio_input_volume", 100, 0, 200));
const cJSON *sw = cJSON_GetObjectItem(store_settings(), "sequence_switch_wait");
cJSON_AddStringToObject(o, "sequence_switch_wait_saved",
cJSON_IsString(sw) && !strcasecmp(sw->valuestring, "downbeat") ? "downbeat" : "beat");
cJSON_AddStringToObject(o, "sequence_switch_wait", seqplay_switch_wait());
cJSON_AddItemToObject(o, "audio_run", audio_run());
cJSON_AddNumberToObject(o, "audio_simulated_bpm", sim_bpm);
cJSON_AddItemToObject(o, "sequence_pending", seqplay_pending());
cJSON_AddBoolToObject(o, "bpm_simulated", !(running && bi.locked));
int sim_bar;
uint32_t tick;
seqplay_clock(&sim_bar, &tick);
cJSON_AddNumberToObject(o, "simulated_beat_tick", tick);
store_unlock();
return o;
}
static esp_err_t send_json(httpd_req_t *req, const char *status, cJSON *o)
{
char *s = cJSON_PrintUnformatted(o);
cJSON_Delete(o);
if (!s) {
return httpd_resp_send_500(req);
}
httpd_resp_set_status(req, status);
httpd_resp_set_type(req, "application/json");
esp_err_t r = httpd_resp_sendstr(req, s);
free(s);
return r;
}
static esp_err_t ok_with_status(httpd_req_t *req)
{
cJSON *o = cJSON_CreateObject();
cJSON_AddTrueToObject(o, "ok");
cJSON_AddItemToObject(o, "status", status_payload());
return send_json(req, "200 OK", o);
}
/* ------------------------------------------------------------ event stream */
static bool send_all(int fd, const char *p, size_t len)
{
while (len > 0) {
int sent = send(fd, p, len, 0);
if (sent <= 0) {
return false;
}
p += sent;
len -= sent;
}
return true;
}
static bool send_event(int fd, const char *type)
{
cJSON *o = cJSON_CreateObject();
cJSON_AddStringToObject(o, "type", type);
cJSON_AddItemToObject(o, "status", status_payload());
char *s = cJSON_PrintUnformatted(o);
cJSON_Delete(o);
bool ok = s && send_all(fd, "data: ", 6) && send_all(fd, s, strlen(s)) && send_all(fd, "\n\n", 2);
free(s);
return ok;
}
static void events_task(void *arg)
{
httpd_req_t *req = arg;
httpd_handle_t server = req->handle;
int fd = httpd_req_to_sockfd(req);
QueueHandle_t q = xQueueCreate(8, sizeof(beat_event_t));
static const char hdr[] = "HTTP/1.1 200 OK\r\nContent-Type: text/event-stream\r\nCache-Control: no-cache\r\n"
"Connection: close\r\n\r\n";
bool ok = q && beat_subscribe(q) == ESP_OK;
if (!ok) {
static const char busy[] = "HTTP/1.1 503 Service Unavailable\r\nConnection: close\r\n\r\nToo many listeners\n";
send_all(fd, busy, sizeof(busy) - 1);
} else {
ok = send_all(fd, hdr, sizeof(hdr) - 1) && send_event(fd, "status");
}
int64_t next = esp_timer_get_time() + EVENTS_HEARTBEAT_US;
while (ok) {
int64_t now = esp_timer_get_time();
beat_event_t ev;
if (now >= next) {
ok = send_event(fd, "status");
next = now + EVENTS_HEARTBEAT_US;
} else if (xQueueReceive(q, &ev, pdMS_TO_TICKS((next - now) / 1000) + 1) == pdTRUE && ev == BEAT_EVENT_BEAT) {
vTaskDelay(pdMS_TO_TICKS(20)); // let the sequencer count this beat first
ok = send_event(fd, "beat");
}
}
if (q) {
beat_unsubscribe(q);
vQueueDelete(q);
}
httpd_req_async_handler_complete(req);
httpd_sess_trigger_close(server, fd);
vTaskDelete(NULL);
}
static esp_err_t events(httpd_req_t *req)
{
httpd_req_t *async_req = NULL;
if (httpd_req_async_handler_begin(req, &async_req) != ESP_OK) {
return ESP_FAIL;
}
if (xTaskCreate(events_task, "audio_events", 6144, async_req, 5, NULL) != pdPASS) {
httpd_req_async_handler_complete(async_req);
return ESP_FAIL;
}
return ESP_OK;
}
/* --------------------------------------------------------------- handlers */
static esp_err_t audio_handler(httpd_req_t *req)
{
const char *action = req->uri + strlen("/api/audio/");
size_t alen = strcspn(action, "?");
char act[16] = "";
if (alen < sizeof(act)) {
memcpy(act, action, alen);
}
if (req->method == HTTP_GET && !strcmp(act, "status")) {
cJSON *o = cJSON_CreateObject();
cJSON_AddItemToObject(o, "status", status_payload());
return send_json(req, "200 OK", o);
}
if (req->method == HTTP_GET && !strcmp(act, "events")) {
return events(req);
}
if (req->method == HTTP_GET && !strcmp(act, "devices")) {
cJSON *o = cJSON_CreateObject(), *devs = cJSON_AddArrayToObject(o, "devices"), *d = cJSON_CreateObject();
cJSON_AddStringToObject(d, "id", "i2s");
cJSON_AddStringToObject(d, "name", "I2S microphone");
cJSON_AddStringToObject(d, "display_name", "I2S microphone");
cJSON_AddTrueToObject(d, "is_default");
cJSON_AddItemToArray(devs, d);
cJSON_AddObjectToObject(o, "diagnostics");
return send_json(req, "200 OK", o);
}
if (req->method == HTTP_PUT && !strcmp(act, "device")) {
cJSON *body = api_body_opt(req);
if (!body) {
return ESP_OK;
}
const cJSON *sel = cJSON_GetObjectItem(body, "device_select");
store_lock();
api_set(store_settings(), "audio_device_select", cJSON_CreateString(cJSON_IsString(sel) ? sel->valuestring : ""));
store_save("settings");
cJSON *o = cJSON_CreateObject();
cJSON_AddTrueToObject(o, "ok");
cJSON_AddItemToObject(o, "audio_run", audio_run());
store_unlock();
cJSON_Delete(body);
return send_json(req, "200 OK", o);
}
if (req->method != HTTP_POST) {
return httpd_resp_send_404(req);
}
if (!strcmp(act, "start") || !strcmp(act, "stop")) {
seqplay_set_audio(act[2] == 'a'); // st[a]rt
ESP_LOGI(TAG, "mic beats %s sequences", act[2] == 'a' ? "time" : "no longer time");
return ok_with_status(req);
}
if (!strcmp(act, "reset") || !strcmp(act, "anchor-bar")) {
if (!seqplay_audio()) {
cJSON *o = cJSON_CreateObject();
cJSON_AddFalseToObject(o, "ok");
cJSON_AddStringToObject(o, "error", "Audio detector is not running");
return send_json(req, "409 Conflict", o);
}
if (act[0] == 'r') {
beat_reset();
} else {
beat_tap();
}
return ok_with_status(req);
}
return httpd_resp_send_404(req);
}
esp_err_t audio_api_register(httpd_handle_t server)
{
static const httpd_method_t METHODS[] = { HTTP_GET, HTTP_POST, HTTP_PUT };
for (size_t m = 0; m < 3; m++) {
httpd_uri_t u = { .uri = "/api/audio/*", .method = METHODS[m], .handler = audio_handler };
esp_err_t err = httpd_register_uri_handler(server, &u);
if (err != ESP_OK) {
return err;
}
}
return ESP_OK;
}
-7
View File
@@ -1,7 +0,0 @@
#pragma once
#include "esp_err.h"
#include "esp_http_server.h"
// /api/audio/{status,events,devices,device,start,stop,reset,anchor-bar}: main's audio API (see audio_api.c)
esp_err_t audio_api_register(httpd_handle_t server);
-227
View File
@@ -1,227 +0,0 @@
/*
* Beat detection glue: runs beat_dsp on the mic feed, pulses the beat LED
* (longer on the downbeat), keeps the latest tempo and bar position for
* /status and fans events out to SSE listeners.
*/
#include <math.h>
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
#include "freertos/semphr.h"
#include "esp_log.h"
#include "esp_check.h"
#include "esp_timer.h"
#include "driver/gpio.h"
#include "beat_dsp.h"
#include "beat.h"
#define MAX_SUBSCRIBERS 4
#define LOG_EVERY_BEATS 64
static const char *TAG = "beat";
static beat_dsp_t s_dsp; // ~10 KB, too big for the mic task's stack
static portMUX_TYPE s_lock = portMUX_INITIALIZER_UNLOCKED;
static beat_info_t s_info;
// Queue sends may yield, so the subscriber list gets a mutex, not s_lock
static SemaphoreHandle_t s_subs_mutex;
static QueueHandle_t s_subs[MAX_SUBSCRIBERS];
static esp_timer_handle_t s_led_timer;
static bool s_was_locked;
static int64_t s_tap_us; // pending tap time, 0 if none (guarded by s_lock)
static void led_set(bool on)
{
#if CONFIG_BEAT_LED_GPIO >= 0
#if CONFIG_BEAT_LED_ACTIVE_LOW
on = !on;
#endif
gpio_set_level(CONFIG_BEAT_LED_GPIO, on);
#endif
}
static void led_off_cb(void *arg)
{
led_set(false);
}
static beat_cb_t s_cb;
void beat_set_callback(beat_cb_t cb)
{
s_cb = cb;
}
static void publish(beat_event_t ev)
{
xSemaphoreTake(s_subs_mutex, portMAX_DELAY);
for (int i = 0; i < MAX_SUBSCRIBERS; i++) {
if (s_subs[i]) {
// A slow listener just misses events rather than stalling audio
xQueueSend(s_subs[i], &ev, 0);
}
}
xSemaphoreGive(s_subs_mutex);
}
static void dsp_event(void *ctx, int events, const beat_dsp_t *d)
{
int64_t now = esp_timer_get_time();
beat_info_t info;
portENTER_CRITICAL(&s_lock);
if (events & BEAT_EV_ONSET) {
s_info.onset_count++;
s_info.last_onset_us = now;
}
if (events & BEAT_EV_BEAT) {
s_info.beat_count++;
s_info.last_beat_us = now;
s_info.meter = d->meter;
s_info.bar_beat = d->bar_beat;
s_info.bar_sure = d->bar_sure;
}
if (events & BEAT_EV_DOWNBEAT) {
s_info.downbeat_count++;
}
info = s_info;
portEXIT_CRITICAL(&s_lock);
if (events & BEAT_EV_ONSET) {
publish(BEAT_EVENT_ONSET);
}
if (events & BEAT_EV_BEAT) {
if (s_cb) {
s_cb(&info, beat_dsp_bpm(d), (events & BEAT_EV_DOWNBEAT) != 0);
}
led_set(true);
esp_timer_stop(s_led_timer);
int pulse_ms = events & BEAT_EV_DOWNBEAT ? CONFIG_BEAT_LED_DOWNBEAT_MS : CONFIG_BEAT_LED_PULSE_MS;
esp_timer_start_once(s_led_timer, pulse_ms * 1000);
publish(BEAT_EVENT_BEAT);
if (info.beat_count % LOG_EVERY_BEATS == 0) {
ESP_LOGI(TAG, "%.1f BPM, confidence %.2f, %lu beats, %d/4 time, bar contrast %.2f",
beat_dsp_bpm(d), d->confidence, (unsigned long)info.beat_count, d->meter, d->bar_contrast);
}
}
}
static float s_rate;
static bool s_reset;
esp_err_t beat_start(float sample_rate)
{
float gate_rms = powf(10.0f, CONFIG_BEAT_GATE_DBFS / 20.0f);
s_rate = sample_rate;
beat_dsp_init(&s_dsp, sample_rate, gate_rms, CONFIG_BEAT_LEAD_MS / 1000.0f);
s_info.meter = s_dsp.meter;
s_subs_mutex = xSemaphoreCreateMutex();
ESP_RETURN_ON_FALSE(s_subs_mutex, ESP_ERR_NO_MEM, TAG, "Mutex alloc failed");
#if CONFIG_BEAT_LED_GPIO >= 0
gpio_config_t io = {
.pin_bit_mask = 1ULL << CONFIG_BEAT_LED_GPIO,
.mode = GPIO_MODE_OUTPUT,
};
ESP_RETURN_ON_ERROR(gpio_config(&io), TAG, "LED GPIO config failed");
#endif
led_set(false);
const esp_timer_create_args_t timer_args = { .callback = led_off_cb, .name = "beat_led" };
ESP_RETURN_ON_ERROR(esp_timer_create(&timer_args, &s_led_timer), TAG, "LED timer create failed");
ESP_LOGI(TAG, "Beat detection on, %.1f onset frames/s, gate %d dBFS",
s_dsp.frame_rate, CONFIG_BEAT_GATE_DBFS);
return ESP_OK;
}
void beat_reset(void)
{
portENTER_CRITICAL(&s_lock);
s_reset = true;
portEXIT_CRITICAL(&s_lock);
}
void beat_tap(void)
{
portENTER_CRITICAL(&s_lock);
s_tap_us = esp_timer_get_time();
portEXIT_CRITICAL(&s_lock);
}
void beat_feed(const float *x, size_t n)
{
portENTER_CRITICAL(&s_lock);
bool reset = s_reset;
s_reset = false;
portEXIT_CRITICAL(&s_lock);
if (reset) { // start tempo and bar tracking over, in the detector's task
beat_dsp_init(&s_dsp, s_rate, powf(10.0f, CONFIG_BEAT_GATE_DBFS / 20.0f), CONFIG_BEAT_LEAD_MS / 1000.0f);
portENTER_CRITICAL(&s_lock);
s_info.bar_beat = 0;
s_info.bar_sure = false;
s_info.meter = s_dsp.meter;
portEXIT_CRITICAL(&s_lock);
ESP_LOGI(TAG, "Tracking reset");
}
beat_dsp_feed(&s_dsp, x, n, dsp_event, NULL);
// Taps arrive from the HTTP task; apply them here, in the detector's task
portENTER_CRITICAL(&s_lock);
int64_t tap_us = s_tap_us;
s_tap_us = 0;
portEXIT_CRITICAL(&s_lock);
if (tap_us) {
// The newest analysed frame is ~30 ms behind real time (capture block
// plus half the FFT window), so the tap is that much further back
float ago_s = (esp_timer_get_time() - tap_us) / 1e6f + 0.03f;
beat_dsp_tap(&s_dsp, ago_s * s_dsp.frame_rate);
ESP_LOGI(TAG, "Tap: beat 1 set, holding the bar for a while");
}
portENTER_CRITICAL(&s_lock);
s_info.bpm = beat_dsp_bpm(&s_dsp);
s_info.confidence = s_dsp.confidence;
s_info.locked = s_dsp.locked;
portEXIT_CRITICAL(&s_lock);
if (s_dsp.locked != s_was_locked) {
s_was_locked = s_dsp.locked;
if (s_was_locked) {
ESP_LOGI(TAG, "Locked at %.1f BPM (confidence %.2f)", beat_dsp_bpm(&s_dsp), s_dsp.confidence);
} else {
ESP_LOGI(TAG, "Lost the beat");
}
}
}
void beat_get_info(beat_info_t *out)
{
portENTER_CRITICAL(&s_lock);
*out = s_info;
portEXIT_CRITICAL(&s_lock);
}
esp_err_t beat_subscribe(QueueHandle_t q)
{
esp_err_t ret = ESP_ERR_NO_MEM;
xSemaphoreTake(s_subs_mutex, portMAX_DELAY);
for (int i = 0; i < MAX_SUBSCRIBERS; i++) {
if (!s_subs[i]) {
s_subs[i] = q;
ret = ESP_OK;
break;
}
}
xSemaphoreGive(s_subs_mutex);
return ret;
}
void beat_unsubscribe(QueueHandle_t q)
{
// Once this returns the queue is no longer touched and can be deleted
xSemaphoreTake(s_subs_mutex, portMAX_DELAY);
for (int i = 0; i < MAX_SUBSCRIBERS; i++) {
if (s_subs[i] == q) {
s_subs[i] = NULL;
}
}
xSemaphoreGive(s_subs_mutex);
}
-51
View File
@@ -1,51 +0,0 @@
#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "esp_err.h"
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
typedef struct {
float bpm; // 0 until a tempo has been found
float confidence; // 0..1, how periodic the onsets are
bool locked; // beats are being emitted
uint32_t beat_count;
int64_t last_beat_us; // esp_timer time of the last beat, 0 if none
int meter; // beats per bar, 3 or 4
int bar_beat; // 1..meter of the last beat (best guess), 0 early on
bool bar_sure; // bar_beat is reliable, downbeats are being flashed
uint32_t downbeat_count;
uint32_t onset_count;
int64_t last_onset_us;
} beat_info_t;
// Event codes posted to subscriber queues
typedef enum {
BEAT_EVENT_ONSET,
BEAT_EVENT_BEAT,
} beat_event_t;
// Set up the detector and beat LED; call before feeding audio
esp_err_t beat_start(float sample_rate);
// Feed DC-free mono samples at full scale +/-1 (called from the mic task)
void beat_feed(const float *x, size_t n);
void beat_get_info(beat_info_t *out);
// The user tapped beat 1 just now: correct the bar position to match
void beat_tap(void);
// Forget the tempo and bar position and start tracking again
void beat_reset(void);
// Have beat_event_t values posted (without blocking) to a queue of
// beat_event_t. Returns ESP_ERR_NO_MEM when all subscriber slots are taken.
esp_err_t beat_subscribe(QueueHandle_t q);
void beat_unsubscribe(QueueHandle_t q);
// Called from the audio task the moment a beat is emitted, before any queue
// fan-out, so the radio can send it with minimal delay. Must not block.
typedef void (*beat_cb_t)(const beat_info_t *info, float bpm, bool downbeat);
void beat_set_callback(beat_cb_t cb);
-532
View File
@@ -1,532 +0,0 @@
/*
* Realtime beat tracker.
*
* 1. Onsets: every 16 ms, Hann-windowed 512-point FFT; novelty is the
* half-wave rectified rise in log magnitude (spectral flux) plus the rise
* in bass power. Log flux catches every instrument but rates a faint hat
* like a loud kick; the uncompressed bass term keeps the kick on the beat.
* 2. Tempo: every ~0.5 s, autocorrelate the last ~8 s of log flux alone
* (bass would pull rock with kicks on 1 and 3 to half time), weight
* lags with a log-normal prior around 120 BPM, and add the 2x lag so the
* bar-level pulse backs up the beat. A new tempo has to clearly beat the
* current one, several times in a row, before it is taken.
* 3. Phase: every frame, find the offset whose comb of past beat positions
* collects the most novelty. When that offset wraps back to zero a beat is
* due, so beats keep coming through quiet bars instead of only on onsets.
* 4. Lock: beats only go out while autocorrelation confidence times phase
* salience (on-grid vs. average onset energy) is high. Speech and noise
* can score on one of them but not both. Tuned on real music clips.
* 5. Bar: each grid beat gets two downbeat cues, the bass hit on it and how
* much new spectral energy its beat brings over the one before (chords
* change on the one). Cues are averaged per bar position
* for 3/4 and 4/4; the meter whose positions differ most wins, and its
* strongest position is the downbeat.
*/
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "beat_dsp.h"
#define NV_MASK (BEAT_NV_LEN - 1)
#define FLUX_MAX_BIN 192 // ~6 kHz; above that is mostly hats and hiss
#define BASS_MAX_BIN 6 // <~190 Hz, kick drums
#define BASS_WEIGHT 1.0f // bass power rise vs. full-band log flux
#define LOG_GAMMA 100.0f // log(1 + g*|X|) compression
#define TEMPO_EVERY 32 // frames between tempo estimates
#define TEMPO_MIN_EXTRA 128 // history beyond the longest lag before estimating
#define PRIOR_BPM 120.0f
#define PRIOR_OCTAVES 1.0f // std dev of the tempo prior
#define TEMPO_TOL 0.06f // relative change treated as the same tempo
#define TEMPO_MEMORY_S 3.0f // time constant of the history fade
#define TEMPO_MARGIN 1.5f // a new tempo must score this much better
#define TEMPO_SWITCH 3 // estimates in a row needed to jump tempo
#define COMB_BEATS 6 // past beats the phase comb looks at
#define COMB_DECAY 0.88f
#define PHASE_STICK 1.3f // bonus for the phase that follows on
#define LOCK_STRENGTH 0.9f // confidence x salience to start emitting beats
#define UNLOCK_STRENGTH 0.5f // ...and to keep going
#define ONSET_K 1.5f // onset threshold, x running novelty mean
#define ONSET_GAP_S 0.1f
#define SALIENCE_S 2.0f // smoothing of the on-beat energy ratio
#define ACTIVE_HOLD_S 2.0f // keep beating this long into silence
#define KICK_WEIGHT 1.0f // downbeat cue: bass hit on the beat
#define CHANGE_WEIGHT 1.0f // downbeat cue: spectral change into the beat
#define SPAN_FRAC 1.0f // part of each beat compared for harmonic change
#define BAR_RATE 0.08f // per-bar update rate of the position scores
#define BAR_MARGIN 1.1f // a new downbeat position must score this much more
#define METER_MARGIN 1.5f // ...and a new meter must stand out this much more
#define METER3_BIAS 0.5f // weight on the 3/4 evidence
#define BAR_SURE_ON 0.3f // contrast to call the bar position sure
#define BAR_SURE_OFF 0.2f // ...and to stop
#define BAR_WARMUP 8 // grid beats before guessing a bar position
#define TAP_BOOST 2.0f // head start for a tapped beat 1, x the best score
#define TAP_HOLD_BARS 16 // bars a tap holds the bar position
static float s_window[BEAT_FFT_SIZE];
static float s_cos[BEAT_FFT_SIZE / 2], s_sin[BEAT_FFT_SIZE / 2];
static uint16_t s_bitrev[BEAT_FFT_SIZE];
static int8_t s_band[FLUX_MAX_BIN + 1]; // bin -> band, -1 if unused
static float s_band_w[BEAT_BANDS]; // 1 / bins in band
static const int s_meters[BEAT_METERS] = {3, 4};
static bool s_tables_ready;
static void init_tables(void)
{
if (s_tables_ready) {
return;
}
const int n = BEAT_FFT_SIZE;
int bits = 0;
while ((1 << bits) < n) {
bits++;
}
for (int i = 0; i < n; i++) {
s_window[i] = 0.5f - 0.5f * cosf(2.0f * (float)M_PI * i / n);
int r = 0;
for (int b = 0; b < bits; b++) {
r |= ((i >> b) & 1) << (bits - 1 - b);
}
s_bitrev[i] = r;
}
for (int i = 0; i < n / 2; i++) {
s_cos[i] = cosf(2.0f * (float)M_PI * i / n);
s_sin[i] = -sinf(2.0f * (float)M_PI * i / n);
}
// Bands spaced evenly in log frequency from bin 2 (~60 Hz) up
int count[BEAT_BANDS] = {0};
for (int k = 0; k <= FLUX_MAX_BIN; k++) {
int b = k < 2 ? -1 : (int)(BEAT_BANDS * logf(k / 2.0f) / logf(FLUX_MAX_BIN / 2.0f));
s_band[k] = b < 0 ? -1 : b >= BEAT_BANDS ? BEAT_BANDS - 1 : b;
if (s_band[k] >= 0) {
count[s_band[k]]++;
}
}
for (int b = 0; b < BEAT_BANDS; b++) {
s_band_w[b] = count[b] ? 1.0f / count[b] : 0.0f;
}
s_tables_ready = true;
}
// In-place iterative radix-2 complex FFT
static void fft(float *re, float *im)
{
const int n = BEAT_FFT_SIZE;
for (int i = 0; i < n; i++) {
int j = s_bitrev[i];
if (j > i) {
float t = re[i]; re[i] = re[j]; re[j] = t;
t = im[i]; im[i] = im[j]; im[j] = t;
}
}
for (int len = 2; len <= n; len <<= 1) {
int half = len >> 1, step = n / len;
for (int start = 0; start < n; start += len) {
for (int k = 0; k < half; k++) {
float wr = s_cos[k * step], wi = s_sin[k * step];
int a = start + k, b = a + half;
float tr = re[b] * wr - im[b] * wi;
float ti = re[b] * wi + im[b] * wr;
re[b] = re[a] - tr; im[b] = im[a] - ti;
re[a] += tr; im[a] += ti;
}
}
}
}
static inline float nv_at(const beat_dsp_t *d, uint32_t i)
{
return d->nv[i & NV_MASK];
}
// Onsets can land a frame either side of the beat grid
static inline float nv_max3(const beat_dsp_t *d, uint32_t i, uint32_t cur)
{
float v = fmaxf(nv_at(d, i), nv_at(d, i - 1));
return i < cur ? fmaxf(v, nv_at(d, i + 1)) : v;
}
void beat_dsp_init(beat_dsp_t *d, float sample_rate, float gate_rms, float lead_s)
{
init_tables();
memset(d, 0, sizeof(*d));
d->frame_rate = sample_rate / BEAT_HOP;
d->gate_rms = gate_rms;
d->lead_frames = (int)lrintf(lead_s * d->frame_rate);
d->min_lag = (int)floorf(d->frame_rate * 60.0f / BEAT_MAX_BPM);
d->max_lag = (int)ceilf(d->frame_rate * 60.0f / BEAT_MIN_BPM);
// Start half a window in so the first frame comes after one hop
d->in_fill = BEAT_FFT_SIZE - BEAT_HOP;
d->meter = 4;
}
static float onset_strength(beat_dsp_t *d, bool *active, float *tempo_nv, float *bass_nv)
{
float sum_sq = 0.0f;
for (int i = 0; i < BEAT_FFT_SIZE; i++) {
float x = d->in[i];
sum_sq += x * x;
d->re[i] = x * s_window[i];
d->im[i] = 0.0f;
}
*active = sqrtf(sum_sq / BEAT_FFT_SIZE) >= d->gate_rms;
fft(d->re, d->im);
float flux = 0.0f, bass = 0.0f;
memset(d->band_now, 0, sizeof(d->band_now));
for (int k = 1; k <= FLUX_MAX_BIN; k++) {
float mag2 = d->re[k] * d->re[k] + d->im[k] * d->im[k];
float l = log1pf(LOG_GAMMA * sqrtf(mag2));
flux += fmaxf(l - d->prev_log[k], 0.0f);
d->prev_log[k] = l;
if (s_band[k] >= 0) {
d->band_now[s_band[k]] += l * s_band_w[s_band[k]];
}
if (k <= BASS_MAX_BIN) {
bass += mag2;
}
}
float bass_rise = fmaxf(bass - d->prev_bass, 0.0f);
d->prev_bass = bass;
if (!*active) {
flux = bass_rise = 0.0f;
}
// Each channel minus its ~0.5 s running mean, so sustained texture
// doesn't count, and over it, so neither channel's units dominate
const float a = 1.0f / (0.5f * d->frame_rate);
d->flux_mean += a * (flux - d->flux_mean);
d->bass_mean += a * (bass_rise - d->bass_mean);
float full = fmaxf(flux - d->flux_mean, 0.0f) / (d->flux_mean + 1e-6f);
*tempo_nv = full;
*bass_nv = fmaxf(bass_rise - d->bass_mean, 0.0f) / (d->bass_mean + 1e-12f);
return full + BASS_WEIGHT * *bass_nv;
}
static void estimate_tempo(beat_dsp_t *d)
{
int n = d->t < BEAT_NV_LEN ? (int)d->t : BEAT_NV_LEN;
int top = 2 * (d->max_lag + 1);
if (n < top + TEMPO_MIN_EXTRA || top >= BEAT_AC_LEN) {
return;
}
// Oldest-first, mean-removed copy of the history (re[] is free here)
float *x = d->re, mean = 0.0f;
for (int i = 0; i < n; i++) {
x[i] = d->tempo_nv[(d->t - n + i) & NV_MASK];
mean += x[i];
}
mean /= n;
// Fade older frames so a tempo change wins within a few seconds
const float fade = expf(-1.0f / (TEMPO_MEMORY_S * d->frame_rate));
float w = 1.0f;
for (int i = n - 1; i >= 0; i--) {
x[i] = (x[i] - mean) * w;
w *= fade;
}
for (int l = 0; l <= top; l++) {
float s = 0.0f;
for (int i = l; i < n; i++) {
s += x[i] * x[i - l];
}
d->ac[l] = s / (n - l);
}
if (d->ac[0] <= 1e-9f) {
d->confidence *= 0.5f;
return;
}
// score[l] for l in [min_lag-1, max_lag+1], kept in im[] for interpolation
float *score = d->im;
const float l0 = d->frame_rate * 60.0f / PRIOR_BPM;
int best = d->min_lag;
for (int l = d->min_lag - 1; l <= d->max_lag + 1; l++) {
float o = log2f((float)l / l0) / PRIOR_OCTAVES;
// The 2x lag backs up a beat but can't carry it: in 3/4, 2/3 of the
// beat is barely periodic yet its double is a whole bar
score[l] = expf(-0.5f * o * o) * (d->ac[l] + 0.5f * fminf(d->ac[2 * l], fmaxf(d->ac[l], 0.0f)));
if (l >= d->min_lag && l <= d->max_lag && score[l] > score[best]) {
best = l;
}
}
// Hold the current tempo unless another clearly beats it; real music
// often has a 3:2 or 2:1 alternative that is nearly as periodic
if (d->period > 0.0f) {
int lo = (int)fmaxf(floorf(d->period * (1.0f - TEMPO_TOL)), d->min_lag);
int hi = (int)fminf(ceilf(d->period * (1.0f + TEMPO_TOL)), d->max_lag);
int near = lo;
for (int l = lo + 1; l <= hi; l++) {
if (score[l] > score[near]) {
near = l;
}
}
if (score[near] > 0.0f && score[best] < TEMPO_MARGIN * score[near]) {
best = near;
}
}
float a = score[best - 1], b = score[best], c = score[best + 1];
float denom = a - 2.0f * b + c;
float period = best + (denom < 0.0f ? 0.5f * (a - c) / denom : 0.0f);
float conf = fminf(fmaxf(d->ac[best] / d->ac[0], 0.0f), 1.0f);
d->confidence += 0.3f * (conf - d->confidence);
if (d->period == 0.0f) {
d->period = period; // tentative; locking decides whether beats go out
} else if (fabsf(period / d->period - 1.0f) < TEMPO_TOL) {
d->period += 0.2f * (period - d->period);
d->pending_count = 0;
} else if (d->pending_count > 0 && fabsf(period / d->pending_period - 1.0f) < TEMPO_TOL) {
if (++d->pending_count >= TEMPO_SWITCH) {
d->period = period;
d->pending_count = 0;
}
} else {
d->pending_period = period;
d->pending_count = 1;
}
}
// Frames since the most recent beat according to the comb over past beats
static int best_phase(beat_dsp_t *d, uint32_t cur)
{
const float p = d->period;
const int np = (int)p;
const int expect = (d->prev_phase - d->lead_frames + 1 + 2 * np) % np;
int best = 0;
float best_score = -1.0f, total = 0.0f;
for (int phi = 0; phi < np; phi++) {
float s = 0.0f, w = 1.0f;
for (int k = 0; k < COMB_BEATS; k++) {
float back = phi + k * p;
if (back >= BEAT_NV_LEN - 2 || back > cur) {
break;
}
s += w * nv_max3(d, cur - (uint32_t)lrintf(back), cur);
w *= COMB_DECAY;
}
total += s;
if (abs(phi - expect) <= 1) {
s *= PHASE_STICK;
}
if (s > best_score) {
best_score = s;
best = phi;
}
}
// How much more onset energy sits on the beat grid than off it
float salience = total > 0.0f ? best_score * np / total : 0.0f;
// Plain running mean until the window fills, so locking isn't held back
float span = fminf(SALIENCE_S * d->frame_rate, (float)++d->salience_n);
d->salience += (salience - d->salience) / span;
return best;
}
// Add one cue value to the bar position of grid beat n, for every meter
static void bar_cue(beat_dsp_t *d, uint32_t n, float v)
{
for (int m = 0; m < BEAT_METERS; m++) {
float *s = &d->bar_score[m][n % s_meters[m]];
*s += BAR_RATE * (v - *s);
}
}
// Pick the downbeat position per meter, then the meter, with hysteresis
static void bar_decide(beat_dsp_t *d)
{
float contrast[BEAT_METERS];
for (int m = 0; m < BEAT_METERS; m++) {
const int len = s_meters[m];
const float *s = d->bar_score[m];
int best = 0;
float mean = 0.0f;
for (int i = 0; i < len; i++) {
mean += s[i] / len;
if (s[i] > s[best]) {
best = i;
}
}
// A tap holds the bar for a while; the audio only takes over after
if (d->tap_hold == 0 && s[best] > BAR_MARGIN * s[d->down_pos[m]]) {
d->down_pos[m] = best;
}
contrast[m] = mean > 0.0f ? s[d->down_pos[m]] / mean - 1.0f : 0.0f;
}
// Most music is in 4/4, so 3/4 has to make a stronger case
contrast[0] *= METER3_BIAS;
int cur = d->meter == 3 ? 0 : 1, other = 1 - cur;
if (d->tap_hold == 0 && contrast[other] > METER_MARGIN * contrast[cur]) {
cur = other;
}
d->meter = s_meters[cur];
d->bar_contrast = contrast[cur];
}
// Runs a couple of frames after grid beat pending_n landed
static void analyse_beat(beat_dsp_t *d)
{
uint32_t beat = d->pending_frame - 2;
float kick = 0.0f;
for (uint32_t i = beat - 1; i <= beat + 2; i++) {
kick = fmaxf(kick, d->bass_nv[i & NV_MASK]);
}
d->kick_mean += 0.1f * (kick - d->kick_mean);
bar_cue(d, d->pending_n, KICK_WEIGHT * kick / (d->kick_mean + 1e-6f));
bar_decide(d);
d->pending = false;
}
// A beat just landed: close the spectrum of the previous beat and score how
// much new energy it brought over the one before as a bar start
static void close_span(beat_dsp_t *d)
{
if (d->band_frames > 0) {
float change = 0.0f;
for (int b = 0; b < BEAT_BANDS; b++) {
float v = d->band_acc[b] / d->band_frames;
// Rises only: a chord fading out late in the bar isn't a change
change += fmaxf(v - d->prev_span[b], 0.0f);
d->prev_span[b] = v;
d->band_acc[b] = 0.0f;
}
d->band_frames = 0;
d->change_mean += 0.1f * (change - d->change_mean);
if (d->span_n > 0) { // the first span has nothing to compare with
bar_cue(d, d->span_n, CHANGE_WEIGHT * change / (d->change_mean + 1e-6f));
}
}
d->span_n = d->pending_n;
}
static int process_frame(beat_dsp_t *d)
{
int events = 0;
bool active;
float tempo_nv, bass_nv;
float nv = onset_strength(d, &active, &tempo_nv, &bass_nv);
uint32_t cur = d->t++;
d->nv[cur & NV_MASK] = nv;
d->tempo_nv[cur & NV_MASK] = tempo_nv;
d->bass_nv[cur & NV_MASK] = bass_nv;
if (d->pending && cur == d->pending_frame - 2) {
close_span(d);
}
if (d->period > 0.0f && cur - (d->pending_frame - 2) < SPAN_FRAC * d->period) {
for (int b = 0; b < BEAT_BANDS; b++) {
d->band_acc[b] += d->band_now[b];
}
d->band_frames++;
}
if (d->pending && cur >= d->pending_frame) {
analyse_beat(d);
}
if (active) {
d->last_active = cur;
}
// Onset: previous frame is a local peak above the adaptive threshold
if (cur >= 2) {
uint32_t c = cur - 1;
float v = nv_at(d, c);
if (v > nv_at(d, c - 1) && v >= nv && v > ONSET_K * d->nv_mean + 1e-3f &&
(d->last_onset == 0 || c - d->last_onset >= ONSET_GAP_S * d->frame_rate)) {
d->last_onset = c;
events |= BEAT_EV_ONSET;
}
}
d->nv_mean += (nv - d->nv_mean) / d->frame_rate;
if (d->t % TEMPO_EVERY == 0) {
estimate_tempo(d);
}
if (d->period == 0.0f) {
return events;
}
bool audible = cur - d->last_active < ACTIVE_HOLD_S * d->frame_rate;
// Speech and noise can score on one measure, music with a beat on both
float strength = d->confidence * d->salience;
d->locked = audible && strength >= (d->locked ? UNLOCK_STRENGTH : LOCK_STRENGTH);
// Shifting the phase by the lead makes it wrap that many frames early
int np = (int)d->period;
int phase = (best_phase(d, cur) + d->lead_frames) % np;
// Phase dropping by more than half a beat means it wrapped: beat due now
if (phase + d->period / 2 < d->prev_phase && cur - d->last_beat >= d->period / 2) {
if (d->pending) {
if (cur < d->pending_frame - 2) {
close_span(d);
}
analyse_beat(d);
}
uint32_t n = d->grid_n++;
int pos = (int)((n + 4 * 3 - (uint32_t)d->down_pos[d->meter == 3 ? 0 : 1]) % d->meter);
// Always offer a best guess, but only call downbeats when sure
if (d->tap_hold > 0) {
d->tap_hold--;
d->bar_beat = pos + 1;
d->bar_sure = true;
} else {
d->bar_beat = n >= BAR_WARMUP ? pos + 1 : 0;
d->bar_sure = d->bar_contrast >= (d->bar_sure ? BAR_SURE_OFF : BAR_SURE_ON);
}
if (d->locked) {
events |= BEAT_EV_BEAT;
if (d->bar_beat == 1 && d->bar_sure) {
events |= BEAT_EV_DOWNBEAT;
}
}
d->last_beat = cur;
// The beat lands lead_frames from now; look at it 2 frames after
d->pending_frame = cur + d->lead_frames + 2;
d->pending_n = n;
d->pending = true;
}
d->prev_phase = phase;
return events;
}
void beat_dsp_tap(beat_dsp_t *d, float frames_ago)
{
if (d->period <= 0.0f || d->grid_n == 0) {
return;
}
// Grid beat grid_n - 1 lands lead_frames after it was announced; snap the
// tap to that beat or the one either side, whichever is nearest
float tap = (float)d->t - frames_ago;
float last = (float)(d->last_beat + d->lead_frames);
int k = (int)lrintf((tap - last) / d->period);
k = k < -1 ? -1 : k > 1 ? 1 : k;
int32_t n = (int32_t)d->grid_n - 1 + k;
n = n < 0 ? 0 : n;
for (int m = 0; m < BEAT_METERS; m++) {
float top = 1e-3f;
for (int i = 0; i < s_meters[m]; i++) {
top = fmaxf(top, d->bar_score[m][i]);
}
int pos = n % s_meters[m];
d->bar_score[m][pos] = TAP_BOOST * top;
d->down_pos[m] = pos;
}
d->tap_hold = TAP_HOLD_BARS * d->meter;
d->bar_sure = true;
}
void beat_dsp_feed(beat_dsp_t *d, const float *x, size_t n, beat_dsp_cb_t cb, void *ctx)
{
while (n > 0) {
size_t take = BEAT_FFT_SIZE - d->in_fill;
take = take < n ? take : n;
memcpy(d->in + d->in_fill, x, take * sizeof(float));
d->in_fill += take;
x += take;
n -= take;
if (d->in_fill < BEAT_FFT_SIZE) {
break;
}
int events = process_frame(d);
memmove(d->in, d->in + BEAT_HOP, (BEAT_FFT_SIZE - BEAT_HOP) * sizeof(float));
d->in_fill = BEAT_FFT_SIZE - BEAT_HOP;
if (events && cb) {
cb(ctx, events, d);
}
}
}
-98
View File
@@ -1,98 +0,0 @@
#pragma once
/*
* Realtime beat tracker, plain C with no ESP-IDF dependencies so it can be
* tested on a PC. Spectral-flux onsets -> autocorrelation tempo -> comb-filter
* phase tracking that predicts beats from the last few bars -> bar position
* (downbeats and 3/4 vs 4/4) from bass hits and harmonic changes per beat.
*/
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#define BEAT_FFT_SIZE 512 // 32 ms window at 16 kHz
#define BEAT_HOP 256 // 16 ms between onset frames
#define BEAT_NV_LEN 512 // onset history (~8 s), power of two
#define BEAT_MIN_BPM 60.0f
#define BEAT_MAX_BPM 200.0f
#define BEAT_AC_LEN (BEAT_NV_LEN / 2) // autocorrelation lags kept
#define BEAT_BANDS 16 // log-spaced bands for harmonic change
#define BEAT_METERS 2 // 3/4 and 4/4
#define BEAT_EV_ONSET 0x1
#define BEAT_EV_BEAT 0x2
#define BEAT_EV_DOWNBEAT 0x4 // with BEAT_EV_BEAT, when the bar is sure
typedef struct {
// Settings (from beat_dsp_init)
float frame_rate; // onset frames per second
float gate_rms; // frames quieter than this are treated as silence
int min_lag, max_lag; // beat period search range, frames
int lead_frames; // emit predicted beats this early
// Onset detection
float in[BEAT_FFT_SIZE];
size_t in_fill;
float re[BEAT_FFT_SIZE], im[BEAT_FFT_SIZE]; // FFT work, reused as scratch
float prev_log[BEAT_FFT_SIZE / 2 + 1];
float prev_bass;
float flux_mean, bass_mean, nv_mean;
float nv[BEAT_NV_LEN]; // novelty (onset strength) ring, indexed by frame
float tempo_nv[BEAT_NV_LEN]; // log flux only, for the tempo estimate
float bass_nv[BEAT_NV_LEN]; // bass rise only, for downbeats
uint32_t t; // frames processed
uint32_t last_active, last_onset;
// Tempo
float ac[BEAT_AC_LEN];
float period; // frames per beat, 0 until found
float confidence; // 0..1 periodicity of the onset envelope
float pending_period;
int pending_count;
// Beat phase
float salience; // on-beat vs. average onset energy, 1 = no beat
uint32_t salience_n;
int prev_phase;
uint32_t last_beat;
bool locked;
// Bar position. Grid beats are numbered whether or not they are emitted;
// each one is analysed a couple of frames after it lands.
uint32_t grid_n; // grid beats so far
uint32_t pending_frame; // frame to analyse the latest beat at
uint32_t pending_n; // its grid number
bool pending;
float band_now[BEAT_BANDS]; // log band energy of the current frame
float band_acc[BEAT_BANDS]; // ...summed over the start of the latest beat
float prev_span[BEAT_BANDS]; // ...averaged over the start of the one before
int band_frames;
uint32_t span_n; // grid number of the beat band_acc belongs to
float kick_mean, change_mean;
float bar_score[BEAT_METERS][4]; // cue strength per meter and position
int down_pos[BEAT_METERS]; // grid_n % meter of the downbeat
int meter; // 3 or 4
float bar_contrast; // how clearly one position stands out
int bar_beat; // 1..meter of the last grid beat (best guess), 0 early on
bool bar_sure; // bar_beat is reliable; downbeats only go out then
uint32_t tap_hold; // grid beats left that a tap holds the bar for
} beat_dsp_t;
// lead_s fires predicted beats early to cover capture and output latency
void beat_dsp_init(beat_dsp_t *d, float sample_rate, float gate_rms, float lead_s);
// Feed mono samples scaled to +/-1. Calls cb once per frame that produced
// events (BEAT_EV_* bits). Beats are predicted, so they arrive lead_s ahead
// of the frame they belong to; onsets need one frame of lookahead.
typedef void (*beat_dsp_cb_t)(void *ctx, int events, const beat_dsp_t *d);
void beat_dsp_feed(beat_dsp_t *d, const float *x, size_t n, beat_dsp_cb_t cb, void *ctx);
// The user tapped beat 1 frames_ago frames back: make the nearest grid beat
// beat 1 and hold that for a while before the audio can move it again
void beat_dsp_tap(beat_dsp_t *d, float frames_ago);
static inline float beat_dsp_bpm(const beat_dsp_t *d)
{
return d->period > 0.0f ? 60.0f * d->frame_rate / d->period : 0.0f;
}
-241
View File
@@ -1,241 +0,0 @@
#include "bench.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
#include "driver/gpio.h"
#include "esp_timer.h"
#include "espnow_tx.h"
#include "freertos/FreeRTOS.h"
#include "freertos/portmacro.h"
#include "freertos/queue.h"
#include "freertos/task.h"
#define RING 64
#define MAX_DRIVERS 8
typedef struct {
uint16_t idx;
int64_t tx_us;
int64_t first_us, last_us;
uint8_t echoes;
int fire_in_ms;
} beat_t;
typedef struct {
uint8_t mac[6];
uint32_t echoes;
} drv_t;
static portMUX_TYPE s_mux = portMUX_INITIALIZER_UNLOCKED;
static beat_t s_ring[RING];
static drv_t s_drv[MAX_DRIVERS];
static uint32_t s_sent, s_echoes, s_late_echoes;
static int64_t s_min_us, s_max_us, s_sum_us;
static int64_t s_spread_sum, s_spread_max;
static uint32_t s_spread_n;
static int s_remaining;
static bool s_running;
static float s_bpm;
#if CONFIG_BEAT_TEST_GPIO >= 0
static bool s_gpio_ready;
static int s_level;
#endif
static esp_timer_handle_t s_timer;
static QueueHandle_t s_logq;
// USB latency test: one "BT <idx> <esp_timer us>" line per synthetic beat, printed from a low-priority
// task so the beat path itself never waits on the console. tools/usb_latency.py reads these.
typedef struct {
uint16_t idx;
int64_t tx_us;
} beat_log_t;
static void log_task(void *arg)
{
beat_log_t l;
for (;;) {
if (xQueueReceive(s_logq, &l, portMAX_DELAY) == pdTRUE) {
printf("BT %u %lld\n", l.idx, (long long)l.tx_us);
}
}
}
static uint32_t s_gen_count;
static void gpio_mark(void)
{
#if CONFIG_BEAT_TEST_GPIO >= 0
if (!s_gpio_ready) {
gpio_set_direction(CONFIG_BEAT_TEST_GPIO, GPIO_MODE_OUTPUT);
s_gpio_ready = true;
}
s_level = !s_level;
gpio_set_level(CONFIG_BEAT_TEST_GPIO, s_level);
#endif
}
void bench_on_beat_tx(uint16_t idx, int64_t tx_us, int fire_in_ms)
{
gpio_mark(); // edge as the first copy goes out
if (s_running && s_logq) {
beat_log_t l = { .idx = idx, .tx_us = tx_us };
xQueueSend(s_logq, &l, 0);
}
portENTER_CRITICAL(&s_mux);
beat_t *b = &s_ring[idx % RING];
memset(b, 0, sizeof(*b));
b->idx = idx;
b->tx_us = tx_us;
b->fire_in_ms = fire_in_ms;
s_sent++;
portEXIT_CRITICAL(&s_mux);
}
void bench_on_echo(const uint8_t mac[6], uint16_t idx, int64_t rx_us)
{
portENTER_CRITICAL(&s_mux);
beat_t *b = &s_ring[idx % RING];
if (b->idx != idx || b->tx_us == 0) {
s_late_echoes++; // beat already overwritten in the ring
portEXIT_CRITICAL(&s_mux);
return;
}
// Round trip minus the deliberate fire_in wait: airtime out + driver work + airtime back
int64_t dt = rx_us - b->tx_us - (int64_t)b->fire_in_ms * 1000;
if (s_echoes == 0 || dt < s_min_us) {
s_min_us = dt;
}
if (s_echoes == 0 || dt > s_max_us) {
s_max_us = dt;
}
s_sum_us += dt;
s_echoes++;
if (b->echoes++ == 0) {
b->first_us = rx_us;
} else {
int64_t spread = rx_us - b->first_us;
if (spread > s_spread_max) {
s_spread_max = spread;
}
s_spread_n++; // one sample per extra driver that heard this beat
s_spread_sum += spread;
}
b->last_us = rx_us;
drv_t *d = NULL;
for (int i = 0; i < MAX_DRIVERS && !d; i++) {
if (memcmp(s_drv[i].mac, mac, 6) == 0 && s_drv[i].echoes) {
d = &s_drv[i];
}
}
for (int i = 0; i < MAX_DRIVERS && !d; i++) {
if (!s_drv[i].echoes) {
d = &s_drv[i];
memcpy(d->mac, mac, 6);
}
}
if (d) {
d->echoes++;
}
portEXIT_CRITICAL(&s_mux);
}
static void gen_cb(void *arg)
{
if (!s_running) {
return;
}
s_gen_count++;
// Downbeat on every fourth beat, like a 4/4 bar
espnow_tx_beat(s_bpm, (s_gen_count % 4) == 1, ((s_gen_count - 1) % 4) + 1);
if (s_remaining > 0 && --s_remaining == 0) {
bench_stop();
}
}
esp_err_t bench_start(float bpm, int count)
{
if (bpm < 30 || bpm > 300) {
return ESP_ERR_INVALID_ARG;
}
bench_stop();
if (!s_logq) {
s_logq = xQueueCreate(32, sizeof(beat_log_t));
if (s_logq) {
xTaskCreate(log_task, "bench_log", 3072, NULL, 2, NULL);
}
}
portENTER_CRITICAL(&s_mux);
memset(s_ring, 0, sizeof(s_ring));
memset(s_drv, 0, sizeof(s_drv));
s_sent = s_echoes = s_late_echoes = 0;
s_min_us = s_max_us = s_sum_us = 0;
s_spread_sum = s_spread_max = 0;
s_spread_n = 0;
portEXIT_CRITICAL(&s_mux);
if (!s_timer) {
const esp_timer_create_args_t ta = { .callback = gen_cb, .name = "bench_beat", .dispatch_method = ESP_TIMER_TASK };
esp_err_t err = esp_timer_create(&ta, &s_timer);
if (err != ESP_OK) {
return err;
}
}
s_bpm = bpm;
s_remaining = count;
s_gen_count = 0;
s_running = true;
return esp_timer_start_periodic(s_timer, (uint64_t)(60e6 / bpm));
}
bool bench_running(void)
{
return s_running;
}
void bench_stop(void)
{
s_running = false;
if (s_timer) {
esp_timer_stop(s_timer);
}
}
cJSON *bench_results(void)
{
cJSON *o = cJSON_CreateObject();
portENTER_CRITICAL(&s_mux);
uint32_t sent = s_sent, echoes = s_echoes, late = s_late_echoes, spread_n = s_spread_n;
int64_t mn = s_min_us, mx = s_max_us, sum = s_sum_us, ssum = s_spread_sum, smax = s_spread_max;
drv_t drv[MAX_DRIVERS];
memcpy(drv, s_drv, sizeof(drv));
portEXIT_CRITICAL(&s_mux);
int ndrv = 0;
cJSON *drivers = cJSON_AddObjectToObject(o, "drivers");
for (int i = 0; i < MAX_DRIVERS; i++) {
if (drv[i].echoes) {
char key[13];
snprintf(key, sizeof(key), "%02x%02x%02x%02x%02x%02x", drv[i].mac[0], drv[i].mac[1], drv[i].mac[2],
drv[i].mac[3], drv[i].mac[4], drv[i].mac[5]);
cJSON *d = cJSON_AddObjectToObject(drivers, key);
cJSON_AddNumberToObject(d, "echoes", drv[i].echoes);
cJSON_AddNumberToObject(d, "hit_pct", sent ? 100.0 * drv[i].echoes / sent : 0);
ndrv++;
}
}
cJSON_AddBoolToObject(o, "running", s_running);
cJSON_AddNumberToObject(o, "beats_sent", sent);
cJSON_AddNumberToObject(o, "echoes", echoes);
cJSON_AddNumberToObject(o, "late_echoes", late);
// Fraction of beats each driver acted on; ~100 with the double send even at moderate loss
cJSON_AddNumberToObject(o, "hit_pct_total", sent && ndrv ? 100.0 * echoes / ((double)sent * ndrv) : 0);
cJSON_AddNumberToObject(o, "rtt_minus_lead_min_us", mn);
cJSON_AddNumberToObject(o, "rtt_minus_lead_avg_us", echoes ? (double)sum / echoes : 0);
cJSON_AddNumberToObject(o, "rtt_minus_lead_max_us", mx);
// Arrival spread between drivers for the same beat (needs two or more drivers echoing)
cJSON_AddNumberToObject(o, "spread_avg_us", spread_n ? (double)ssum / spread_n : 0);
cJSON_AddNumberToObject(o, "spread_max_us", smax);
bool beats_lossy;
cJSON_AddNumberToObject(o, "loss_pct", espnow_tx_loss(&beats_lossy));
cJSON_AddBoolToObject(o, "loss_includes_beats", beats_lossy);
return o;
}
-24
View File
@@ -1,24 +0,0 @@
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include "cJSON.h"
#include "esp_err.h"
// Bench-test helpers: a synthetic beat generator, an echo-based latency and
// delivery measurement, and the optional GPIO marker for a logic analyzer.
// Called by espnow_tx for every beat (first copy time, and how long drivers wait before firing)
void bench_on_beat_tx(uint16_t idx, int64_t tx_us, int fire_in_ms);
// A driver echoed beat `idx` right after it fired (called from the Wi-Fi task)
void bench_on_echo(const uint8_t mac[6], uint16_t idx, int64_t rx_us);
// Send `count` synthetic beats at `bpm` (count 0 = until stopped); resets the results
esp_err_t bench_start(float bpm, int count);
void bench_stop(void);
// True while the synthetic generator runs; mic beats are muted meanwhile so they cannot mix in
bool bench_running(void);
// Results so far; caller owns the object
cJSON *bench_results(void);
-99
View File
@@ -1,99 +0,0 @@
#include "bridge.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "lwip/netdb.h"
#include "lwip/sockets.h"
static const char *TAG = "bridge";
static int s_sock = -1;
static struct sockaddr_in s_peer;
static bridge_rx_cb_t s_cb;
static char s_addr[80];
static void rx_task(void *arg)
{
(void)arg;
uint8_t buf[6 + 256];
for (;;) {
int n = recv(s_sock, buf, sizeof(buf), 0);
if (n < 0) {
vTaskDelay(pdMS_TO_TICKS(100));
continue;
}
if (n > 6 && s_cb) {
s_cb(buf, buf + 6, n - 6);
}
}
}
esp_err_t bridge_start(const char *addr, bridge_rx_cb_t cb)
{
if (s_sock >= 0 || !addr || !addr[0]) {
return ESP_ERR_INVALID_STATE;
}
char host[64];
int port = BRIDGE_DEFAULT_PORT;
snprintf(host, sizeof(host), "%s", addr);
char *colon = strrchr(host, ':');
if (colon) {
*colon = 0;
port = atoi(colon + 1);
}
if (port <= 0 || port > 65535 || !host[0]) {
ESP_LOGE(TAG, "bad bridge address %s", addr);
return ESP_ERR_INVALID_ARG;
}
struct addrinfo hints = { .ai_family = AF_INET, .ai_socktype = SOCK_DGRAM }, *res = NULL;
if (getaddrinfo(host, NULL, &hints, &res) != 0 || !res) {
ESP_LOGE(TAG, "cannot resolve %s", host);
return ESP_FAIL;
}
memcpy(&s_peer, res->ai_addr, sizeof(s_peer));
freeaddrinfo(res);
s_peer.sin_port = htons(port);
int s = socket(AF_INET, SOCK_DGRAM, 0);
if (s < 0) {
return ESP_FAIL;
}
// connect() fixes the peer, so only its datagrams are received
if (connect(s, (struct sockaddr *)&s_peer, sizeof(s_peer)) != 0) {
close(s);
return ESP_FAIL;
}
s_sock = s;
s_cb = cb;
snprintf(s_addr, sizeof(s_addr), "%s:%d", host, port);
xTaskCreate(rx_task, "bridge_rx", 4096, NULL, 6, NULL);
ESP_LOGW(TAG, "ESP-NOW frames go to the UDP bridge %s, not the radio", s_addr);
return ESP_OK;
}
bool bridge_active(void)
{
return s_sock >= 0;
}
const char *bridge_addr(void)
{
return s_sock >= 0 ? s_addr : NULL;
}
esp_err_t bridge_send(const uint8_t *dst_mac, const void *data, size_t len)
{
if (s_sock < 0 || len > 250) {
return ESP_ERR_INVALID_STATE;
}
uint8_t buf[6 + 250];
memcpy(buf, dst_mac, 6);
memcpy(buf + 6, data, len);
// A refused datagram (the simulator is not running yet) is a lost frame, as on air
send(s_sock, buf, 6 + len, 0);
return ESP_OK;
}
-21
View File
@@ -1,21 +0,0 @@
#pragma once
// UDP bridge: carries the controller's ESP-NOW frames to a host that stands in for the radio, such as
// led-simulator (settings "bridge": "host:port"). Down: dst_mac(6) + packet. Up: src_mac(6) + packet.
// While it runs, nothing goes out over the air.
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "esp_err.h"
typedef void (*bridge_rx_cb_t)(const uint8_t *src_mac, const uint8_t *data, int len);
#define BRIDGE_DEFAULT_PORT 8766
// addr "host" or "host:port". Starts the receive task; frames arrive on cb.
esp_err_t bridge_start(const char *addr, bridge_rx_cb_t cb);
bool bridge_active(void);
esp_err_t bridge_send(const uint8_t *dst_mac, const void *data, size_t len);
// "host:port" while active, else NULL
const char *bridge_addr(void);
-504
View File
@@ -1,504 +0,0 @@
#include "drv_ota.h"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cJSON.h"
#include "esp_log.h"
#include "esp_random.h"
#include "mbedtls/sha256.h"
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
#include "freertos/semphr.h"
#include "freertos/task.h"
#include "rel.h"
#include "store.h"
static const char *TAG = "drv_ota";
#define WIRE_MAGIC 0x4C
#define OP_BEGIN 0x07
#define OP_DATA 0x08
#define OP_END 0x09
#define OP_COMMIT 0x0A
#define OP_ABORT 0x0B
#define OP_MISSING 0x0C
// Status codes from the driver
enum { C_OK, C_READY, C_SAME, C_BADHASH, C_INCOMPLETE, C_BADPATH, C_IOERR, C_NOSESS, C_TOOBIG, C_NCODES };
static const char *const CODE_NAMES[] = { "ok", "ready", "same", "badhash", "incomplete",
"badpath", "ioerr", "nosess", "toobig" };
#define CHUNK 944 // 4 link fragments; must match espnow_ota.CHUNK
#define MAX_FILE 65536
#define MAX_CHUNKS ((MAX_FILE + CHUNK - 1) / CHUNK)
#define MAX_MACS 32
#define MAX_PATH 128
#define ACK_MS 3000 // rel gives up after about 1 s; this only guards against a lost outcome
#define BEGIN_MS 1000 // per try: the driver hashes its current copy first
#define END_MS 2500 // per try: the driver hashes the staged copy (64 KB takes well under 1 s on a C3)
#define CMD_TRIES 5 // status replies are not acked, so a lost one costs a resend
#define REPAIR_ROUNDS 4
#define BCAST_GAP_MS 50 // between broadcast chunks: a C3 writing flash cannot take them faster
typedef struct {
uint8_t mac[6];
uint16_t sess;
uint8_t op, code;
uint8_t arg_len;
uint8_t arg[24];
} status_t;
typedef struct {
uint8_t mac[6];
char hex[13];
int state; // C_READY while in the transfer, C_SAME, C_OK when written, else the error
const char *err; // link-level failure text, when no driver code applies
int repaired;
} target_t;
static QueueHandle_t s_status_q;
static SemaphoreHandle_t s_busy;
static void on_status(const uint8_t mac[6], const uint8_t *pkt, int len)
{
if (len < 6) {
return;
}
status_t st = { .sess = pkt[2] | (pkt[3] << 8), .op = pkt[4], .code = pkt[5] };
memcpy(st.mac, mac, 6);
st.arg_len = len - 6 > (int)sizeof(st.arg) ? sizeof(st.arg) : len - 6;
memcpy(st.arg, pkt + 6, st.arg_len);
xQueueSend(s_status_q, &st, 0);
}
// Wait for this driver's reply to op; replies left over from earlier requests are dropped
static bool wait_status(const uint8_t *mac, uint16_t sess, uint8_t op, int timeout_ms, status_t *out)
{
TickType_t until = xTaskGetTickCount() + pdMS_TO_TICKS(timeout_ms);
for (;;) {
TickType_t now = xTaskGetTickCount();
if ((int32_t)(until - now) <= 0) {
return false;
}
if (xQueueReceive(s_status_q, out, until - now) != pdTRUE) {
return false;
}
if (out->sess == sess && out->op == op && memcmp(out->mac, mac, 6) == 0) {
return true;
}
}
}
static void drain_status(void)
{
status_t st;
while (xQueueReceive(s_status_q, &st, 0) == pdTRUE) {
}
}
// Acked command to one driver, then its status reply. Returns the code, or -1 if the driver never answered.
static int command(const uint8_t *mac, const uint8_t *pkt, size_t len, uint16_t sess, uint8_t op, int timeout_ms,
status_t *st)
{
status_t local;
st = st ? st : &local;
// Neither the reply nor a given-up ack proves the driver missed it: every command is safe to repeat
for (int t = 0; t < CMD_TRIES; t++) {
rel_send_wait(mac, pkt, len, ACK_MS);
if (wait_status(mac, sess, op, timeout_ms, st)) {
return st->code;
}
}
return -1;
}
static size_t data_pkt(uint8_t *pkt, uint16_t sess, int idx, const uint8_t *body, size_t size)
{
size_t off = (size_t)idx * CHUNK, n = size - off > CHUNK ? CHUNK : size - off;
pkt[0] = WIRE_MAGIC;
pkt[1] = OP_DATA;
pkt[2] = sess & 255;
pkt[3] = sess >> 8;
pkt[4] = idx & 255;
pkt[5] = idx >> 8;
memcpy(pkt + 6, body + off, n);
return 6 + n;
}
// Acked unicast of the chunks marked in want (NULL = all), two messages in flight.
// rel_send copies each message, so one packet buffer is enough. A chunk whose ack never came
// is left to the END/MISSING repair; only a run of them means the driver is gone.
#define DEAD_AFTER 8
static bool chunk_done(const uint8_t *mac, uint16_t seq, int *dead)
{
if (rel_wait(mac, seq, ACK_MS) == ESP_OK) {
*dead = 0;
return true;
}
return ++*dead < DEAD_AFTER;
}
static bool send_chunks(const uint8_t *mac, uint16_t sess, const uint8_t *body, size_t size, const uint8_t *want,
int *sent)
{
static uint8_t pkt[6 + CHUNK];
int cnt = (size + CHUNK - 1) / CHUNK;
uint16_t fifo[2];
int head = 0, inflight = 0, dead = 0;
for (int i = 0; i < cnt; i++) {
if (want && !(want[i >> 3] & (1 << (i & 7)))) {
continue;
}
if (inflight == 2) {
if (!chunk_done(mac, fifo[head], &dead)) {
return false;
}
head ^= 1;
inflight--;
}
size_t n = data_pkt(pkt, sess, i, body, size);
uint16_t seq;
esp_err_t err = ESP_ERR_NO_MEM;
for (int t = 0; t < 50 && err == ESP_ERR_NO_MEM; t++) {
err = rel_send_seq(mac, pkt, n, false, 1, &seq);
if (err == ESP_ERR_NO_MEM) {
vTaskDelay(pdMS_TO_TICKS(10));
}
}
if (err != ESP_OK) {
return false;
}
fifo[(head + inflight) & 1] = seq;
inflight++;
if (sent) {
(*sent)++;
}
}
for (; inflight > 0; inflight--, head ^= 1) {
if (!chunk_done(mac, fifo[head], &dead)) {
return false;
}
}
return true;
}
static void broadcast_chunks(uint16_t sess, const uint8_t *body, size_t size)
{
static uint8_t pkt[6 + CHUNK];
int cnt = (size + CHUNK - 1) / CHUNK;
for (int i = 0; i < cnt; i++) {
size_t n = data_pkt(pkt, sess, i, body, size);
for (int t = 0; t < 50 && rel_send(NULL, pkt, n, false, 1) == ESP_ERR_NO_MEM; t++) {
vTaskDelay(pdMS_TO_TICKS(10));
}
vTaskDelay(pdMS_TO_TICKS(BCAST_GAP_MS));
}
}
// END until the driver has every chunk: ask what is missing and resend it by unicast
static void finish(target_t *t, uint16_t sess, const uint8_t *body, size_t size)
{
uint8_t end[4] = { WIRE_MAGIC, OP_END, sess & 255, sess >> 8 };
uint8_t miss[4] = { WIRE_MAGIC, OP_MISSING, sess & 255, sess >> 8 };
for (int round = 0; round < REPAIR_ROUNDS; round++) {
int code = command(t->mac, end, sizeof(end), sess, OP_END, END_MS, NULL);
if (code != C_INCOMPLETE) {
t->state = code;
t->err = code < 0 ? "no reply to end" : NULL;
return;
}
status_t st;
if (command(t->mac, miss, sizeof(miss), sess, OP_MISSING, BEGIN_MS, &st) != C_OK || st.arg_len < 2) {
t->state = -1;
t->err = "no reply to missing";
return;
}
int cnt = st.arg[0] | (st.arg[1] << 8);
if (cnt != (int)((size + CHUNK - 1) / CHUNK) || st.arg_len < 2 + (cnt + 7) / 8) {
t->state = -1;
t->err = "bad missing reply";
return;
}
if (!send_chunks(t->mac, sess, body, size, st.arg + 2, &t->repaired)) {
t->state = -1;
t->err = "link lost";
return;
}
}
t->state = C_INCOMPLETE;
}
static void transfer(target_t *ts, int n, uint16_t sess, const char *path, const uint8_t sha[32], const uint8_t *body,
size_t size)
{
uint8_t begin[41 + MAX_PATH];
size_t plen = strlen(path);
begin[0] = WIRE_MAGIC;
begin[1] = OP_BEGIN;
begin[2] = sess & 255;
begin[3] = sess >> 8;
for (int i = 0; i < 4; i++) {
begin[4 + i] = (size >> (8 * i)) & 255;
}
memcpy(begin + 8, sha, 32);
begin[40] = plen;
memcpy(begin + 41, path, plen);
int ready = 0;
for (int i = 0; i < n; i++) {
int code = command(ts[i].mac, begin, 41 + plen, sess, OP_BEGIN, BEGIN_MS, NULL);
ts[i].state = code;
ts[i].err = code < 0 ? "no reply to begin" : NULL;
ready += code == C_READY;
}
if (ready == 0) {
return;
}
if (ready > 1) {
broadcast_chunks(sess, body, size);
} else {
for (int i = 0; i < n; i++) {
if (ts[i].state == C_READY && !send_chunks(ts[i].mac, sess, body, size, NULL, NULL)) {
ts[i].state = -1;
ts[i].err = "link lost";
}
}
}
for (int i = 0; i < n; i++) {
if (ts[i].state == C_READY) {
finish(&ts[i], sess, body, size);
}
}
}
static int parse_hex(const char *s, uint8_t *out, int n)
{
for (int i = 0; i < n; i++) {
unsigned v;
if (sscanf(s + 2 * i, "%2x", &v) != 1) {
return -1;
}
out[i] = v;
}
return s[2 * n] == '\0' || s[2 * n] == ',' ? 0 : -1;
}
// mac=all, or a comma-separated list of 12-hex addresses
static int parse_targets(const char *list, target_t *ts)
{
int n = 0;
if (!strcmp(list, "all")) {
store_lock();
const cJSON *d;
cJSON_ArrayForEach(d, store_coll("device"))
{
const cJSON *tr = cJSON_GetObjectItem(d, "transport"), *addr = cJSON_GetObjectItem(d, "address");
if (n < MAX_MACS && cJSON_IsString(tr) && !strcmp(tr->valuestring, "espnow") && cJSON_IsString(addr) &&
strlen(addr->valuestring) == 12 && parse_hex(addr->valuestring, ts[n].mac, 6) == 0) {
n++;
}
}
store_unlock();
} else {
for (const char *p = list; *p && n < MAX_MACS;) {
if (parse_hex(p, ts[n].mac, 6) != 0) {
return -1;
}
n++;
p += 12;
if (*p == ',') {
p++;
}
}
}
for (int i = 0; i < n; i++) {
uint8_t *m = ts[i].mac;
snprintf(ts[i].hex, sizeof(ts[i].hex), "%02x%02x%02x%02x%02x%02x", m[0], m[1], m[2], m[3], m[4], m[5]);
ts[i].state = -1;
ts[i].err = NULL;
ts[i].repaired = 0;
}
return n;
}
static esp_err_t send_json(httpd_req_t *req, const char *status, cJSON *obj)
{
char *s = cJSON_PrintUnformatted(obj);
cJSON_Delete(obj);
if (!s) {
return httpd_resp_send_500(req);
}
httpd_resp_set_status(req, status);
httpd_resp_set_type(req, "application/json");
esp_err_t r = httpd_resp_sendstr(req, s);
free(s);
return r;
}
static esp_err_t send_error(httpd_req_t *req, const char *status, const char *msg)
{
ESP_LOGW(TAG, "%s", msg);
cJSON *o = cJSON_CreateObject();
cJSON_AddStringToObject(o, "error", msg);
return send_json(req, status, o);
}
static cJSON *results(const target_t *ts, int n, bool file)
{
cJSON *o = cJSON_CreateObject();
for (int i = 0; i < n; i++) {
cJSON *e = cJSON_AddObjectToObject(o, ts[i].hex);
int s = ts[i].state;
const char *result = s == C_OK ? (file ? "written" : "ok") : s == C_SAME ? "same" : "error";
cJSON_AddStringToObject(e, "result", result);
if (s < 0) {
cJSON_AddStringToObject(e, "code", ts[i].err ? ts[i].err : "no reply");
} else if (s != C_OK && s != C_SAME) {
cJSON_AddStringToObject(e, "code", s < C_NCODES ? CODE_NAMES[s] : "unknown");
}
if (file) {
cJSON_AddNumberToObject(e, "repaired", ts[i].repaired);
}
}
return o;
}
static esp_err_t handle(httpd_req_t *req, const char *action, const char *query, target_t *ts, int n, uint16_t sess)
{
if (!strcmp(action, "commit") || !strcmp(action, "abort")) {
bool commit = action[0] == 'c';
uint8_t op = commit ? OP_COMMIT : OP_ABORT;
uint8_t pkt[4] = { WIRE_MAGIC, op, sess & 255, sess >> 8 };
for (int i = 0; i < n; i++) {
ts[i].state = command(ts[i].mac, pkt, sizeof(pkt), sess, op, BEGIN_MS, NULL);
}
return send_json(req, "200 OK", results(ts, n, false));
}
if (strcmp(action, "file")) {
return send_error(req, "404 Not Found", "unknown action");
}
char path[MAX_PATH + 1], shahex[65];
uint8_t sha[32];
if (httpd_query_key_value(query, "path", path, sizeof(path)) != ESP_OK || !path[0] ||
httpd_query_key_value(query, "sha", shahex, sizeof(shahex)) != ESP_OK || strlen(shahex) != 64 ||
parse_hex(shahex, sha, 32) != 0) {
return send_error(req, "400 Bad Request", "path and sha (64 hex) are required");
}
for (const char *c = path; *c; c++) { // query values arrive undecoded: keep paths to plain names
if (!(isalnum((unsigned char)*c) || *c == '_' || *c == '.' || *c == '/' || *c == '-')) {
return send_error(req, "400 Bad Request", "path may only hold letters, digits and _ . / -");
}
}
if (req->content_len > MAX_FILE) {
return send_error(req, "413 Payload Too Large", "file must be at most 65536 bytes");
}
uint8_t *body = malloc(req->content_len + 1); // empty files (__init__.py) are fine
if (!body) {
return send_error(req, "500 Internal Server Error", "out of memory");
}
size_t got = 0;
while (got < req->content_len) {
int r = httpd_req_recv(req, (char *)body + got, req->content_len - got);
if (r == HTTPD_SOCK_ERR_TIMEOUT) {
continue;
}
if (r <= 0) {
free(body);
return send_error(req, "400 Bad Request", "receive failed");
}
got += r;
}
ESP_LOGI(TAG, "%s (%u B) to %d driver(s), session %u", path, (unsigned)got, n, sess);
transfer(ts, n, sess, path, sha, body, got);
free(body);
return send_json(req, "200 OK", results(ts, n, true));
}
static esp_err_t ota_post_handler(httpd_req_t *req)
{
const char *action = req->uri + strlen("/drivers/ota/");
size_t alen = strcspn(action, "?");
char act[16] = "";
if (alen < sizeof(act)) {
memcpy(act, action, alen);
act[alen] = '\0';
}
char query[480], macs[400], sessbuf[8];
if (httpd_req_get_url_query_str(req, query, sizeof(query)) != ESP_OK ||
httpd_query_key_value(query, "mac", macs, sizeof(macs)) != ESP_OK ||
httpd_query_key_value(query, "sess", sessbuf, sizeof(sessbuf)) != ESP_OK) {
return send_error(req, "400 Bad Request", "mac and sess are required");
}
long sess = strtol(sessbuf, NULL, 10);
if (sess < 1 || sess > 0xFFFF) {
return send_error(req, "400 Bad Request", "sess must be 1..65535");
}
static target_t ts[MAX_MACS];
if (xSemaphoreTake(s_busy, 0) != pdTRUE) {
return send_error(req, "409 Conflict", "a driver update is already running");
}
esp_err_t r;
int n = parse_targets(macs, ts);
if (n <= 0) {
r = send_error(req, "400 Bad Request", n < 0 ? "bad mac list" : "no ESP-NOW drivers");
} else {
drain_status();
r = handle(req, act, query, ts, n, (uint16_t)sess);
}
xSemaphoreGive(s_busy);
return r;
}
cJSON *drv_ota_send(const char *macs, const char *path, const uint8_t *data, size_t len, bool commit, esp_err_t *err)
{
static target_t ts[MAX_MACS];
if (len > MAX_FILE || strlen(path) > MAX_PATH) {
*err = ESP_ERR_INVALID_SIZE;
return NULL;
}
if (!s_busy || xSemaphoreTake(s_busy, 0) != pdTRUE) {
*err = ESP_ERR_INVALID_STATE;
return NULL;
}
cJSON *out = NULL;
int n = parse_targets(macs, ts);
if (n <= 0) {
*err = n < 0 ? ESP_ERR_INVALID_ARG : ESP_ERR_NOT_FOUND;
} else {
uint8_t sha[32];
mbedtls_sha256(data, len, sha, 0);
uint16_t sess = (esp_random() % 0xFFFF) + 1;
drain_status();
ESP_LOGI(TAG, "%s (%u B) to %d driver(s), session %u", path, (unsigned)len, n, sess);
transfer(ts, n, sess, path, sha, data, len);
out = results(ts, n, true);
if (commit) {
uint8_t pkt[4] = { WIRE_MAGIC, OP_COMMIT, sess & 255, sess >> 8 };
for (int i = 0; i < n; i++) {
if (ts[i].state == C_OK) {
command(ts[i].mac, pkt, sizeof(pkt), sess, OP_COMMIT, BEGIN_MS, NULL);
}
}
}
*err = ESP_OK;
}
xSemaphoreGive(s_busy);
return out;
}
esp_err_t drv_ota_register(httpd_handle_t server)
{
s_status_q = xQueueCreate(16, sizeof(status_t));
s_busy = xSemaphoreCreateMutex();
if (!s_status_q || !s_busy) {
return ESP_ERR_NO_MEM;
}
rel_set_ota_status_cb(on_status);
const httpd_uri_t u = { .uri = "/drivers/ota/*", .method = HTTP_POST, .handler = ota_post_handler };
return httpd_register_uri_handler(server, &u);
}
-27
View File
@@ -1,27 +0,0 @@
#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "cJSON.h"
#include "esp_err.h"
#include "esp_http_server.h"
// Update led-driver app files (.py) over ESP-NOW. Wire format is documented in
// led-driver/src/espnow_ota.py; tools/driver_ota.py drives a session:
//
// POST /drivers/ota/file?mac=<12hex>[,<12hex>...]|all&sess=<1..65535>&path=<p>&sha=<64hex>
// body: the raw file (0..64 KB). One driver gets the chunks by acked unicast; several get
// one broadcast, then each is asked for its missing chunks and repaired by unicast.
// Reply: {"<mac>":{"result":"same|written|error","code":"...","repaired":n}, ...}
// POST /drivers/ota/commit?mac=...&sess= drivers move their staged files into place and reset
// POST /drivers/ota/abort?mac=...&sess= drivers drop their staged files
//
// mac=all means every ESP-NOW device in the devices collection. One request runs at a time.
esp_err_t drv_ota_register(httpd_handle_t server);
// Send one file the same way from C (macs as above). With commit, drivers that wrote it switch to it
// and reset. Returns the per-driver results (caller owns), or NULL with *err: ESP_ERR_INVALID_STATE
// when an update is running, ESP_ERR_NOT_FOUND with no drivers, ESP_ERR_INVALID_ARG for a bad list,
// ESP_ERR_INVALID_SIZE for a file over 64 KB.
cJSON *drv_ota_send(const char *macs, const char *path, const uint8_t *data, size_t len, bool commit, esp_err_t *err);
-1042
View File
File diff suppressed because it is too large. Load diff
-42
View File
@@ -1,42 +0,0 @@
#pragma once
#include <stdbool.h>
#include "cJSON.h"
#include "esp_err.h"
// Zone play/stop and preset push/send. Drivers run the patterns themselves; this builds preset +
// select frames and hands them to ESP-NOW. Sequences are played by seqplay.c.
// Hook driver announce and resync replies
esp_err_t engine_init(void);
#define GROUP_ID_MAX 20
#define ZONE_TARGETS_MAX 12
// Group ids a zone plays to: its group_ids, plus "z<zone id>" when it names drivers directly (zones
// from before groups). -1 when the zone does not exist. Call with the store locked.
int engine_zone_targets(const char *zone_id, char out[][GROUP_ID_MAX], int max);
// A preset ready to send: palette colours and background resolved, mode as n6. Caller owns it;
// NULL when there is no such preset. Call with the store locked.
cJSON *engine_preset_payload(const char *preset_id);
// Drivers in group gid (a group id, "z<zone>" or a driver's own "d<mac>"), as 12-hex MACs from the
// device list. Call with the store locked.
int engine_group_macs(const char *gid, char out[][13], int max);
// The preset a zone last played (engine_play / engine_stop), or NULL. Call with the store locked.
const char *engine_zone_current(const char *zone_id);
// Select a preset on every driver in the zone's groups (broadcast, sent twice)
esp_err_t engine_play(const char *zone_id, const char *preset_id);
// Turn the zone's drivers off
esp_err_t engine_stop(const char *zone_id);
// POST /presets/push: v1 messages for targets (MAC strings), or broadcast when targets is NULL
esp_err_t engine_push(const cJSON *messages, const cJSON *targets);
// POST /presets/send: presets from the current profile by id
esp_err_t engine_send_presets(const cJSON *ids, bool save, const char *def, const cJSON *targets, int *sent);
// Zones or devices changed: re-send group membership to every registered ESP-NOW driver
void engine_groups_changed(void);
// POST /devices/groups: send every ESP-NOW driver its groups, including silent ones, and wait for the
// acks. Call without the store lock held.
void engine_groups_push_all(int *total, int *sent, int *failed);
-207
View File
@@ -1,207 +0,0 @@
#include "envelope.h"
#include <stdlib.h>
#include <string.h>
void env_blob_init(env_blob_t *b)
{
b->data[0] = 0;
b->len = 1;
b->v3 = false;
}
static bool put(env_blob_t *b, const void *src, size_t n)
{
if (b->len + n > ENV_BLOB_MAX) {
return false;
}
memcpy(b->data + b->len, src, n);
b->len += n;
return true;
}
static bool put_u8(env_blob_t *b, unsigned v)
{
uint8_t x = v;
return put(b, &x, 1);
}
static bool put_le16(env_blob_t *b, unsigned v)
{
uint8_t x[2] = { v & 255, (v >> 8) & 255 };
return put(b, x, 2);
}
// Python truthiness of a JSON value
static bool truthy(const cJSON *v)
{
if (!v || cJSON_IsNull(v) || cJSON_IsFalse(v)) {
return false;
}
if (cJSON_IsNumber(v)) {
return v->valuedouble != 0;
}
if (cJSON_IsString(v)) {
return v->valuestring[0] != 0;
}
return true;
}
static const cJSON *get2(const cJSON *o, const char *a, const char *b)
{
const cJSON *v = cJSON_GetObjectItem(o, a);
return truthy(v) ? v : cJSON_GetObjectItem(o, b);
}
static int clamp(double v, int lo, int hi)
{
int i = (int)v;
return i < lo ? lo : (i > hi ? hi : i);
}
static int num_or(const cJSON *v, int dflt)
{
return cJSON_IsNumber(v) ? (int)v->valuedouble : (cJSON_IsBool(v) ? cJSON_IsTrue(v) : dflt);
}
// Same rule as the Python packer: 6+ hex digits or an [r,g,b] list; anything else is skipped
static bool color_rgb(const cJSON *c, uint8_t rgb[3])
{
if (cJSON_IsString(c)) {
const char *s = c->valuestring;
while (*s == ' ') {
s++;
}
while (*s == '#') {
s++;
}
if (strlen(s) < 6) {
return false;
}
char full[7];
memcpy(full, s, 6);
full[6] = 0;
char *end;
unsigned long v = strtoul(full, &end, 16);
if (*end) {
return false;
}
rgb[0] = v >> 16;
rgb[1] = v >> 8;
rgb[2] = v;
return true;
}
if (cJSON_IsArray(c) && cJSON_GetArraySize(c) >= 3) {
for (int i = 0; i < 3; i++) {
rgb[i] = (uint8_t)num_or(cJSON_GetArrayItem(c, i), 0);
}
return true;
}
return false;
}
bool env_add_preset(env_blob_t *b, const char *name, const cJSON *p)
{
size_t save_len = b->len;
uint8_t save_count = b->data[0];
const cJSON *pat = get2(p, "p", "pattern");
const char *pattern = cJSON_IsString(pat) ? pat->valuestring : "off";
const cJSON *cols = get2(p, "c", "colors");
int ncol = cJSON_IsArray(cols) ? cJSON_GetArraySize(cols) : 0;
size_t nl = strlen(name), pl = strlen(pattern);
if (nl > 250 || pl > 250 || ncol > 255) {
return false;
}
const cJSON *fade = get2(p, "f", "fade"), *tb = get2(p, "tb", "beat_time");
int fade_ms = clamp(num_or(fade, 0), 0, 10000);
bool beat = truthy(tb);
bool ext = fade_ms > 0 || beat;
if (b->data[0] == 0) {
b->v3 = ext;
} else if (b->v3 != ext) {
return false;
}
uint8_t rgbs[255][3];
int nvalid = 0;
for (int i = 0; i < ncol; i++) {
if (color_rgb(cJSON_GetArrayItem(cols, i), rgbs[nvalid])) {
nvalid++;
}
}
bool ok = put_u8(b, nl) && put(b, name, nl) && put_u8(b, pl) && put(b, pattern, pl) && put_u8(b, nvalid);
for (int i = 0; ok && i < nvalid; i++) {
ok = put(b, rgbs[i], 3);
}
const cJSON *d = get2(p, "d", "delay"), *br = get2(p, "b", "brightness");
const cJSON *a = cJSON_GetObjectItem(p, "a");
if (!a) {
a = cJSON_GetObjectItem(p, "auto");
}
int auto_ = a ? truthy(a) : 1;
ok = ok && put_le16(b, clamp(num_or(d, 100), 0, 65535)) && put_u8(b, clamp(num_or(br, 127), 0, 255)) &&
put_u8(b, auto_);
for (int i = 1; ok && i <= 6; i++) {
char key[4] = { 'n', '0' + i, 0 };
ok = put_le16(b, (uint16_t)(int16_t)clamp(num_or(cJSON_GetObjectItem(p, key), 0), -32768, 32767));
}
if (ok && b->v3) {
uint8_t ext_len = (fade_ms ? 4 : 0) + (beat ? 3 : 0);
ok = put_u8(b, ext_len);
if (ok && fade_ms) {
ok = put_u8(b, ENV_EXT_FADE) && put_u8(b, 2) && put_le16(b, fade_ms);
}
if (ok && beat) {
ok = put_u8(b, ENV_EXT_BEAT) && put_u8(b, 1) && put_u8(b, 1);
}
}
if (!ok) {
b->len = save_len;
b->data[0] = save_count;
return false;
}
b->data[0]++;
return true;
}
bool env_add_select(env_blob_t *b, const char *device, const char *preset, int step)
{
size_t save_len = b->len;
size_t dl = strlen(device), pl = strlen(preset);
if (dl > 250 || pl > 250 || (step > 65535)) {
return false;
}
bool ok = put_u8(b, dl) && put(b, device, dl) && put_u8(b, pl) && put(b, preset, pl) && put_u8(b, step >= 0);
if (ok && step >= 0) {
ok = put_le16(b, step);
}
if (!ok) {
b->len = save_len;
return false;
}
b->data[0]++;
return true;
}
size_t env_frame(uint8_t *out, int brightness, const env_blob_t *presets, const env_blob_t *select)
{
size_t lp = presets && presets->data[0] ? presets->len : 0;
size_t ls = select && select->data[0] ? select->len : 0;
int wire = 255;
if (brightness >= 0) {
wire = brightness > 255 ? 127 : (brightness * 127 + 127) / 255; // 0-127 scales to 0-255
}
out[0] = lp && presets->v3 ? 3 : 2;
out[1] = wire;
out[2] = lp;
out[3] = ls;
out[4] = 0;
if (lp) {
memcpy(out + 5, presets->data, lp);
}
if (ls) {
memcpy(out + 5 + lp, select->data, ls);
}
return 5 + lp + ls;
}
-35
View File
@@ -1,35 +0,0 @@
#pragma once
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include "cJSON.h"
// Native binary (v2) driver envelope, byte-compatible with
// src/util/binary_envelope.py. Presets and select entries go in separate
// frames so each frame is 5 + blob <= ENV_FRAME_MAX (one ESP-NOW payload).
#define ENV_FRAME_MAX 224 // + 4C 04 <group> wrapper must fit REL_FRAG_MAX
#define ENV_BLOB_MAX (ENV_FRAME_MAX - 5)
typedef struct {
uint8_t data[ENV_BLOB_MAX + 1]; // data[0] is the entry count
size_t len;
bool v3; // preset records carry an extension block (fade, beat timing): a v3 frame
} env_blob_t;
// Envelope v3: v2, except that each preset record is followed by [ext_len][key, len, value]... Keys:
#define ENV_EXT_FADE 1 // u16: fade-in ms when the preset is selected
#define ENV_EXT_BEAT 2 // u8: 1 = durations are quarter beats, not ms
void env_blob_init(env_blob_t *b);
// Append one preset (short keys p,c,d,b,a,n1..n6,f,tb or long pattern/colors/.../fade/beat_time); false if
// it does not fit. A preset with a fade or beat timing makes the blob v3; v2 and v3 records never share a
// blob, so mixing them also returns false (callers send what they have and start a new blob).
bool env_add_preset(env_blob_t *b, const char *name, const cJSON *preset);
// Append one select entry; step < 0 means none
bool env_add_select(env_blob_t *b, const char *device, const char *preset, int step);
// Frame with either a presets blob or a select blob (the other empty);
// brightness < 0 leaves device brightness unchanged. Returns frame length.
size_t env_frame(uint8_t *out, int brightness, const env_blob_t *presets, const env_blob_t *select);
Loaded 100 of 291 files, more files were not shown because too many files have changed in this diff. Show more