critter-bridge — cloud IoT for standalone boards

critter-bridge is a small companion app that runs on a PC, Raspberry Pi or any always-on device on your LAN. It polls state from your Firefly boards and pushes it to free cloud IoT services (ThingSpeak first; Adafruit IO, InfluxDB Cloud and others on the roadmap) and to Telegram — things an ESP8266 cannot do reliably on its own. It also accepts board-originated Telegram pushes from newer firmware, so a rule can deliver an alert immediately instead of waiting for the next poll.

Who needs it

  • ESP8266 users who want remote visibility (ThingSpeak charts, Telegram alerts) without Home Assistant.
  • ESP32 users who prefer a centralised setup: secrets live on the bridge, not on the board.

If you already run Home Assistant, you don't need the bridge — keep using HA's MQTT integration. If you have a single ESP32 board and no always-on device, use ESP32 direct cloud mode instead.

How it works

  • Polling (pull). The bridge polls each board's existing /api/dashboard endpoint every 15–30 s for ThingSpeak and bridge-side rules.
  • Board push (optional). Newer critterOS firmware posts Telegram triggers to POST /api/telegram/send. The endpoint queues the message and returns 202 immediately; a background worker calls Telegram. The board finds the bridge through the Logger server name (logger_host, or legacy server_name) on port 8787, so there is no separate bridge-host setting.
  • ThingSpeak (first backend). Forwards panel values to a ThingSpeak channel (one board = one channel by default, so multiple boards never contend for the free-tier ~15 s update cadence).
  • Rules → Telegram. Panel-state conditions (threshold, hysteresis, per-rule cooldown) trigger Telegram messages. Bridge rules skip telegram panels because the board handles those triggers itself.
  • Local web UI on port 8787 for board registry, ThingSpeak field mapping, rules, settings and an event log.

Telegram setup

Enter the bot token and a default chat id in the bridge's Settings card. The test button and board-originated pushes both use that chat unless the sender supplies an explicit chat_id.

POST /api/telegram/send
Content-Type: application/json

{“text”:“pressure is high”,“device”:“firefly”,“panel”:“tg1”}

Requires a configured telegram_token and either telegram_chat_id or a chat_id in the request. Returns 202 {"ok":true,"queued":true} on success, 400 for missing configuration, or 503 if the queue is full.

IR decode

The bridge also hosts a small IR decoder so boards keep no protocol library and low RAM. Firefly's ir_remote input panel captures raw IR; the board then asks the bridge for a slot-ready code.

GET  /api/ir/decode?raw=RAW:38000,9000,4500,...   (also POST JSON {"raw": ...}; CORS *)
→ {"ok":true, "code":"NEC:8F701FE:32", "protocol":"NEC", "hz":38000}
  • Prefers full protocol decoding with mode2_decode (from IRremoteESP8266; bundled at tools/mode2_decode, built by tools/build_mode2_decode.sh, also searched in tools/ and PATH); falls back to lightweight Python decoders for NEC and ELECTRA_AC.
  • code is slot-ready for a Firefly IR panel: NEC:<hex>:<bits>, ELECTRA:<hex>, or RAW:38000,…. Other protocols are reported in protocol but returned slot-ready as RAW; unknown → raw unchanged; ok:false on empty/short capture.
  • Board integration (automatic): a Firefly board calls this when its logger host (logger_host, or legacy server_name) is this bridge, port 8787, via its GET /api/ir/decode?id=… endpoint. The board uses the bridge's code only when ok and protocol != RAW, otherwise returns the raw capture; unreachable bridge → raw.
  • The capture → slot workflow: add an ir_remote input, press any key, fetch GET /api/ir/raw / GET /api/ir/decode on the board, paste the slot-ready code into one of an ir_tx IR panel's 4 slots, then trigger send1…send4 from a rule. See the board API reference.

Quick start

git clone https://github.com/mfacen/critter-bridge
cd critter-bridge
./run.sh          # creates the Python venv on first run
# open http://localhost:8787

Requirements: Python 3.9+. The app creates config.json on first run; boards are auto-discovered from their UDP beacon, so you rarely need to type an IP.

Design notes

  • Trusted LAN. Traffic between the bridge and boards is plaintext HTTP, matching critterOS's hobbyist stance. Do not expose the board or the bridge beyond your LAN.
  • Polling wakes the OLED. /api/dashboard counts as a viewer in critterOS, so a polled board keeps its display awake.
  • Secrets stay on the bridge. In bridge mode, ThingSpeak keys and Telegram tokens never reach a board. ESP32 direct mode is the exception: that board stores its own ThingSpeak/Telegram credentials.

Source

critter-bridge is a separate repository: github.com/mfacen/critter-bridge.