Skip to content

Set up an ESP32 board

TriggerGate's ESP32 firmware turns a wESP32 board into a self-contained TriggerGate with eight inputs: it serves the same hub and the same web page as the Windows and Uno editions, over Ethernet. This page takes a board from a firmware build you have received to a running device: the first flash over USB, the first start, finding the board on the network, and later updates over the network. During pre-release, firmware builds are supplied on request: get in touch.

What you need

Item Requirement
Board A wESP32 with 16 MB of flash and the RTL8201 Ethernet PHY, which is the PHY the firmware drives.
USB connection The USB serial connection the board's maker documents for programming the board. Only the first flash, and recovery, need it.
Network Ethernet with a DHCP server. The board takes its address by DHCP; it has no static address setting. It can be powered over Ethernet (PoE).
Inputs Contacts wired as described in ESP32 input wiring.
Computer Python 3 with esptool for the first flash (python -m pip install esptool). For updates, Python 3 with the cryptography package (python -m pip install cryptography), and optionally PowerShell 7.

A firmware build has two parts:

Files Used for
bootloader.bin, partitions.bin, ota_data_initial.bin, firmware.bin, littlefs.bin The first flash over USB. firmware.bin is the firmware and littlefs.bin the web page; the other three set up the board's flash.
A signed update bundle (.tgupd), the public key it was signed for (.pem), ota_bundle.py and Update-TriggerGateEsp32.ps1 Updates over the network. Neither tool needs a private key.

Flash the board over USB

Connect the board's USB serial connection and find its port (for example COM7 on Windows, /dev/ttyUSB0 on Linux). In the folder that holds the five files:

python -m esptool --chip esp32 --port COM7 write_flash --flash_size 16MB -z `
  0x1000 bootloader.bin `
  0x8000 partitions.bin `
  0xf000 ota_data_initial.bin `
  0x20000 firmware.bin `
  0x320000 littlefs.bin

On Linux or macOS, put the command on one line or end each line with \ instead of a backtick.

A board that already runs TriggerGate firmware keeps its settings and its HTTPS identity in a separate area of flash, which this flash does not touch. Back that area up first, so you can restore it if something goes wrong:

python -m esptool --chip esp32 --port COM7 read_flash 0x9000 0x5000 nvs-backup.bin

The backup contains the board's private HTTPS keys. Keep it private, outside any shared folder, and delete it when you no longer need it.

Then flash the five files exactly as for a new board:

python -m esptool --chip esp32 --port COM7 write_flash --flash_size 16MB -z `
  0x1000 bootloader.bin `
  0x8000 partitions.bin `
  0xf000 ota_data_initial.bin `
  0x20000 firmware.bin `
  0x320000 littlefs.bin

Replace COM7 with your board's port. Do not erase the whole flash of a board that already runs TriggerGate: that erases its settings and its HTTPS identity, and every computer and phone would have to install a new certificate.

After the first flash, update the board over the network. Use USB again only for recovery, and then always write all five files together: ota_data_initial.bin makes the board start from the slot that the firmware and web page were written to.

What the board does when it starts

  1. Reads its settings from flash: which GPIO each input uses, the status output, the NTP server, and OSC destination/source-subnet defaults. A board with no settings uses the defaults in ESP32 input wiring and the OSC defaults in Trigger actions.
  2. On its first start only, creates its own certificate authority and HTTPS certificate for its name. This takes a moment.
  3. Writes its name and its certificate authority's SHA-256 fingerprint to the serial log, at every start.
  4. Advertises itself over mDNS, starts Ethernet and asks for an address by DHCP.
  5. Opens its inputs. They are read whether or not the network is up.
  6. Starts its device log, mounts the web page that belongs to the running firmware, and starts its web servers on ports 80, 9090 and 443.
  7. Once the network is up, starts synchronizing its clock by NTP and listens for a PTP master. See Clocks and time.

After an update, the board also checks its own health: the new firmware is kept only if its web page mounts and its web servers start, and the network comes up within 60 seconds. Otherwise the board returns to the previous firmware and web page by itself.

The status output (GPIO 2 by default) lights for one second after any input changes, and for half a second when a client sends Identify.

The serial log runs at 115200 baud. The two lines to look for are:

TLS identity: device triggergate-a1b2c3.local, CA fingerprint (SHA-256) ...

which gives the board's name and the fingerprint to compare with the certificate page before you trust it, and, if the web page cannot start, a line beginning Web UI unavailable: with the reason.

Find the board on the network

The board's name is triggergate- followed by the last three bytes of its Ethernet MAC address in lowercase hexadecimal, for example triggergate-a1b2c3. It uses that name in three places:

  • mDNS: triggergate-a1b2c3.local, on any computer that resolves .local names.
  • DHCP: as its host name, so it appears under that name in your DHCP server's list of leases. The address is there too.
  • DNS-SD services, which discovery tools browse:
Service Port What it is
_gp-triggergate._tcp 9090 The hub. The find button in client applications, and tgtest discover, list the board through it. See The tgtest tool.
_https._tcp 443 The web page.
_http._tcp 80 The certificate page, at /.well-known/gameshowpro/, while the board uses its own certificate authority.

The board keeps the name it had when it created its HTTPS identity. If another device on the network answers for the same name, the board's mDNS responder renames it to triggergate-a1b2c3-2.local; the board logs this, and its certificate stays valid only for the original name.

Open the web page

Open http://triggergate-a1b2c3.local/ (or http://<board-ip>/). The board sends you to its certificate page, where you install the board's certificate once. A browser that already trusts it goes on to the web page at https://triggergate-a1b2c3.local/. See Open the web page over HTTPS for the steps on each kind of computer and phone, and HTTPS settings and your own certificate to use a certificate from your own certificate authority.

In the web page's settings dialog you can:

  • assign each of the eight logical inputs to a GPIO, or leave it unassigned, and choose the status output (see ESP32 input wiring),
  • set the NTP server (see Clocks and time), and
  • set OSC playback defaults for destination and source subnet (see Trigger actions).

Settings are saved in the board's flash and kept across restarts and updates.

Applications connect to the hub at http://triggergate-a1b2c3.local:9090/TriggerGate, as for any TriggerGate. See .NET client library.

Update the firmware

An update replaces the firmware and the web page together, from one signed bundle. Put the bundle, its public key, ota_bundle.py and Update-TriggerGateEsp32.ps1 in one folder, and use the board's http:// address:

./Update-TriggerGateEsp32.ps1 -Bundle triggergate.tgupd -PublicKey triggergate-ota-public.pem -DeviceUrl http://triggergate-a1b2c3.local

Add -Python <path> if Python is not on the PATH as python.

python ota_bundle.py upload --bundle triggergate.tgupd --public-key triggergate-ota-public.pem --url http://triggergate-a1b2c3.local

Use the file names of the bundle and key you received. What happens:

  1. The tool checks the bundle's signature and both image hashes against the public key, before it sends anything, and prints Bundle signature, lengths, and image hashes valid; epoch ....
  2. The board checks the signature again before it erases anything, writes the update to its inactive slot, reads it back and checks it, and answers {"accepted":true,"rebooting":true}. It then restarts into the new version.
  3. The tool waits up to 90 seconds for the board to report the new version, running from the other slot and confirmed healthy, and prints Device healthy on slot ... at epoch ....

The previous firmware and web page stay in the other slot. If the new version does not start cleanly, the board returns to them by itself, and the tool reports Device did not return healthy on the expected epoch and slot.

To see what a board runs, open http://triggergate-a1b2c3.local/api/update/status. It reports whether updates are enabled, whether one is in progress, the running slot, the running build's epoch (a build time in Unix seconds) and whether the running firmware is confirmed.

Scripted updates without the tools

The bundle is already signed, so a script can send it as it is, with any HTTP client, to the board's upload address on port 80. It must have the content type application/vnd.triggergate.update:

curl --data-binary @triggergate.tgupd -H "Content-Type: application/vnd.triggergate.update" http://triggergate-a1b2c3.local/api/update/bundle

The board checks and installs the bundle exactly as when the tools send it, answers {"accepted":true,"rebooting":true} and restarts, or answers with one of the errors below. Without the tools nothing is checked on your computer first, and nothing waits for the result: read /api/update/status afterwards and check that buildEpoch is the new build's, slot has changed and confirmed is true.

When the board refuses an update

The tool prints Meaning What to do
HTTP 503: Device busy A faceoff or pre-faceoff is armed or a lockout is running, a button health check is running, random test triggers are running, or an Identify is in progress. End it, then run the update again.
HTTP 503: OTA busy Another update is in progress, or one has finished and the board has not restarted yet. Wait for the board to restart.
HTTP 400: Invalid bundle epoch or length The bundle is not newer than the firmware the board runs. A board only accepts a newer build. Use a newer bundle.
HTTP 400: Invalid signed manifest The board does not trust the key the bundle was signed with. Use a bundle signed for this board's firmware.
HTTP 403: OTA trust key absent This firmware was built without an update key, so it accepts no update over the network. Flash a build that accepts updates, over USB.

If the tool itself stops before sending anything, the bundle does not match the public key you gave it, or the file is damaged.

Limits

  • Eight inputs.
  • DHCP only; no static address.
  • OSC trigger actions and RunOsc are supported over IPv4 Ethernet. OSC datagrams are limited to 1472 bytes; prepared action payloads use a bounded queue of 32 slots and 8192 bytes. A full queue refuses direct RunOsc; a faceoff action that cannot be queued is logged and dropped without invalidating faceoff timing. Lighting actions remain unsupported and are refused. See Trigger actions.
  • Updates are accepted on the board's plain HTTP address (port 80) only.
  • The HTTPS web page allows three connections at a time. Close web pages you are not using.
  • The board's flash is not encrypted. Anyone who can take the board and read its memory can read its settings and its HTTPS keys.
v2.0.62