Implementiert ein binäres Frame-Format für effiziente Speicherung auf dem ESP8266.
- 🎯 75% kleiner: 776 Bytes statt ~3 KB pro Frame (16×16)
- ⚡ 90% schneller: Kein JSON-Parsing, direktes Laden in LED-Array
- 💾 97% weniger RAM: Kein großer JSON-Buffer nötig
- 🔄 Abwärtskompatibel: Unterstützt weiterhin JSON-Format
Funktionen:
compressFrame(frame)- Konvertiert einzelnen Frame zu BinärcompressAnimation(animation)- Konvertiert komplette Animation zu BinärcalculateCompressionStats(animation)- Berechnet KompressionsratedecompressAnimation(binary)- Dekomprimiert für Tests
Binär-Format:
Animation-Header (16 Bytes):
- magic: "FMLX" (4 Bytes)
- version: uint16_t (2 Bytes)
- frameCount: uint16_t (2 Bytes)
- loop: uint8_t (1 Byte)
- reserved: 7 Bytes
Frame (776 Bytes für 16×16):
- Header (8 Bytes):
- duration: uint32_t (4 Bytes)
- width: uint8_t (1 Byte)
- height: uint8_t (1 Byte)
- reserved: uint16_t (2 Bytes)
- Pixels (768 Bytes):
- R, G, B (je 1 Byte pro Pixel)
Angepasste Funktion:
uploadFramesToDevice()- Verwendet jetzt binäres Format- Content-Type:
application/octet-stream - Zeigt Kompressionsstatistiken in Console
- Content-Type:
Neue Strukturen:
struct FrameHeader {
uint32_t duration;
uint8_t width;
uint8_t height;
uint16_t reserved;
} __attribute__((packed));
struct AnimationHeader {
char magic[4]; // "FMLX"
uint16_t version;
uint16_t frameCount;
uint8_t loop;
uint8_t reserved[7];
} __attribute__((packed));Neue Funktionen:
handleUploadFrames()- Auto-Detection JSON vs. BinärhandleBinaryFrameUpload()- Verarbeitet binäre UploadshandleJsonFrameUpload()- Legacy JSON-SupportisBinaryFormat()- Prüft Magic-BytesloadBinaryFrame()- Lädt Frame direkt in LED-ArrayupdateFrameDisplay()- Unterstützt beide Formate
Auto-Detection:
- Prüft Content-Type:
application/octet-stream - Prüft Magic-Bytes:
FMLX - Wählt automatisch richtigen Parser
| Frames | JSON | Binär | Ersparnis |
|---|---|---|---|
| 1 | ~3 KB | 776 B | 74% |
| 10 | ~30 KB | 7.6 KB | 75% |
| 30 | ~90 KB | 23 KB | 74% |
| 100 | ~300 KB | 77 KB | 74% |
const { compressAnimation, calculateCompressionStats } = useFrameCompression()
const animation = {
description: 'My Animation',
loop: true,
frames: [
{ pixels: [[...]], duration: 1000 },
{ pixels: [[...]], duration: 1000 },
]
}
// Komprimiere
const binary = compressAnimation(animation)
// Zeige Statistiken
const stats = calculateCompressionStats(animation)
console.log(`Saved ${stats.savings}%`)
// Upload
await uploadFramesToDevice(deviceIp, animation.frames)Die Firmware erkennt automatisch das Format:
=== POST /frames ===
Content-Type: application/octet-stream
Received data: 792 bytes
📦 Detected BINARY format
✓ Valid binary format detected
Version: 1
Frame count: 1
Loop: Yes
✓ Binary frames saved: 1 frames, 792 bytes
Beim Abspielen:
📦 Using BINARY format
Binary frame 0 displayed (3000ms)
- Frontend sendet Binär
- ESP8266 akzeptiert JSON und Binär
- Automatische Erkennung
- Entferne JSON-Support
- Reduziere RAM-Verbrauch weiter
- Kleinere Firmware
const { compressAnimation, decompressAnimation } = useFrameCompression()
const original = { /* ... */ }
const binary = compressAnimation(original)
const decompressed = decompressAnimation(binary)
// Vergleiche original mit decompressed
console.assert(JSON.stringify(original.frames) === JSON.stringify(decompressed.frames))- Flashe neue Firmware auf ESP8266
- Sende Test-Frame über Web-App
- Prüfe Serial Monitor:
📦 Compression: 3024 → 792 bytes (73.8% saved) ✓ Upload successful: 1 frames - Prüfe LED-Display: Frame wird angezeigt
JSON (alt):
- Upload: ~3 KB
- Parse-Zeit: ~50-100ms
- RAM: 32 KB Buffer
Binär (neu):
- Upload: ~800 Bytes
- Load-Zeit: ~5-10ms
- RAM: Kein Buffer nötig
- IRAM fast voll (93%): Weitere Features sollten IRAM-Nutzung vermeiden
- Max. Frame-Größe: Begrenzt durch verfügbaren Flash-Speicher (~1-2 MB)
- Keine Kompression: Binär-Format ist unkomprimiert (kein gzip/LZ4)
Speichere nur Unterschiede zwischen Frames:
Frame 0: Vollständig (776 B)
Frame 1: Delta (50 B)
Frame 2: Delta (30 B)
Verwende 8-Bit Farbpalette:
Palette: 256 Farben × 3 Bytes = 768 B
Pixels: 256 × 1 Byte = 256 B
Total: 1024 B (vs. 776 B, aber flexibler)
Für einfarbige Bereiche:
[count, R, G, B]
[10, 255, 0, 0] = 10× Rot
app/composables/useFrameCompression.ts- Kompression-LogikFRAME_COMPRESSION_CONCEPT.md- Konzept-DokumentationBINARY_COMPRESSION_IMPLEMENTATION.md- Diese Datei
app/composables/useESP8266.ts- Upload verwendet Binärfirmware/framolux-esp8266-wifimanager/framolux-esp8266-wifimanager.ino- Binär-Support
RAM: 36564 / 80192 bytes (45%)
Flash: 399376 / 1048576 bytes (38%)
IRAM: 60967 / 65536 bytes (93%) ⚠️
Binary: 429.92 KB
- ✅ Firmware flashen
- ✅ Test-Frame senden
- ✅ Kompression verifizieren
- 🔄 Produktiv nutzen
- 📊 Performance messen
- 🎨 Weitere Optimierungen evaluieren
Bei Problemen:
- Prüfe Serial Monitor (115200 baud)
- Achte auf Debug-Ausgaben (
📦,📄,✓,✗) - Vergleiche JSON- vs. Binär-Größe in Console