Board API reference
Reference for the HTTP and MQTT entry points served by the Firefly / critterOS boards. The firmware serves a small REST-style API plus MQTT topics for Home Assistant and other LAN clients.
Base URL: http://<board-ip> or http://firefly.local (mDNS).
Note: the URL of the firmware page is
/firmware/on the website, but the board itself has no such path — all endpoints below are relative to the board’s own address.
Status and diagnostics
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/health | Uptime, heap, max free block, tick statistics |
| GET | /api/dashboard | Full state: version, device name, panels, oled, peers, logger, automation |
| GET | /api/system | Chip type (ESP8266 / ESP32) and build info |
| GET | /api/sensordebug | Raw I2C sensor data and chip ID (raw UT/UP, trigger/echo counts) |
| GET | /api/i2cscan | I2C bus scan. ?sda=/?scl= override pins; ?debug=1 adds idle line levels and ACK/NACK/fault counts |
| GET | /api/peers | Boards discovered on the LAN (UDP beacon list) |
Settings and configuration
| Method | Endpoint | Parameters |
|---|---|---|
| GET | /api/settings | — (returns all settings as plain text) |
| POST | /api/settings | body = full settings text (overwrites the file) |
| GET | /api/backup | — (downloads firefly-backup.txt) |
| POST | /api/restore | body = backup text |
| GET | /api/reset | — (reboots the board) |
Panels
| Method | Endpoint | Parameters |
|---|---|---|
| POST | /api/createPanel | name, type, input/output, hardware, pin, pin2, pin3, pin4, rpanel, mac, inverted, … |
| POST | /api/panel/delete | id |
| POST | /api/panel/target | id, target, enabled (bind a UDP remote panel) |
| GET/POST | /api/panel/calibrate | id, lowRaw, lowRef, highRaw, highRef, enable (direct two-point calibration; omit all calibration args to read the current points) |
| POST | /api/event | id, value (trigger a panel event, e.g. a button press) |
| POST | /api/pushbind | btn, slot, target (bind a push button to a program) |
For input panels whose hardware is an I2C driver (bmp180, bme280,
bme680, sht31, bh1750, mpu6050, vl53l0x), pin (SDA) and pin2
(SCL) default to 4 (D2) and 5 (D1) when omitted. The dashboard resets
both selects to those pins whenever an I2C driver is picked.
Output polarity (active low / inverted)
The global active_low setting controls default output polarity. Output panels
(type=output) with hardware digital_out or pwm also support a per-panel
Active low / inverted toggle:
- Create: pass
inverted=1(ortrue) to/api/createPanel. - Dashboard JSON: output panel objects include
"inverted": true|false. - Event:
/api/event?id=<panelId>inv&value=1|0. - Element API:
panelId.inverted(toggle element fordigital_out/pwm). - Backup: per-panel
[panel:<id>]block storesinverted=1|0.
When inverted, the logical value (0-100% for PWM, 0/1 for digital) stays the
same in the UI/rules, but the electrical pin drive is flipped for that panel
(useful for active-low devices).
ESP8266 limitation:
servo(50 Hz) andpwm(1 kHz) output panels cannot be used reliably on the same ESP8266 board. On ESP8266,analogWritefrequency/range are chip-global, so the last-created panel wins and the other misbehaves. Use one type per board, or use an ESP32, where LEDC timers allow different frequencies.
Direct two-point calibration
/api/event captures the current raw reading when you press Low/High. If you
already know the raw counts (or want to set the points without moving the
sensor), use /api/panel/calibrate instead. All four values are in the panel’s
raw units / engineering units, and the change is saved immediately.
# Set both points: raw 102 at 0 °C, raw 923 at 100 °C
curl "http://<board-ip>/api/panel/calibrate?id=tank&lowRaw=102&lowRef=0&highRaw=923&highRef=100"
# Enable/disable calibration
curl "http://<board-ip>/api/panel/calibrate?id=tank&enable=1"
# Read the current points (no calibration args)
curl "http://<board-ip>/api/panel/calibrate?id=tank"
lowRaw/highRaw may also be sent as calLRaw/calHRaw, and
lowRef/highRef as calLRef/calHRef (the backup-file names). Works for
input and flowcontrol panels.
Flow / RPM panels: when calibrated, the dashboard shows two values —
total (calibrated accumulated units, e.g. liters) and rate (calibrated
units per minute, e.g. L/min). Both are scaled by the same Low/High slope.
Leave uncalibrated for raw pulses/min (RPM mode: total = revolutions, rate =
rev/min).
Infrared (IR)
Two pieces work together:
- IR remote — an
inputpanel with hardwareir_remote, on an interrupt-capable pin (not D0). No protocol decode on-board (small RAM); it records mark+space durations in µs and exposes a RAW capture. Frames end on a 12 ms gap; up to 240 pulses kept (211 needed for ELECTRA_AC); timings snapped to common values for stable re-capture; NEC frames normalised. - IR panel — an
outputtype=ir_txpanel on a drivable output pin, with 4 learned slots (slot1…slot4, persisted; read back via/api/ir/txslots). Slot syntax:NEC:<hex>[:bits](bits default 32;0xallowed)ELECTRA:<hex>(exactly 13 bytes = 26 hex chars)RAW:<hz>,us,us,...(optional leading repeat1–5;hzdefault 38000 if<1000; up to 512 values; a capturedRAW:38000,…pastes unchanged)- empty / unknown → no-op; fired slots show
IR slot Non the OLED.
ir_remote values: default "" (last code; auto-stales to 0 after 2 s of silence; calibration applies like any input), code (sticky 24-bit id of the last captured button; match this in rules / copy it), pulse, repeat. Rule examples: IF ir.code == 123456 THEN SET relay1 = 1 once, SET ir1.send1 = 1. (Rules can only SET numeric values; slot text goes in via the dashboard, POST /api/element/set, or POST /api/event, while rules trigger slots with SET ir1.sendN = 1.)
Learning a slot: press any key once, then GET /api/ir/raw?id=… (raw) or GET /api/ir/decode?id=… (slot-ready code); paste into POST /api/element/set id=<ir>.slot1&value=…; replay with POST /api/event id=<ir>.send1&value=1 or SET <ir>.send1 = 1. See the /api/ir/* endpoints below.
IR decoder on the bridge side
GET /api/ir/decode returns raw if no decoder is available. With critter-bridge on the LAN, the board delegates decoding:
- Bridge host =
logger_host(or legacyserver_name), port 8787,http(s):///trailing/stripped; no separate bridge-host setting; no bridge host or unreachable bridge → raw unchanged. - Request
GET http://<bridge>:8787/api/ir/decode?raw=<url-encoded RAW>,Connection: close, 2 s connect / 3 s read, ≤ 4 KB; minimal JSON scan ofok,protocol,code. - Bridge (
ir_decode.decode_slot_code,GET/POST /api/ir/decode, CORS*) returns{"ok":true,"code":"…","protocol":"…","hz":38000}; prefers full protocol decode withmode2_decode(IRremoteESP8266;tools/mode2_decode, built bytools/build_mode2_decode.sh); lightweight NEC + ELECTRA_AC Python fallbacks; NEC →NEC:%08X:32, ELECTRA_AC →ELECTRA:<13-byte hex>, other protocols reported but returned slot-ready asRAW, unknown → raw. - Substitute only when
ok&&protocolnon-empty &&!= "RAW"&&codenon-empty; otherwise raw. Output always slot-ready (NEC:…/ELECTRA:…/RAW:…). Keeping decode off-board keeps board RAM low.
/api/ir/* endpoints
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/ir/raw?id=<inputPanelId> | text/plain last raw RAW:38000,us,us,...; no-cache; 400 id required, 404 not found, 404 not ir_remote |
| GET | /api/ir/decode?id=<inputPanelId> | text/plain slot-ready code; no-cache; 404 no capture; same checks; raw fallback |
| GET | /api/ir/txslots?id=<irPanelId> | application/json array of 4 slot strings; 400 id required, 404 not found, 404 not ir_tx |
Variables
| Method | Endpoint | Parameters |
|---|---|---|
| POST | /api/variables/add | name, value |
| POST | /api/variables/set | name, value |
| POST | /api/variables/delete | name |
| POST | /api/variables/computed/add | name, a, b, op (+ - * /) |
Automation
| Method | Endpoint | Parameters |
|---|---|---|
| POST | /api/automation/add | program, action, op, target, pause |
| POST | /api/automation/delete | id |
| POST | /api/automation/run | id |
| POST | /api/automation/set | id, enabled |
| POST | /api/automation/mode | id, mode |
| POST | /api/automation/program/add | name |
| POST | /api/automation/program/delete | name |
| POST | /api/automation/program/set | name, running |
| POST | /api/automation/program/run | name |
| POST | /api/automation/statement/add | program, kind, target, pause |
| POST | /api/automation/condition/add | ruleId, op, logic |
| POST | /api/automation/condition/delete | ruleId, index |
Telegram notifications
A panel of type telegram is a one-shot notification trigger. The message
template lives in the panel, and a rule raises the panel value to 1 when
the alert should be sent:
rule main IF pressure > 50 THEN SET tg1 = 1 once
When the board sees the value at 1, it renders the message, sends it, and resets
the panel to 0. A 5-second per-panel guard keeps a [while] rule (or a bouncing
condition) from flooding the chat. The placeholders {device}, {name},
{panel}, and {value} are expanded before sending; {value} and {panel}
use the panel’s optional source panel.
Transport selection
| Board / settings | How the message is delivered |
|---|---|
ESP32 with direct_cloud,1, tg_token, and tg_chat_id | Direct HTTPS to api.telegram.org from the board |
Any board with logger_host (or legacy server_name) set | POST http://<logger-host>:8787/api/telegram/send to critter-bridge |
| No direct credentials and no logger host | Logged locally; the trigger is reset |
The bridge host deliberately reuses the Logger server name instead of a
separate setting: the logger and critter-bridge normally run on the same
machine. The bridge listens on its default port 8787. It needs
telegram_token and a default telegram_chat_id configured in its own UI; the
board never sends the bot token. On ESP32, direct mode is used only when
direct_cloud=1 and both Telegram credentials are present — otherwise the
board falls back to the bridge.
The bridge endpoint returns 202 Accepted as soon as the message is queued and
delivers it from a background worker, so a slow Telegram API never blocks the
board. The board retries a failed bridge push (up to three attempts, 30 s apart)
and drops the message on a 4xx configuration error.
Display
| Method | Endpoint | Parameters |
|---|---|---|
| GET | /api/display | text, timeout (seconds; 0 = until cleared) — push text to the OLED |
OTA / update
The board serves a multipart-file upload endpoint that can flash either the sketch partition or the LittleFS (filesystem) partition.
| Method | Endpoint | Parameters | Description |
|---|---|---|---|
| POST | /api/update/file | multipart firmware | Flash the Arduino sketch. Keeps all panel rules, settings, WiFi config intact. Use this for new firmware releases that don’t change the filesystem. |
| POST | /api/update/file?target=fs | multipart firmware | Flash LittleFS (the small onboard filesystem). Wipes all configuration — panels, rules, settings, WiFi credentials are erased. Use this when you’ve edited the data/ directory (HTML, CSS, new panels) and need the board to serve the updated web pages. |
How to upload (browser-based, no USB needed)
Build the
.binon your development machine:pio run -e d1_miniThe files are at
.pio/build/d1_mini/littlefs.bin(Filesystem) and.pio/build/d1_mini/firmware.bin(Sketch).Upload the LittleFS image (to update dashboard HTML, CSS, etc.):
curl -X POST "http://<board-ip>/api/update/file?target=fs" \ -F "littlefs.bin=@.pio/build/d1_mini/littlefs.bin"- The board reboots automatically after success.
- After reboot, visit
http://<board-ip>/to verify the new dashboard.
Upload the firmware sketch (to update the code itself):
curl -X POST "http://<board-ip>/api/update/file" \ -F "firmware.bin=@.pio/build/d1_mini/firmware.bin"- Configuration (panels, rules, WiFi) is preserved.
- Board reboots into the new firmware.
Notes
- LittleFS upload wipes everything. After
?target=fs, you must re-enter WiFi, re-add panels, re-apply rules, etc. - The browser Update button in the dashboard (
/nav-update) also invokes this endpoint; it opens a file dialog to select the.bin. - Both endpoints accept
multipart/form-dataPOST with a single file field namedfirmware(for sketch) orlittlefs.bin(for FS; the server checks the?target=fsquery). - If you only need to change the HTML/CSS (as in this session), upload only the
littlefs.bin. The sketch does not need rebuilding unless the C++ code changed.
Version and build tracking
The firmware embeds a version string that combines the release version with the
git short hash of the source commit, e.g. "2.0-c75244e". This is returned by
/api/dashboard in the version field and is compared against
version.txt on the update server.
How it works
src/Config.hdefinesCRITTEROS_VERSIONas"2.0-" CRITTEROS_BUILDCRITTEROS_BUILDis injected at compile time bytools/inject_build.py(a PlatformIO pre-build script) which runsgit rev-parse --short HEAD- If git is unavailable, it falls back to
"nogit" - Both ESP8266 and ESP32 builds produce the same version string (same commit)
Publishing a new version
- Commit your changes (the hash becomes the build ID)
- Build:
pio run -e d1_miniandpio run -e node32s - Rebuild filesystem:
pio run -e d1_mini -t buildfsandpio run -e node32s -t buildfs - Copy binaries to
static/firmware/andstatic/firmware/esp32/ - Update
version.txtto match the new git hash (e.g.2.0-abc1234) - Deploy the website
Notes
- The updater compares the board’s version string against
version.txt(first line). Boards running an older commit won’t match and are flagged as outdated. - No manual version bumping is needed — the git commit hash is the build number.
- The
tools/inject_build.pyscript is wired intoplatformio.iniviaextra_scripts = pre:tools/backup_before_uploadfs.py, pre:tools/inject_build.py.
Time
| Method | Endpoint | Parameters |
|---|---|---|
| POST | /api/time/set | epoch (Unix seconds) |
Logger
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/logger | Logger status (enabled, interval, file, host) |
| GET | /api/logger/file | Download the log CSV |
Static pages served by the board
| Path | Description |
|---|---|
/ | Web dashboard |
/graph.html | Value graph |
/i2cscanner.html | I2C scanner tool |
/style.css | Dashboard stylesheet |
MQTT entry points
MQTT is an alternative to the HTTP API. Set mqtt_server (host or host:port)
and mqtt_mode in Settings.
| Direction | Topic | Purpose |
|---|---|---|
| Subscribe (command) | cmnd/<device>/<panel> | Set an output / send a value |
| Subscribe (command) | cmnd/<device>/display | Push text to the OLED |
| Publish (state) | stat/<panel>/STATE | Panel state (template configurable) |
| Publish (discovery) | homeassistant/<type>/<device>_<panel>/config | Home Assistant auto-discovery (when mqtt_mode=homeassistant) |
Notes
- Most POST endpoints return
okon success,bad args(400) ornot found(404) on failure. /api/update/filewithouttarget=fskeeps your configuration; withtarget=fsit wipes everything (panels, rules, settings, WiFi).- The board’s own address is usually reachable at
http://firefly.local(mDNS) when it is on your home network, or at its LAN IP otherwise. - Both the HTTP API and the MQTT topics are served by the same firmware, so Home Assistant can drive outputs and the display without HTTP.