diff --git a/docs/images/command-menu.png b/docs/images/command-menu.png index 6251ae0..1673f4f 100644 Binary files a/docs/images/command-menu.png and b/docs/images/command-menu.png differ diff --git a/docs/images/dashboard.png b/docs/images/dashboard.png index dff48d5..b6892b5 100644 Binary files a/docs/images/dashboard.png and b/docs/images/dashboard.png differ diff --git a/docs/images/history.png b/docs/images/history.png index 9358044..e657ecc 100644 Binary files a/docs/images/history.png and b/docs/images/history.png differ diff --git a/docs/images/maintenance.png b/docs/images/maintenance.png index d31040e..8f72509 100644 Binary files a/docs/images/maintenance.png and b/docs/images/maintenance.png differ diff --git a/docs/images/mobile.png b/docs/images/mobile.png index 358e532..4a487aa 100644 Binary files a/docs/images/mobile.png and b/docs/images/mobile.png differ diff --git a/docs/images/share.png b/docs/images/share.png index a6adf55..98f8159 100644 Binary files a/docs/images/share.png and b/docs/images/share.png differ diff --git a/scripts/demo/README.md b/scripts/demo/README.md new file mode 100644 index 0000000..33d3625 --- /dev/null +++ b/scripts/demo/README.md @@ -0,0 +1,8 @@ +# Demo data for README screenshots + +Everything here is made up: printer names (Test Printer A to D), serials, access codes, file names and prints. Nothing connects to a real printer; the fake broker binds to 127.0.0.1 to 127.0.0.4 only. + +1. `go run scripts/demo/fake_bambu.go` (fake Bambu printers on port 8883) +2. `python3 scripts/demo/seed.py /tmp/demo-home` (fake config, history, queue) +3. Build and start the Bridge: `CGO_ENABLED=0 go build -tags headless -o bridge ./cmd/foxtrack-bridge`, then `HOME=/tmp/demo-home XDG_CONFIG_HOME=/tmp/demo-home/.config FOXTRACK_BRIDGE_PORT=18099 ./bridge` +4. `PLAYWRIGHT_CORE= node scripts/demo/screenshots.cjs http://127.0.0.1:18099 docs/images` diff --git a/scripts/demo/fake_bambu.go b/scripts/demo/fake_bambu.go new file mode 100644 index 0000000..3dcb507 --- /dev/null +++ b/scripts/demo/fake_bambu.go @@ -0,0 +1,187 @@ +//go:build ignore + +// fake_bambu is a stand-in for four Bambu Lab printers, for taking README +// screenshots with made-up data. It speaks just enough MQTT 3.1.1 over TLS for +// the Bridge: it accepts any login, then publishes one printer report per +// serial on device//report. It binds to loopback only and never talks +// to a real printer. +// +// go run scripts/demo/fake_bambu.go # listens on 127.0.0.1-127.0.0.4, port 8883 +// +// Each printer in the demo config uses one of those loopback addresses as its +// "IP". See scripts/demo/README.md. +package main + +import ( + "crypto/ecdsa" + "crypto/elliptic" + "crypto/rand" + "crypto/tls" + "crypto/x509" + "crypto/x509/pkix" + "encoding/json" + "log" + "math/big" + "net" + "strings" + "sync" + "time" + + "github.com/eclipse/paho.mqtt.golang/packets" +) + +type tray struct { + Color, Type string +} + +type printer struct { + IP, Serial, Machine string + State, File string // gcode_state, subtask_name + Percent, Minutes int + Nozzle, NozzleSet float64 + Bed, BedSet float64 + LightOn bool + Trays []tray // empty: no AMS + Active string // tray_now + External *tray // external spool + Hours float64 +} + +var printers = []printer{ + {IP: "127.0.0.1", Serial: "TESTSERIAL000A", Machine: "P1S", State: "RUNNING", File: "test_bracket_top_8", + Percent: 47, Minutes: 104, Nozzle: 220, NozzleSet: 220, Bed: 65, BedSet: 65, LightOn: true, + Trays: []tray{{"F2EFE6", "PLA"}, {"1C1C1C", "PLA"}, {"E87722", "PETG"}, {"8A9A5B", "PLA"}}, + Active: "2", Hours: 1284}, + {IP: "127.0.0.2", Serial: "TESTSERIAL000B", Machine: "X1C", State: "FINISH", File: "test_cable_clip", + Percent: 100, Nozzle: 41, Bed: 38, + Trays: []tray{{"2A4B8D", "PLA"}, {"F2EFE6", "PLA"}, {"C8372D", "ABS"}, {"D9C3A0", "PLA"}}, + Active: "255", Hours: 2310}, + {IP: "127.0.0.3", Serial: "TESTSERIAL000C", Machine: "A1", State: "IDLE", + Nozzle: 26, Bed: 25, LightOn: true, External: &tray{"6B93A8", "PLA"}, Active: "254", Hours: 416}, + {IP: "127.0.0.4", Serial: "TESTSERIAL000D", Machine: "P1S", State: "RUNNING", File: "test_organizer_v3", + Percent: 82, Minutes: 38, Nozzle: 250, NozzleSet: 250, Bed: 80, BedSet: 80, LightOn: true, + Trays: []tray{{"F2EFE6", "PETG"}, {"3A3A3A", "PETG"}, {"A0693F", "PLA"}, {"5E8A4F", "PLA"}}, + Active: "0", Hours: 873}, +} + +func (p printer) report() []byte { + mode := "off" + if p.LightOn { + mode = "on" + } + pr := map[string]any{ + "msg": 0, "gcode_state": p.State, "subtask_name": p.File, + "mc_percent": p.Percent, "mc_remaining_time": p.Minutes, + "nozzle_temper": p.Nozzle, "nozzle_target_temper": p.NozzleSet, + "bed_temper": p.Bed, "bed_target_temper": p.BedSet, + "lights_report": []map[string]string{{"node": "chamber_light", "mode": mode}}, + "spd_lvl": 2, "cooling_fan_speed": "0", "machine_type": p.Machine, + "total_run_time": int64(p.Hours * 3600), "mc_print_error_code": "0", + } + if p.State == "RUNNING" { + pr["gcode_file"] = p.File + ".gcode.3mf" + } + var ams []map[string]any + if len(p.Trays) > 0 { + var ts []map[string]any + for i, t := range p.Trays { + ts = append(ts, map[string]any{"id": string(rune('0' + i)), "tray_color": t.Color + "FF", + "tray_type": t.Type, "remain": 80, "tray_weight": "1000"}) + } + ams = []map[string]any{{"id": "0", "tray": ts}} + pr["ams"] = map[string]any{"ams": ams, "tray_now": p.Active} + } + if p.External != nil { + pr["vt_tray"] = map[string]any{"id": "254", "tray_color": p.External.Color + "FF", + "tray_type": p.External.Type, "remain": 100, "tray_weight": "1000"} + } + b, _ := json.Marshal(map[string]any{"print": pr}) + return b +} + +func selfSigned() tls.Certificate { + key, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + tpl := &x509.Certificate{SerialNumber: big.NewInt(1), Subject: pkix.Name{CommonName: "fake-bambu"}, + NotBefore: time.Now().Add(-time.Hour), NotAfter: time.Now().Add(24 * time.Hour)} + der, err := x509.CreateCertificate(rand.Reader, tpl, tpl, &key.PublicKey, key) + if err != nil { + log.Fatal(err) + } + return tls.Certificate{Certificate: [][]byte{der}, PrivateKey: key} +} + +func serve(conn net.Conn, p printer) { + defer conn.Close() + var wmu sync.Mutex + write := func(cp packets.ControlPacket) { + wmu.Lock() + defer wmu.Unlock() + _ = cp.Write(conn) + } + publish := func() { + pub := packets.NewControlPacket(packets.Publish).(*packets.PublishPacket) + pub.TopicName = "device/" + p.Serial + "/report" + pub.Payload = p.report() + write(pub) + } + stop := make(chan struct{}) + defer close(stop) + for { + cp, err := packets.ReadPacket(conn) + if err != nil { + return + } + switch pk := cp.(type) { + case *packets.ConnectPacket: + ack := packets.NewControlPacket(packets.Connack).(*packets.ConnackPacket) + write(ack) + case *packets.SubscribePacket: + ack := packets.NewControlPacket(packets.Suback).(*packets.SubackPacket) + ack.MessageID = pk.MessageID + for range pk.Topics { + ack.ReturnCodes = append(ack.ReturnCodes, 0) + } + write(ack) + publish() + go func() { + for { + select { + case <-stop: + return + case <-time.After(5 * time.Second): + publish() + } + } + }() + case *packets.PublishPacket: + if strings.HasSuffix(pk.TopicName, "/request") { + publish() // the Bridge's pushall + } + case *packets.PingreqPacket: + write(packets.NewControlPacket(packets.Pingresp)) + case *packets.DisconnectPacket: + return + } + } +} + +func main() { + cfg := &tls.Config{Certificates: []tls.Certificate{selfSigned()}} + for _, p := range printers { + ln, err := tls.Listen("tcp", p.IP+":8883", cfg) + if err != nil { + log.Fatal(err) + } + log.Printf("fake %s %s on %s:8883", p.Machine, p.Serial, p.IP) + go func(p printer) { + for { + c, err := ln.Accept() + if err != nil { + return + } + go serve(c, p) + } + }(p) + } + select {} +} diff --git a/scripts/demo/screenshots.cjs b/scripts/demo/screenshots.cjs new file mode 100644 index 0000000..ed88633 --- /dev/null +++ b/scripts/demo/screenshots.cjs @@ -0,0 +1,61 @@ +// Takes the README screenshots from a Bridge running on demo data. +// usage: node scripts/demo/screenshots.cjs +// Needs playwright-core (set PLAYWRIGHT_CORE to its path if require cannot find it) and a Chromium that Playwright can launch. +const { chromium } = require(process.env.PLAYWRIGHT_CORE || 'playwright-core'); + +const base = (process.argv[2] || 'http://127.0.0.1:18099').replace(/\/$/, '') + '/'; +const out = process.argv[3] || '.'; + +async function shot(browser, name, viewport, run) { + const ctx = await browser.newContext({ viewport, deviceScaleFactor: 2, colorScheme: 'light' }); + const page = await ctx.newPage(); + await run(page); + await page.screenshot({ path: `${out}/${name}.png` }); + await ctx.close(); +} + +(async () => { + const browser = await chromium.launch(); + const settle = (page) => page.waitForTimeout(4000); // the fake printers' first reports + + await shot(browser, 'dashboard', { width: 1280, height: 1160 }, async (p) => { + await p.goto(base); + await settle(p); + }); + + await shot(browser, 'command-menu', { width: 1280, height: 860 }, async (p) => { + await p.goto(base); + await settle(p); + await p.keyboard.press('Control+k'); + await p.waitForTimeout(800); + }); + + await shot(browser, 'mobile', { width: 390, height: 844 }, async (p) => { + await p.goto(base); + await settle(p); + }); + + await shot(browser, 'history', { width: 1384, height: 704 }, async (p) => { + await p.goto(base + '#history'); + await settle(p); + }); + + await shot(browser, 'maintenance', { width: 1224, height: 908 }, async (p) => { + await p.goto(base + '#settings/maintenance'); + await settle(p); + }); + + // A share link for Test Printer A, made through the API. + const ctx = await browser.newContext(); + const res = await ctx.request.post(base + 'api/shares', { + data: { name: 'Test Printer A in the workshop', printer_id: 'demo-a', camera: false }, + }); + const { path } = await res.json(); + await ctx.close(); + await shot(browser, 'share', { width: 390, height: 700 }, async (p) => { + await p.goto(base.slice(0, -1) + path); + await p.waitForTimeout(3000); + }); + + await browser.close(); +})(); diff --git a/scripts/demo/seed.py b/scripts/demo/seed.py new file mode 100644 index 0000000..76f4260 --- /dev/null +++ b/scripts/demo/seed.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python3 +"""Write a demo Bridge config folder with four made-up printers. + +usage: seed.py + +The Bridge keeps its files in /.config/FoxTrack-Bridge when started +with HOME= XDG_CONFIG_HOME=/.config. Everything here is +invented: names, serials, access codes, file names and prints. +""" +import json, os, sys, time, calendar + +home = sys.argv[1] +d = os.path.join(home, ".config", "FoxTrack-Bridge") +os.makedirs(d, exist_ok=True) + +printers = [ + {"id": "demo-a", "name": "Test Printer A", "ip": "127.0.0.1", "serial": "TESTSERIAL000A", "lan_code": "00000000"}, + {"id": "demo-b", "name": "Test Printer B", "ip": "127.0.0.2", "serial": "TESTSERIAL000B", "lan_code": "00000000"}, + {"id": "demo-c", "name": "Test Printer C", "ip": "127.0.0.3", "serial": "TESTSERIAL000C", "lan_code": "00000000"}, + {"id": "demo-d", "name": "Test Printer D", "ip": "127.0.0.4", "serial": "TESTSERIAL000D", "lan_code": "00000000"}, +] + + +def ts(y, m, dd, hh, mm): + return calendar.timegm((y, m, dd, hh, mm, 0, 0, 0, 0)) + + +def rec(printer, file, start, minutes, result, grams, note=""): + r = { + "printer_name": printer, "file_name": file, "nozzle_temp": 220, "bed_temp": 65, + "start_time": start, "end_time": start + minutes * 60, "duration": minutes * 60, + "result": result, "percent_at_end": 100 if result == "finished" else 60, + "filaments": [{"slot": 0, "material": "PLA", "grams": grams}], + } + if note: + r["note"] = note + return r + + +A, B, C, D = (p["name"] for p in printers) +history = [ + rec(A, "test_bracket_top_7", ts(2026, 11, 5, 1, 0), 146, "finished", 50), + rec(A, "test_bracket_side_7", ts(2026, 11, 2, 1, 0), 155, "finished", 53), + rec(A, "test_stand_v2", ts(2026, 10, 31, 1, 0), 90, "finished", 31, "Matte black, 0.16 mm layers."), + rec(B, "test_cable_clip_x12", ts(2026, 11, 4, 1, 0), 44, "finished", 15), + rec(B, "test_divider_a", ts(2026, 11, 3, 1, 0), 51, "error", 18, "AMS jam on slot 3."), + rec(B, "test_gear_15t", ts(2026, 10, 31, 1, 0), 30, "finished", 10), + rec(C, "test_calibration_cube", ts(2026, 11, 3, 1, 0), 18, "finished", 6), + rec(C, "test_hook", ts(2026, 11, 1, 1, 0), 10, "cancelled", 4, "Stopped: first layer lifted."), + rec(D, "test_planter_small", ts(2026, 11, 5, 1, 0), 120, "finished", 41, "A test note."), + rec(D, "test_lamp_spiral", ts(2026, 11, 2, 1, 0), 210, "finished", 71, "Vase mode with the 0.6 mm nozzle."), +] + +oct1 = ts(2026, 10, 1, 0, 0) +tasks = [ + {"id": "m1", "printer_id": "demo-a", "name": "Lubricate the Z rods", "interval_hours": 200, "last_done_at": oct1}, + {"id": "m2", "printer_id": "demo-a", "name": "Clean the carbon rods", "interval_hours": 100, "last_done_at": ts(2026, 11, 3, 0, 0)}, + {"id": "m3", "printer_id": "demo-b", "name": "Replace the nozzle", "interval_hours": 500, "last_done_at": oct1}, + {"id": "m4", "printer_id": "demo-d", "name": "Check belt tension", "interval_hours": 150, "last_done_at": oct1}, +] + +cfg = { + "api_key": "", + "printers": printers, + "notifications": { + "channels": [ + {"id": "n1", "name": "Test Discord", "kind": "discord", "enabled": True, "url": "https://discord.invalid/api/webhooks/0/test"}, + {"id": "n2", "name": "Test ntfy", "kind": "ntfy", "enabled": True, "url": "https://ntfy.invalid/test-topic"}, + {"id": "n3", "name": "Test Telegram", "kind": "telegram", "enabled": False, "token": "", "target": ""}, + ], + "quiet_start": "22:30", "quiet_end": "07:00", "almost_done_minutes": 10, + }, + "costs": {"currency": "$", "filament_per_kg": 20.8}, + "maintenance": {"tasks": tasks}, +} +queue = {"demo-c": [ + {"id": "q1", "file_name": "test_stand_v3.gcode.3mf", "added_at": 1790000000}, + {"id": "q2", "file_name": "test_holder.gcode.3mf", "added_at": 1790000100}, +]} + +for name, obj in (("config.json", cfg), ("history.json", history), ("queue.json", queue)): + with open(os.path.join(d, name), "w") as f: + json.dump(obj, f, indent=2) +print("wrote", d)