Build a prop: a two-button domination box
From an ESP32 on the bench to a zone captured in a real game. Everything below is plain HTTPS and MQTT; any board and language that can do TLS will work. Our own reference firmware does exactly this and is MIT-licensed, so you can start from it instead: put it on a Heltec V4 from your browser at gridtac.com/flash (Chrome or Edge, a USB cable, no install). It talks to api.gridtac.com; the optional Server step on the same page points it at your own server or a dev stack instead. The protocol itself: GT-Link.
GT-Link
gtl/1is frozen: what this guide uses will not change under you. See the overview.
1. Pair it
The box has a small screen, so it pairs the way a TV does. With no key stored yet it asks for a code:
POST https://api.gridtac.com/api/v1/devices/announce
Content-Type: application/json
{ "kind": "prop", "model": "acme.dombox", "fw": "0.1.0" }
It shows userCode (for example KX7M-Q2RP), then polls POST /api/v1/devices/token with its
deviceCode every interval seconds. You type the code in the GridTac app (Account → My devices)
or on gridtac.com. The next poll answers once with deviceId (dev_…) and key (gt_prop_…):
store both in flash. Details and the Bluetooth path for boxes without a screen: Devices.
Pick a model name in your own namespace (yourname.thing); gridtac.* is ours. There is nothing to
register.
2. Connect
POST https://api.gridtac.com/api/v1/prop/mqtt-credentials
Authorization: Bearer gt_prop_…
Connect to wss://mqtt.gridtac.com/mqtt (or mqtts://mqtt.gridtac.com:8883) with the returned
username and token as the password, and set the last will to gridtac/dev/<id>/lwt =
{"on":false}, retained. Subscribe to gridtac/dev/<id>/cmd and gridtac/dev/<id>/game. Fetch new
credentials before expiresAt.
3. Say what it has
Publish the manifest to gridtac/dev/<id>/hello, retained, on every connect:
{
"p": "gtl/1",
"m": "acme.dombox",
"fw": "0.1.0",
"caps": [
{ "id": "red", "kind": "button", "label": "Red", "role": "team:0", "props": { "colour": "red" } },
{ "id": "blue", "kind": "button", "label": "Blue", "role": "team:1", "props": { "colour": "blue" } },
{ "id": "capture", "kind": "strip", "label": "Light bar", "props": { "pixels": 8 } },
{ "id": "beep", "kind": "buzzer", "label": "Buzzer" }
]
}
role: "team:0" marks a team button. Which side it means in a given game is decided by the game
master; by default the button's label or colour picks the side with that name or colour. Capability
ids are yours to choose (a port name like in3 is fine) and must stay the same across firmware
versions.
4. Keep a boot counter
Read a counter from flash at start, add one, write it back: that is b. Number every message in this
boot from 0: that is s. Send ms, milliseconds since boot, in every message. Never send a
wall-clock time; the box does not have a trusted one.
5. Send events
A press on the red button:
{ "b": 7, "s": 12, "ms": 905300, "c": "red", "e": "press" }
to gridtac/dev/<id>/evt at QoS 1. If the zone needs a hold, send hold with the held time in
milliseconds as x ({"c":"red","e":"hold","x":10000,…}) as soon as the button has been held long
enough, not on release.
Every minute or so, and on a change, publish telemetry to gridtac/dev/<id>/tele:
{ "b": 7, "s": 13, "ms": 960000, "bat": { "v": 3.92, "pct": 81 }, "rssi": -61, "up": 960 }
Lost the connection? Keep the events in a small queue with their b, s and ms, and send them
when it is back, after a fresh tele. GridTac dates them from that tele (up to 15 minutes back) and
drops anything it has already seen.
6. Listen to the server
On cmd, act on what you know and answer every command on gridtac/dev/<id>/ack:
{ "id": "own-3fa2c1d0-lx8k2", "ok": true }
What a capture box receives from GridTac:
| Command | Meaning |
|---|---|
{"k":"config","mo":"capture","set":{"holdMs":10000}} |
How long a hold is (0 = a press captures). Fill the light bar while a button is held, and send hold the moment it is long enough. |
{"k":"mode","mo":"capture","a":"owner","args":{"own":0}} |
Who holds the zone now: team slot 0-3, or null for neutral. Light the bar in that colour, or whatever your box does for an owner. |
{"k":"mode","mo":"capture","a":"answer","args":{"ok":false,"slot":0,"reason":"too_few_inside","have":2,"need":5}} |
The answer to a hold that started, in a game where enough players must be inside the zone. Show it: two of five. |
{"k":"disable","on":true} |
The game master switched the props off: everything dark, ignore the buttons until on: false. |
A mode command tells your box what happened in the game mode; how it shows that (lights, sounds,
a display) is up to the box. An output or action you do not have gets
{"id":"…","ok":false,"err":"unknown_output"}, a mode you do not run "err":"unknown_mode". Unknown
fields are ignored.
On game, keep the phase and the clock: offset = srv - millis(). While ph is not live, show
that and do not capture locally.
7. Into a game
The game master adds the box to the game, binds it to a zone and picks how the zone is taken: by the box alone (a press or a hold) or by the box with enough players of that side inside. They see its battery, signal and last seen, and can switch every prop in the game off at once.
No MQTT? Use HTTPS
A box that wakes, sends and sleeps can post the same messages in one batch:
POST https://api.gridtac.com/api/v1/prop/events
Authorization: Bearer gt_prop_…
Content-Type: application/json
{ "tele": { "b": 7, "s": 11, "ms": 905000, "bat": { "pct": 81 } },
"evts": [{ "b": 7, "s": 12, "ms": 905300, "c": "red", "e": "press" }] }
The answer carries accepted, the commands waiting for the box, and the current game. Sending a
batch again after a timeout is safe: events are deduplicated on b and s.
Every field: Message reference.