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

MethodEndpointDescription
GET/api/healthUptime, heap, max free block, tick statistics
GET/api/dashboardFull state: version, device name, panels, oled, peers, logger, automation
GET/api/systemChip type (ESP8266 / ESP32) and build info
GET/api/sensordebugRaw I2C sensor data and chip ID (raw UT/UP, trigger/echo counts)
GET/api/i2cscanI2C bus scan. ?sda=/?scl= override pins; ?debug=1 adds idle line levels and ACK/NACK/fault counts
GET/api/peersBoards discovered on the LAN (UDP beacon list)

Settings and configuration

MethodEndpointParameters
GET/api/settings— (returns all settings as plain text)
POST/api/settingsbody = full settings text (overwrites the file)
GET/api/backup— (downloads firefly-backup.txt)
POST/api/restorebody = backup text
GET/api/reset— (reboots the board)

Panels

MethodEndpointParameters
POST/api/createPanelname, type, input/output, hardware, pin, pin2, pin3, pin4, rpanel, mac, inverted, …
POST/api/panel/deleteid
POST/api/panel/targetid, target, enabled (bind a UDP remote panel)
GET/POST/api/panel/calibrateid, lowRaw, lowRef, highRaw, highRef, enable (direct two-point calibration; omit all calibration args to read the current points)
POST/api/eventid, value (trigger a panel event, e.g. a button press)
POST/api/pushbindbtn, 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 (or true) 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 for digital_out/pwm).
  • Backup: per-panel [panel:<id>] block stores inverted=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) and pwm (1 kHz) output panels cannot be used reliably on the same ESP8266 board. On ESP8266, analogWrite frequency/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 input panel with hardware ir_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 output type=ir_tx panel 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; 0x allowed)
    • ELECTRA:<hex> (exactly 13 bytes = 26 hex chars)
    • RAW:<hz>,us,us,... (optional leading repeat 1–5; hz default 38000 if <1000; up to 512 values; a captured RAW:38000,… pastes unchanged)
    • empty / unknown → no-op; fired slots show IR slot N on 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 legacy server_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 of ok, 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 with mode2_decode (IRremoteESP8266; tools/mode2_decode, built by tools/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 as RAW, unknown → raw.
  • Substitute only when ok && protocol non-empty && != "RAW" && code non-empty; otherwise raw. Output always slot-ready (NEC:… / ELECTRA:… / RAW:…). Keeping decode off-board keeps board RAM low.

/api/ir/* endpoints

MethodEndpointDescription
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

MethodEndpointParameters
POST/api/variables/addname, value
POST/api/variables/setname, value
POST/api/variables/deletename
POST/api/variables/computed/addname, a, b, op (+ - * /)

Automation

MethodEndpointParameters
POST/api/automation/addprogram, action, op, target, pause
POST/api/automation/deleteid
POST/api/automation/runid
POST/api/automation/setid, enabled
POST/api/automation/modeid, mode
POST/api/automation/program/addname
POST/api/automation/program/deletename
POST/api/automation/program/setname, running
POST/api/automation/program/runname
POST/api/automation/statement/addprogram, kind, target, pause
POST/api/automation/condition/addruleId, op, logic
POST/api/automation/condition/deleteruleId, 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 / settingsHow the message is delivered
ESP32 with direct_cloud,1, tg_token, and tg_chat_idDirect HTTPS to api.telegram.org from the board
Any board with logger_host (or legacy server_name) setPOST http://<logger-host>:8787/api/telegram/send to critter-bridge
No direct credentials and no logger hostLogged 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

MethodEndpointParameters
GET/api/displaytext, 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.

MethodEndpointParametersDescription
POST/api/update/filemultipart firmwareFlash 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=fsmultipart firmwareFlash 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)

  1. Build the .bin on your development machine:

    pio run -e d1_mini
    

    The files are at .pio/build/d1_mini/littlefs.bin (Filesystem) and .pio/build/d1_mini/firmware.bin (Sketch).

  2. 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.
  3. 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-data POST with a single file field named firmware (for sketch) or littlefs.bin (for FS; the server checks the ?target=fs query).
  • 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.h defines CRITTEROS_VERSION as "2.0-" CRITTEROS_BUILD
  • CRITTEROS_BUILD is injected at compile time by tools/inject_build.py (a PlatformIO pre-build script) which runs git 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

  1. Commit your changes (the hash becomes the build ID)
  2. Build: pio run -e d1_mini and pio run -e node32s
  3. Rebuild filesystem: pio run -e d1_mini -t buildfs and pio run -e node32s -t buildfs
  4. Copy binaries to static/firmware/ and static/firmware/esp32/
  5. Update version.txt to match the new git hash (e.g. 2.0-abc1234)
  6. 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.py script is wired into platformio.ini via extra_scripts = pre:tools/backup_before_uploadfs.py, pre:tools/inject_build.py.

Time

MethodEndpointParameters
POST/api/time/setepoch (Unix seconds)

Logger

MethodEndpointDescription
GET/api/loggerLogger status (enabled, interval, file, host)
GET/api/logger/fileDownload the log CSV

Static pages served by the board

PathDescription
/Web dashboard
/graph.htmlValue graph
/i2cscanner.htmlI2C scanner tool
/style.cssDashboard stylesheet

MQTT entry points

MQTT is an alternative to the HTTP API. Set mqtt_server (host or host:port) and mqtt_mode in Settings.

DirectionTopicPurpose
Subscribe (command)cmnd/<device>/<panel>Set an output / send a value
Subscribe (command)cmnd/<device>/displayPush text to the OLED
Publish (state)stat/<panel>/STATEPanel state (template configurable)
Publish (discovery)homeassistant/<type>/<device>_<panel>/configHome Assistant auto-discovery (when mqtt_mode=homeassistant)

Notes

  • Most POST endpoints return ok on success, bad args (400) or not found (404) on failure.
  • /api/update/file without target=fs keeps your configuration; with target=fs it 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.