API Guide · v1 Draft
The Legends Board API guide
This is the working draft of the guide. The schema is the contract, and details can change before the first firmware release.
1. What You Can Do
| You want to… | Use |
|---|---|
| Keep score and let the board apply the rules (counts, bonus, penalties, period changes) | Rules mode: send Actions (§5.1) |
| Show a game your own app scores, such as a stats app with its own rules engine | Display mode: send whole states (§5.2) |
| Show scores in a spectator app, a streaming overlay or a bracket page | Connect as a Viewer and subscribe to State and Events (§4.3), or read the advertising (§3.1) |
| Build a play-by-play with board-accurate clock times | Subscribe to the audit stream (§7) |
| Put your brand, a sponsor or a custom sport on the screen | Custom layouts, assets and playlists (§8) |
| Run a board from a press-box laptop or a server | The board's local Wi-Fi API (§3.2), with the same messages |
| Build and test without hardware | The virtual board and the browser simulator (§10) |
2. Concepts
- The board is the source of truth. It holds the game (
GameState) and counts every clock: game clock, shot clock, timeouts, penalties and practice segments. A phone that sleeps, walks out of range or crashes never stops a clock or loses the score. game_idandseq:game_idis chosen by the board at New game.seqgoes up on every accepted change, including the board's own changes, such as a walk resolving after its 1.5 s flash or a period ending.- Clients use both to know whether their view is current.
- Sessions and roles: every connection is a session.
- Viewers can read and subscribe.
- One Controller can change the game.
- One Clock operator can only run the clocks, for tables with a separate timer.
- Control passes with the take-over rules in §4.4.
- Two control modes, one state:
- Rules mode: the board runs the sport's rules. Our TypeScript rules engines are the reference, and the firmware’s C port must pass the same conformance vectors.
- Display mode: your app runs the rules and the board shows what you send.
- Both produce the same
GameState, so Mirrors, spectators and events work identically.
- Capabilities, not assumptions.
DeviceInfolists the API version, capabilities, sports, presets and limits. Check before using anything optional.
3. Transports
Every transport carries the same two envelopes, ClientMessage (to the board) and ServerMessage (from the board), defined in session.proto.
3.1 Bluetooth LE (Always Available)
Legends Board Service: b36c0001-99f2-42c0-86e1-ed5d3a071c41
| Characteristic | UUID | Properties | Content |
|---|---|---|---|
| Inbox | b36c0002-99f2-42c0-86e1-ed5d3a071c41 |
Write, Write Without Response | ClientMessage frames |
| Outbox | b36c0003-99f2-42c0-86e1-ed5d3a071c41 |
Notify | ServerMessage frames |
| Info | b36c0004-99f2-42c0-86e1-ed5d3a071c41 |
Read | A compact DeviceInfo (protobuf, unframed, at most 512 bytes: the per-sport layout lists are left out), so scanners can learn a board without a session. Hello and GetInfo return the full DeviceInfo. |
Framing: each characteristic value is one frame: a 1-byte header, then up to MTU−4 bytes of payload.
| Header bit | Meaning |
|---|---|
| 7 | First frame of a message |
| 6 | Last frame of a message |
| 0–5 | Message counter (0–63), the same on every frame of one message |
- A message that fits one frame has both bits 7 and 6 set.
- The board reassembles up to
Limits.max_message_bytes(4096 at launch). - A frame that arrives out of sequence drops the partial message, and the board replies
STATUS_INVALID. - Clients should negotiate the largest MTU the phone allows (iOS about 185, Android up to 517). Then most messages, including a full
GameState, fit in one frame.
Writes:
- Use Write With Response for requests that change the game, so the phone's Bluetooth stack paces them.
- Write Without Response is allowed for
Pingand for high-rate clock nudges. - The board answers every request that has an
idon the Outbox.
Pairing: not required. The board accepts LE Secure Connections bonding, and a board with a PIN asks for it in Claim, not at the link layer. Link-layer pairing dialogs confuse volunteers on game day.
Advertising (format 2):
- Where: the board advertises the service UUID. The scan response carries the Field name (up to 12 bytes) and one 15-byte manufacturer-data block, because iOS doesn't reliably report a second block.
- What it's for: apps list nearby boards, and spectators follow every game, without connecting.
| Byte | Field |
|---|---|
| 0–1 | Company ID (little-endian). 0xFFFF is for development; shipping needs a Bluetooth SIG company ID. |
| 2 | Format, 2 |
| 3 | Status bits: b0 configured, b1 setup open, b2 in use (has a Controller), b3 PIN, b4 low power, b5 a Mirror isn't responding, b6 viewer slots full, b7 possible duplicate Main |
| 4–5 | Field ID hash (first 2 bytes of SHA-256 of the Field ID): tells apart boards with the same name |
| 6–7 | Board code, e.g. A73F |
| 8 | Sport (b0–3, the Sport enum) and period bits 0–3 (b4–7) |
| 9, 10 | Home and away score, low 8 bits |
| 11 | b0 home score bit 8, b1 away score bit 8 (scores to 511), b2–3 period bits 4–5 (periods to 63), b4 clock running, b5 clock counts up, b6 no clock, b7 away has possession, serve or is batting |
| 12–13 | Main clock in whole seconds (rounded up when counting down) |
| 14 | Sport byte. Baseball: b0–2 balls, b3–4 strikes, b5–6 outs, b7 top of the inning. Football: the down. Otherwise 0. |
Format 1 was baseball-only. Format 2 replaces it and covers every sport.
Connections: up to 4 sessions (1 Controller, 1 Clock operator, viewers). The fifth slot is kept free for setup and recovery.
3.2 Local Wi-Fi API (Capability CAPABILITY_WIFI_API)
A board can join a Wi-Fi network: the facility's, or a phone hotspot. It then serves the same API on the local network:
- Discovery: mDNS
_legends._tcp, with TXT recordscode=A7,api=1,model=LS-1. - Status: designed now so nothing blocks it, but not in the first firmware. It will be built when a partner needs it.
- WebSocket:
wss://<code>.local/api/v1/ws. Binary frames carry protobuf envelopes. Text frames carry the same messages in the proto3 JSON mapping, for scripts and quick tools. - HTTP:
GET /api/v1/infoandGET /api/v1/state(JSON).POST /api/v1/messages: oneClientMessagein, oneServerMessageout, for stateless servers.GET /api/v1/events: Server-Sent Events of State and Event messages.
- Access: a bearer token, created over Bluetooth by the current Controller ("Link a device"). Creating one needs someone standing at the board, so a board on a shared network can't be taken over from the parking lot.
- Radio note: ESP-NOW to Mirrors must share the Wi-Fi channel of the network the Main joins. The Main tells its Mirrors to follow, and setup warns when a network's channel changes.
3.3 Legends Cloud Relay (Planned, Not in v1 Firmware)
For partners whose data lives in the cloud, the relay connects a board to the cloud in one of two ways:
- directly, over Wi-Fi;
- through the Legends app as a bridge.
Partners would then send the same messages through a REST/WebSocket API, with OAuth 2.0 client credentials and webhooks for events. An owner links a board to a partner by scanning a QR code on the board's screen. Messages are identical to §3.1 and §3.2, so nothing designed today needs to change for it.
4. Sessions
4.1 Start
- Connect, then send
Hello. It carries:app_id: reverse-DNS, e.g.com.example.stats.app_name: shown to scorers ("Scored by Example Stats").api_major = 1.partner_key: optional (§11).
- The board replies
HelloReply, withDeviceInfoand your session id. If its API major version differs, it repliesSTATUS_UNSUPPORTED. Subscribeto state and events. The board immediately sends the currentGameStateandControlStatus.
4.2 Requests and Results
Every ClientMessage with a non-zero id gets a ServerMessage whose reply_to matches.
| Status | Meaning | What to do |
|---|---|---|
OK |
Applied; seq is the new sequence |
— |
STALE |
Your base no longer matches (display mode, or an action pinned to an old game_id) |
Re-read the state, then re-apply or show the newer board state |
NOT_CONTROLLER |
Only the Controller (or Clock operator, for clocks) may do this | Claim first |
INVALID |
A value is out of range or malformed; message says which |
Fix the request |
UNSUPPORTED |
The board lacks the capability or sport | Check DeviceInfo |
WRONG_MODE |
An Action in display mode, or a SetState in rules mode | Start a New game in the right mode |
PIN_REQUIRED |
The board has a PIN | Ask the scorer for the PIN |
PENDING |
Your take-over request is waiting for the current controller | Wait for a ControlStatus or DENIED |
DENIED |
Refused; retry_after_ms says when to try again |
Wait, then retry |
RATE_LIMITED |
Too many requests; retry_after_ms says when to try again |
Wait, then retry |
BUSY |
The board is in setup or updating firmware | Try again later |
TOO_LARGE |
The message is over Limits.max_message_bytes |
Send something smaller |
4.3 Reading
Any session can GetState, GetInfo and Subscribe.
State notifications are coalesced. While clocks run, the board sends one notification per visible change and at least one per second. Between notifications, a client draws a running clock from Clock.ms, running and its own elapsed time, and corrects at each notification.
4.4 Control and Take-over
Claim asks for control, as the Controller or the Clock operator. These rules were reviewed for real game days:
- No current holder: granted immediately (with the PIN if one is set).
- Correct PIN: granted immediately. The old holder gets
ControlStatuswithyou_control = false. - Otherwise:
PENDING. The current holder getsTakeoverRequestedand answers withTakeoverReply.- Allow: control is handed over.
- Keep: the requester gets
DENIEDwith a 60 s cooldown. - No answer within 15 s: granted only if the holder has made no change for 10 minutes. Otherwise
DENIED.
- One pending claim at a time.
An app must never claim again automatically after losing control to a take-over, so two phones can't ping-pong.
PIN: 4 digits, stored on the board as a salted hash. Wrong attempts back off exponentially per session, up to 300 s.
4.5 What a Partner App May Do
The controller role covers the game only. Changing how the board itself is set up needs a person at the board, whichever app sends the request:
| Request | Who |
|---|---|
| Read, subscribe, Identify | Any session |
| New game, Actions, SetState, clocks, brightness, horn, layouts, assets, playlists | Controller (clocks: also the Clock operator) |
| Field setup, Mirrors, PIN change, Wi-Fi network, firmware update, factory reset | The board must be in setup mode (its SETUP button held for 3 s) |
The app_id in Hello is shown to people ("Scored by …") and recorded in the audit events. It is never a security check; the PIN and setup mode are.
4.6 Connection Parameters (iOS)
The board accepts the connection parameters Apple's Accessory Design Guidelines ask for. The firmware checks the current guidelines before the defaults are locked. Our service UUID and advertising format are public and stay fixed, because each iOS app finds and pairs the board itself.
4.7 New Game
NewGame carries GameSettings: the sport, a preset id from DeviceInfo.sports[].presets (any field may override the preset), the mode, the teams, and an optional ExternalRef with your own game id. The board picks a new game_id and resets seq.
A plain state write can never start a new game. So a reconnecting phone with a queued old change can't overwrite a game someone else started.
5. Changing the Game
5.1 Rules Mode: Actions
Send ActionRequest { action }. The board applies it with the sport's rules, increments seq and notifies everyone.
Actions describe intent ("strike", "+2 home"), so they never go stale. Two operators can't overwrite each other, and a scorer who taps fast never waits for a round trip. To guard against a game that was replaced, put game_id in the request.
Undo: the Legends app keeps a history and undoes by sending the inverse action, e.g. ScoreAdjust -2. When an action has no inverse (a resolved walk), it uses a display-mode-style correction through BaseballAction and set fields. A board-side undo stack is a candidate for v1.1.
5.2 Display Mode: SetState
Start the game with NewGame { settings.mode = CONTROL_MODE_DISPLAY }. Then send SetState { state, base_seq } whenever anything changes.
What the board does in display mode:
- It keeps its own
game_idandseq. It ignores yours. - It runs any clock you mark
runningfrom themsyou send. A phone that drops out never freezes the clock. - It sounds the horn per the settings, and reports
Hornevents. - It does not apply sport rules: no flash resolution, bonus or penalty promotion. Your app does those. The board still counts running penalty timers down with the game clock.
base_seq: set it to the board's last seq you saw to get STALE if someone else changed the game, or to 0 for last writer wins.
Clocks: to avoid fighting the board over a running clock, send ClockCommand actions for clocks (allowed in display mode). Send a clock's ms in SetState only when setting it.
5.3 Clock Operator
A session holding ROLE_CLOCK_OPERATOR may send ClockCommand and AuxCommand only, in either mode. This matches high school tables, where the timer and the scorer are different people.
6. Sports Reference
Every sport uses home, away, period, period_label and clock. The table lists the rest.
| Sport | Team counters |
Other GameState fields |
Main actions |
|---|---|---|---|
| Baseball / softball | score |
baseball: half, balls, strikes, outs, flash, runners, pitch_count, batter, line_score |
BaseballAction (ball, strike, foul, out, new batter, half), ScoreAdjust |
| Basketball | score, fouls, timeouts_left, bonus |
aux (shot clock), possession (arrow) |
ScoreAdjust, FoulAdjust, Timeout, PossessionSet, AuxCommand, ClockCommand, PeriodChange |
| Hockey | score, shots, timeouts_left, penalties |
— | Goal (with release), ShotOnGoal, PenaltyAdd/Clear/Set, Timeout, clock |
| Lacrosse | score, timeouts_left, penalties |
aux (shot or possession clock) |
as hockey, plus AuxCommand |
| Football | score, timeouts_left |
football: down, to_go, goal_to_go, ball_on; possession; clock.hidden in overtime |
FootballAction, PossessionSet, Timeout, clock |
| Soccer | score |
soccer.added_minutes; clock counts up or down per settings |
ScoreAdjust, AddedTime, clock |
| Volleyball | score, sets, timeouts_left |
possession = serving team, period = set |
VolleyballAction (point, serve, end set), Timeout |
| Score + Timer | score |
— | ScoreAdjust, clock, PeriodChange |
| Practice timer | — | practice: segment label, index, count, next |
PracticeAction, clock; segments in GameSettings.segments |
| Message | — | message.lines |
MessageText |
| Custom | any | custom map |
CustomSet, any of the above |
Presets (e.g. nfhs, nfhs-shot, rec-halves, slowpitch, kickball, usah-12, girls-nfhs, flag, ifab, bo5) are listed per sport in DeviceInfo. Each preset’s exact values come with the SDKs.
7. Events
Event messages carry the board's monotonic time, the game clock and the period at that moment:
Horn, with its reason, andWarning(15 s left in a timeout).Resolved: the board finished a walk or a third out on its own.PenaltyEnded.ControlChanged.NewGameStarted, which echoes yourExternalRef.PowerNotice.Applied(audit, capabilityCAPABILITY_EVENTS_AUDIT): one per accepted change, with the action or "state replaced", and theapp_idthat made it.
A stats partner can build a play-by-play with game-clock times from the audit stream, whichever app did the scoring.
8. Custom Layouts, Assets and Playlists
Layouts:
- A layout is the same small model the built-in sports use: text, lamps, arrows, rectangles and bitmaps on the 128 × 64 grid, bound to
GameStatepaths (home.score,clock.ms,baseball.balls,custom.sponsor). - The JSON form of
Layoutis the same format as the built-in layouts, so you can design in the browser simulator and upload the same file. - The board checks every uploaded layout with the same rules as our tests: in bounds, known fonts and colors. It refuses a layout that fails.
Assets: 4-bit palette images (logos), up to Limits.max_asset_bytes, drawn by bitmap elements.
Playlists: rotate screens, for example a sponsor between innings or a tournament card at halftime. Then return to the game layout, or loop.
Limits: Limits.max_custom_layouts and max_asset_bytes. Built-in layouts can't be replaced. Every custom layout gets a small "Legends" mark in its corner, which the layout can't remove.
8B. Setup, Mirrors and Firmware Updates
These requests are in setup.proto, sent as ClientMessage.setup. They carry the reviewed rules:
- Setup mode: anything that changes how the board itself is set up needs a person at the board, holding SETUP for 3 s. Otherwise the board answers
SETUP_MODE_REQUIRED.DeviceInfo.setup_modeshows the state.
| Request | Who | What it does |
|---|---|---|
ConfigureMain |
Setup mode | The board creates a Field (id, key, mirror-link channel) and becomes its Main |
AddMirror → MirrorInvite |
Setup mode or Controller | The Main admits a Mirror and returns a per-Mirror link key, never the Field key. The invite lapses after 5 minutes without a HELLO. |
JoinField |
Setup mode (on the Mirror) | The app relays the invite to the new Mirror |
RemoveMirror |
Setup mode, or Controller with the PIN | Drops a Mirror |
ReplaceMain |
Setup mode (on a Mirror) | The Mirror takes over a Field whose Main is lost |
Rename |
Setup mode or Controller | Field name and board label |
SetPin |
Setup mode | Set, change or remove the PIN |
GetMirrors → MirrorList |
Any session | Mirror health: last ack, RSSI, firmware older than the Main |
SetWifi |
Setup mode | Join a network for the local API (§3.2) |
CreateAccessToken |
Controller | A bearer token for the Wi-Fi API |
FinishSetup, FactoryReset |
Setup mode | Leave setup mode, or erase everything |
Firmware updates (capability CAPABILITY_OTA): FirmwareBegin (size, SHA-256, version), then FirmwareChunks in order, then FirmwareEnd.
- The board checks the signature (Secure Boot v2) and keeps the previous image.
- It rolls back if the new image doesn't confirm itself after booting.
- It refuses an update while a clock is running.
- The Legends app updates Mirrors through the same flow, one board at a time.
9. Versioning and Compatibility
- Versions:
DeviceInfo.api_versionis semantic, e.g.1.2.0. The major version is the proto package (legends.board.v1). Minor versions add fields, messages, capabilities and presets. - Compatibility rules (checked by
buf breakingin CI):- fields are never renumbered, retyped or reused;
- enums only gain values;
- readers ignore unknown fields.
- Clients: check capabilities, not firmware versions.
- Deprecation: a deprecated field keeps working for at least 12 months and two minor versions, and the changelog says what replaces it.
- Conformance vectors: the vectors (actions in → states and frames out) ship with the SDKs. Partners can check their own display-mode logic against our rules, and the firmware runs them in CI.
10. Developer Kit
- SDKs (generated from the schema, plus a thin hand-written session layer: connect, Hello, claim, request/result matching, reassembly, reconnect):
- TypeScript
@legends/sdk: Web Bluetooth, Capacitor, React Native (viareact-native-ble-plx), and WebSocket. - Swift package (CoreBluetooth) and Kotlin (Android BLE).
- C: the board itself (nanopb).
- TypeScript
- Virtual board: Runs a board on your computer. It will be published as
npx @legends/virtual-board.- It uses the real rules engines and renderer, speaks the WebSocket API (§3.2) and shows the LED screen in a browser tab.
- Partner apps can be built and tested with no hardware.
- The desktop emulator adds Bluetooth, so phone apps can connect to a laptop.
- Browser simulator: design and check custom layouts pixel for pixel.
- Streaming overlay: a page that OBS or a streaming app adds as a browser source. It draws the live score from a Viewer session (through the Legends app or the virtual board), so a game streams with a scorebug and no partner integration.
- Machine-readable docs: a JSON Schema generated from the proto, for the proto3 JSON mapping used over Wi-Fi and the cloud, plus an AsyncAPI description of the WebSocket and SSE channels.
- Docs: this guide, generated message reference, sample apps (a minimal web scorer, a display-mode bridge, a spectator overlay), and a changelog. Available to partners on request.
11. “Works with Legends” Partners
- No key needed: any app can use the API, and a partner key is never needed for safety or basic features.
- What a partner key gives (issued by Pace Wireless):
- The partner's name and logo in the Legends app's "Scored by" line.
- A partner layout slot.
- Listing in the Works with Legends directory.
- Early access to firmware and test hardware.
- Certification: a partner app passes a short checklist before listing:
- it handles every
Status; - it respects take-over, with no automatic re-claim;
- it keeps within rate limits;
- it passes the conformance vectors if it uses display mode.
- it handles every
12. Integration Recipes
- A stats app scores the game and the board shows it:
- Connect over Bluetooth with the TypeScript, Swift or Kotlin SDK.
NewGamein display mode withExternalRef { app_id, game_id }. - On every play,
SetStatewith the current score, count, outs, inning, runners and pitch count. - Start and stop clocks with
ClockCommand. Subscribe toHornto show clock expiry in the app. - No Legends app is needed on the scorer's phone.
- Connect over Bluetooth with the TypeScript, Swift or Kotlin SDK.
- The board is scored in the Legends app; the stats app wants the data: subscribe to the audit stream, or (later) receive it from the Legends Cloud relay by webhook.
- Streaming overlay: a Viewer session over Bluetooth or Wi-Fi SSE, or a spectator scan of the advertising.
- Team and schedule import: a Legends app feature, not a board one. The app fetches the partner's teams and schedules (partner API), and fills
Team.name,short_name,color_rgbandexternal_idat New game. - Co-branded boards:
- A partner layout, such as a stats app's look for baseball, installed at the factory or uploaded.
- A partner boot-screen asset.
- A playlist for sponsors.