Skip to content

Device-initiated flashcards sync on WiFi connect (firmware 0.1.14) - #4

Merged
watchmesink merged 1 commit into
codex/flashcards-sm2pp-uploadfrom
feature/device-initiated-web-sync
Jun 11, 2026
Merged

watchmesink merged 1 commit into
codex/flashcards-sm2pp-uploadfrom
feature/device-initiated-web-sync

Conversation

@watchmesink

Copy link
Copy Markdown
Owner

What

The device now syncs flashcards with the companion web app by itself, whenever it connects to WiFi — no laptop-side agent needed for the common path.

Firmware (src/network/FlashcardsWebSync.{h,cpp}, wired into main.cpp)

  • On any WiFi connect (boot auto-connect, settings, file transfer), after a 4 s settle, a background FreeRTOS task runs one sync pass. At most one pass per connection; 5-minute retry if the pass had errors; auto-sleep is held off while syncing.
  • Progress: each deck's SM-2++ bin is POSTed to /api/sync/<deck>/progress; the server merges with web reviews (more-reviewed record per card wins) and the merged bin is written back only when it differs (no flash wear when idle).
  • Files: /flashcards/<deck>/*.txt reconcile against /api/sync/<deck>/manifest — web-only files download, device-only files upload, web deletion tombstones delete locally, content conflicts resolve device-wins (sha256 compare).
  • Config lives at /.crosspoint/flashcards_sync.json ({"url", "token", "enabled"}); without it the module is fully inert.
  • HTTPS via WiFiClientSecure (same pattern as HttpDownloader); progress JSON is built/parsed without ArduinoJson to keep peak heap low.

Web server (web/server.js)

  • New GET /api/sync/:deck/manifest → {files: [{name, size, sha256}], tombstones: [...]}.
  • DELETE on a deck file records a tombstone (so the device deletes instead of re-uploading); PUT clears it.

Binary

  • 0.1.14-gleb-firmware.bin built from this branch (RAM 31.1%, flash 96.7%).

Testing

  • Web: tombstone lifecycle (PUT → DELETE → manifest → re-PUT) verified locally; full engine suite green; deployed and manifest verified against production.
  • Firmware: compiles clean for esp32-c3 (pio run -e default). On-device validation: flash, connect WiFi, watch serial for [FSY] log lines.

🤖 Generated with Claude Code

When WiFi comes up, the firmware runs one background sync pass against the
companion web app configured in /.crosspoint/flashcards_sync.json:
- SM-2++ progress bins are merged via POST /api/sync/<deck>/progress and
  written back only when changed
- deck TXT files reconcile against GET /api/sync/<deck>/manifest: web-only
  files download, device-only files upload, web deletion tombstones delete
  locally, content conflicts resolve device-wins
- at most one pass per connection (5-min retry on errors), auto-sleep is
  held off while syncing, module is inert without the config file

Web server: adds the manifest endpoint and deletion tombstones (recorded on
DELETE, cleared on PUT).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@watchmesink
watchmesink merged commit d23e376 into codex/flashcards-sm2pp-upload Jun 11, 2026
1 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant