How it works

Firebrat is a small thermal camera with a lot of ways in: its own screen and buttons, a USB cable, your WiFi and Bluetooth. This page explains how each one works, how you set the camera up, and how one interface, composed on the camera, reaches every screen.

The big picture

The camera reads a 32×24 grid of temperatures from an MLX90640 sensor up to 16 times a second, cleans it up (denoise, median) and keeps the newest frame in memory. Four readers take frames from there, each at its own pace: the LCD, the WiFi web app, the USB stream and the Bluetooth stream.

The unusual part is the interface. The camera doesn't serve pages that contain its controls. It builds the interface itself, in C++, and sends it as JSON messages that bitwrench.js turns into the page. Because the interface is just messages, the same one travels over WiFi, a USB cable or Bluetooth, and a web page that knows nothing about the firmware version can show it.

Diagram: the camera in the middle with its screen and buttons; a USB cable carrying the console, the live stream and the host CLI; WiFi carrying the web app and the HTTP API; Bluetooth carrying WiFi setup, the live stream and a console.

Every way in

Way inWhat you getWhat you needWhere the UI comes from
The camera itselfLive heat map, max / centre / min, network status; buttons for palette, interpolation, range hold and Bluetooth setupNothingDrawn by the firmware on the LCD
WiFi web appThe full UI: controls, image-quality sliders, snapshots, recording, hover temperaturesThe camera on your WiFi; any browser on the same networkServed from the camera's flash; controls sent by the camera
WiFi HTTP API/api/frame (temperatures in °C as JSON), /api/statusSame network; curl, a scriptPlain JSON
USB consoleEvery setting and diagnostic as typed commands (help)A cable and any serial terminal at 115200The camera's console (xelp)
USB live viewThe same full UI as WiFi, with no networkA cable and Chrome or Edge (Web Serial)camera.html on this site; controls sent by the camera over the cable
Host CLISnapshots and recordings as PNG, CSV and JSON on your computerA cable and Python with pyserialtools/firebrat.py
Bluetooth WiFi setupGive the camera your WiFi; scan; forgetChrome or Edge (desktop, Android), or Bluefy on iOSsetup.html on this site
Bluetooth live viewThe same full UI, with no WiFi and no cable (up to about 15 fps)Web Bluetooth (as above)camera.html; controls sent by the camera over Bluetooth
Bluetooth consoleThe same commands as the USB consoleAny BLE terminal app (nRF Connect, Bluefruit Connect, Serial Bluetooth Terminal)The camera's second console

Inside the camera

At power-up

  1. Settings load from flash: WiFi, hostname, palette, frame rate, denoise and the rest.
  2. The screen shows a splash.
  3. The sensor is found. The camera tries the I2C pin pairs it knows (the T-Display-S3's connectors, then common generic pins), recovers the bus first in case a reset interrupted a transfer, and remembers the pins that worked.
  4. WiFi starts if a network is saved. The camera keeps retrying in the background if it can't connect.
  5. Bluetooth starts advertising as Firebrat-XXXX (the last four hex digits of its address). It stays discoverable whenever no phone or computer is connected to it.
  6. Both consoles start, USB and Bluetooth, with the same commands.

Tasks and cores

The ESP32-S3 has two cores. The work is split so that a slow reader never holds up the others:

TaskCoreJob
Sensor1Read both half-frames over I2C (1 MHz at 8 and 16 fps), fix the chess pattern, denoise, median, publish the frame
LCD1Upscale 7× (nearest, bilinear or bicubic) and draw, about 14 ms render and 18 ms push per frame
USB stream1The live UI over the cable, while stream on
Main loop1Consoles, buttons, WiFi and Bluetooth bookkeeping, saving settings
Web0The live UI to every browser on WiFi
Bluetooth0The live UI and console output over Bluetooth

Each stream sends only the newest frame when it is ready for one, never a queue. A slow Bluetooth link simply shows fewer frames, and can't make USB or WiFi skip any.

First-time setup

Out of the box the camera already works on its own screen. To use it in a browser over WiFi, it needs your network name and password. There are three ways to give them to it:

  1. Bluetooth, from this site: open WiFi setup in Chrome or Edge, click Connect, pick your network, enter the password, Save. The page then shows the camera's address.
  2. USB console: plug in, open a serial terminal at 115200 and type wifi "My Network" "my password". Quotes allow spaces.
  3. Bluetooth console: the same wifi command from a BLE terminal app, while the setup window is open.

Once it joins, the camera shows its IP address and firebrat.local on its screen. Open either in a browser on the same network. The hostname can be changed with name.

The setup window

Anyone nearby can see the camera over Bluetooth, but it only accepts WiFi changes (save, scan, forget) during its setup window. The window is open:

Outside the window, the camera refuses those writes and its Bluetooth status says so ("setup": false, then "refused": true). The setup page tells you to long-press KEY rather than doing nothing. The password can be written but never read back. To remove saved WiFi, use Forget saved WiFi on the setup page (during the window) or wifi forget at the USB console.

WiFi: the web app

On your network the camera is a small web server. Everything it serves is in flash, gzipped, with no file system:

RequestWhat the camera sends
GET /A redirect to /index.html: a 27-line bootstrap page
GET /bitwrench.jsbitwrench.js, 47 KB gzipped, cached by the browser for a year
GET /thermal.js, /img/logo.svgThe frame painter (the same file this site uses) and the logo
GET /bw/eventsThe live UI as Server-Sent Events: the whole page first, then updates
POST /bw/eventsButton and slider actions coming back from the page
GET /api/frameThe current frame: 768 temperatures in °C, as JSON
GET /api/statusName, versions, IP, sensor state, number of viewers, uptime

What happens when you open the camera in a browser:

  1. The bootstrap page loads bitwrench.js and the painter, sets the theme and calls bw.connect('/bw/events').
  2. The camera answers with one mount message: the whole interface (top bar, image, controls, image-quality card, info panel), composed in C++.
  3. Then, for every frame, one batch message: a call that hands the frame to the page's painter, plus patches for the max / centre / min readouts. Status (WiFi signal, heap, viewers) follows every 2 seconds.
  4. When you press a button, bitwrench posts a small event naming its action (for example pal-iron, from the button's bw_act_pal-iron class) back to /bw/events. The camera applies it, saves it, redraws its own screen, and sends the updated controls to every browser. All viewers stay in sync.

If a browser falls behind, the camera skips frames for it instead of queueing them.

USB: console, live view, host CLI

The USB cable is one serial port (the ESP32-S3's built-in USB) at 115200. Only one program can open it at a time, so close any serial monitor before using the live view or the host CLI.

The console

Type help for the list. The console runs on xelp, with line editing, history, quoted arguments, ; to chain commands, and a 256-byte line. The commands cover everything the web UI can do, and more:

status                     WiFi, web, Bluetooth and sensor state, frame timing, read errors
wifi "SSID" "password"     join a network (wifi scan, wifi forget)
palette iron               iron | rainbow | gray | hot | arctic
interp bicubic             nearest | bilinear | bicubic
rate 16                    full frames per second: 1 | 2 | 4 | 8 | 16
denoise auto               on | off | auto   (also blend, motion, chess, median)
range auto                 or: range 20 35
snap                       one frame as a SNAP:{json} line (snap csv for CSV)
ble on                     open the Bluetooth setup window for 5 minutes
stream on                  switch the port to the live UI (see below)

The live view over USB

Live camera on this site uses Web Serial. When you click Connect over USB and pick the camera's port, the page sends stream on. The camera then:

The page applies each UI: line with bw.apply(), and bitwrench routes button presses into act lines. No WiFi is involved; this works on a camera that has never seen a network. Measured: 15.8 fps with no skipped frames.

The host CLI

tools/firebrat.py talks to the console from a computer: snap saves a PNG, CSV or JSON snapshot, record saves a run of frames (about 16 fps), render turns saved frames into PNGs with the camera's own palettes and interpolation, and cmd runs any console command.

Bluetooth: setup, live view, console

The camera runs three Bluetooth LE services at once:

ServiceCharacteristicsUsed by
Setup 8f3c0001-……0002 SSID (write), …0003 password (write only), …0004 command: connect | forget | scan, …0005 status JSON (read, notify), …0006 scan results (read)setup.html
Live UI (same service)…0007 UI stream (notify), …0008 commands: stream on | stream off | act {…}camera.html
Console: Nordic UART 6e400001-…RX (write) and TX (notify)Any BLE terminal app

Setup over Bluetooth

The setup page connects, reads the status (WiFi state, SSID, IP, and whether the setup window is open) and listens for changes. A notification can be cut to the Bluetooth packet size, so the page treats each one as a nudge and reads the full status again. Save writes the SSID and password, then connect. Scan asks the camera to scan and reads the list it finds.

The live view over Bluetooth

The same page as USB, a different pipe. The page writes stream on to the command characteristic and the camera sends the UI messages as notifications, split to fit the negotiated packet size (the camera offers up to 517 bytes) and joined back into lines by the page. Bluetooth is slower than USB (about 17 KB/s), so frames travel in a compact form: one byte per pixel, scaled between a low and a high temperature, instead of two. That gives up to about 15 fps.

The Bluetooth console

A second console with the same commands as USB, over the Nordic UART Service that BLE terminal apps understand. Commands that could lock you out (WiFi, hostname, sensor pins, the setup window, reboot) only work while the setup window is open.

One connection at a time

While a phone or computer is connected, the camera stops advertising, so others can't find it. If the camera seems to have vanished, disconnect it from the other page or device first (the console's status shows ble: connected when something is attached).

One UI, sent as data

Every live view (WiFi, USB, Bluetooth) runs the same interface, because the camera sends it as data rather than as a page. The messages follow bitwrench's bwserve protocol:

{v:1, type:'mount', ref:'#app', taco:{t:'div', c:[ …the whole interface… ]}}

{v:1, type:'batch', ops:[
  {v:1, type:'call',  name:'thermal', args:[{w:32, h:24, pal:'iron', interp:'bicubic',
                                             lo:22.1, hi:30.3, px:'<base64>'}]},
  {v:1, type:'patch', ref:'fb-max', text:'30.3'},
  {v:1, type:'patch', ref:'fb-min', text:'22.2'}
]}
Camera sendsPage sends backPage connects with
WiFiServer-Sent Events on /bw/eventsPOST /bw/eventsbw.connect()
USBLines prefixed UI:act {…} linesWeb Serial + bw.apply()
BluetoothNotifications, compact framesact {…} writesWeb Bluetooth + bw.apply()

Two things follow from the camera owning the UI. The pages on this site work with any Firebrat firmware, older or newer, because the camera brings its own controls. And a new control means changing the firmware only.

Settings and what persists

Settings live in the ESP32's flash (NVS) and survive power-off: WiFi name and password, hostname, palette, interpolation, frame rate, denoise (auto or manual blend and motion), chess fix, median, flips, colour range, and the sensor's I2C pins. Slider changes are saved after a short pause, so dragging doesn't wear the flash. wifi forget erases the WiFi credentials only.

Security in one paragraph

Firebrat is built for a home or lab network. The web app and the Bluetooth live view have no login and no encryption: anyone who can reach the camera on your WiFi, or is in Bluetooth range, can watch and change view settings. WiFi credentials can only be changed over Bluetooth during the setup window, and the password is never readable. The camera never contacts the internet. Details and how to report a problem: SECURITY.md and PRIVACY.md.

Where it lives in the code

PartFiles
Sensor, denoise, frame feedsrc/thermal.cpp, src/imaging.cpp (pure, unit-tested)
LCD and buttonssrc/display.cpp, src/main.cpp
WiFi, web server, the UI composed in C++src/net.cpp
Bluetooth servicessrc/ble.cpp
Consoles (USB and Bluetooth) and the USB streamsrc/cli.cpp
Settings in flashsrc/settings.cpp
The camera's bootstrap pageweb/index.html
The frame painter (camera and site)docs/thermal.js
Live view and setup pagesdocs/camera.js, docs/setup.js
Host CLItools/firebrat.py

The Docs page has build and flashing steps, wiring, every setting and troubleshooting. The source is on GitHub.