MT3chn1k/TankWatch 是一个托管在 GitHub 上的开源项目,主要使用 Python 编写,采用 MIT License 许可证。
仓库全名
MT3chn1k/TankWatch
README 摘要
TankWatch Tracking anything you can buy an open sensor for. TankWatch started as a way to watch three fish tanks with Raspberry Pis. It works for anything a cheap, open sensor can measure: aquariums, house plants, a pet feeder's food level, a room, a garage freezer. You get the same kind of live dashboards and history that commercial aquarium controllers charge hundreds of dollars for, on hardware you already own,…
TankWatch started as a way to watch three fish tanks with Raspberry Pis. It works for anything a cheap,
open sensor can measure: aquariums, house plants, a pet feeder’s food level, a room, a garage freezer.
You get the same kind of live dashboards and history that commercial aquarium controllers charge hundreds
of dollars for, on hardware you already own, with no subscription and no cloud account.
sensor Pis (nodes) hub (one Pi 5, or any Linux box)
┌──────────────────────┐ ┌──────────────────────────────┐
│ tankwatch-node │ readings, every │ InfluxDB ← stores history │
│ • DS18B20 water °F │ ──────────────────► │ Grafana ← dashboards │
│ • DHT11 air/humidity│ 30–60 s (HTTP) │ │
│ • the Pi's health │ │ both in Docker │
└──────────────────────┘ └──────────────────────────────┘
Everything runs in Docker. One command sets up the hub; a short wizard sets up each sensor Pi.
An admin page for your whole fleet.http://<hub>:8088 shows every collector’s health and what it
reports, walks you through adding a new sensor Pi (it shows the join code and spots the new Pi when it first
reports), and builds the status sign’s config for you. See admin/README.md.
Pis find their own way home. Paste one join code on a new Pi and it finds the hub, detects its sensors and
starts. If the hub’s address ever changes, every device finds it again by itself.
See docs/setup-and-discovery.md.
Sensors are plug-ins. Each collector lists its sensors in one tankwatch.yaml. Adding a new kind of
sensor is one small Python file; see docs/adding-a-sensor.md.
Built for reliability. Nodes keep readings in memory while the hub is unreachable and send them when it
comes back. Every node also reports its own health (CPU temperature, Raspberry Pi undervolt and throttle
warnings, memory, disk), so you know when a sensor box is the problem, not the tank.
Least-privilege tokens. Nodes get a write-only token; Grafana gets a read-only one. A lost sensor Pi
can’t read or delete your history.
°F or °C. Every temperature is stored in both; dashboards have a units switch.
A status sign that tells you when a collector is down. You don’t have to open a dashboard to know
something’s wrong. See below.
The two dashboards that come with TankWatch, shown with 24 hours of sample data: two tanks and a room,
with a water change around 17:00, and three collectors plus one that has gone silent (DOWN).
The status sign: alerting you can see from across the room
A dashboard only helps if you look at it. TankWatch drives an inexpensive LED matrix sign (Pimoroni Galactic
Unicorn) that sits on a shelf and shows every collector’s state by colour:
The real sign. The third collector has gone silent, so its block is red, and the humidity shown is that
collector’s last reading, drawn in grey because it’s stale. The camera washes the grey out to white.
Colour
Meaning
🟢 Green
The collector is reporting normally
🟡 Amber
It’s reporting, but something’s wrong: undervoltage, CPU throttling, or running hot
🔴 Red
The collector has gone silent. No report for 90 seconds. It has crashed, lost power, or dropped off the network
The sign reads straight from the hub’s database with its own read-only token. If the hub itself stops
answering, the sign falls back to checking each Pi directly over the network. That way a dead hub can’t
make every collector look healthy. Between alerts it rotates through the latest readings (water and air
temperature, humidity), so it earns its shelf space.
This matters most for the failure people don’t think about. When a sensor box dies, the tank is fine, but
you’ve stopped watching it. Without the sign, you find out days later from a gap in a graph. With it, you
find out the next time you walk past.
All well: water temperature over its one-hour trend, every collector green.
Press C for a Road Rash race against your collectors. Each one you pass gets a pit-board card with its
uptime and CPU temperature. (These two screens were put up with sample values for the photos.)
Setup, buttons and the styles it can show (including a Road Rash race against your collectors) are in
sign/README.md. Which collectors and readings it shows is one small config.json.
What you need
Part
For
Roughly
Raspberry Pi 5 (4 GB or more) or any 64-bit Linux computer
The hub
You may already have one
Any Raspberry Pi (3B+ or newer, or a Zero 2 W)
Each collector
$15–60
DS18B20 waterproof probe + 4.7 kΩ resistor
Water temperature
$3–10
DHT11 or DHT22, or an SHT40 / SHT41 / SHT45 breakout (more accurate, I2C)
Air temperature and humidity
$2–15
Jumper wires, a reliable power supply per Pi
Pimoroni Galactic Unicorn (Pico 2 W version)
The status sign (optional)
Pimoroni Unicorn HAT Mini on any Pi
A small display (optional)
One Pi can be both the hub and a collector. No hardware yet? The test lab runs a complete
install on one computer with synthetic sensors.
Quick start
0. Install Docker on each Pi
Use 64-bit Raspberry Pi OS (Bookworm or newer). Then:
curl -fsSL https://get.docker.com | sh
sudo usermod -aG docker $USER # then log out and back in
That’s Docker’s official convenience script. To install by hand instead, follow
Docker’s Debian instructions. The collector wizard offers to run
the script for you if Docker is missing.
1. The hub
git clone https://github.com/MT3chn1k/tankwatch.git
cd tankwatch/hub
./setup.sh
setup.sh creates random passwords and tokens in hub/.env, starts InfluxDB, Grafana and the discovery beacon,
checks other devices can reach them, and prints two join codes: one for collectors, one for displays.
Open the dashboards at http://<hub-ip>:3000 and the admin page at http://<hub-ip>:8088, with the users and
passwords it printed.
2. A collector (each sensor Pi)
git clone https://github.com/MT3chn1k/tankwatch.git
cd tankwatch/node
./setup.sh
Paste the collector join code when it asks. The admin page’s Add a sensor Pi section shows the code and
these commands, then tells you when the new Pi first reports. The wizard finds the hub, detects your DS18B20 probes, asks about
a DHT sensor and where each sensor is, tests every sensor once, and starts the collector.
No sensors wired yet? Add type: synthetic to tankwatch.yaml for realistic made-up readings.
A sensor that isn’t wired or answering doesn’t stop the others. The log says “could not start” and what to
check, and the collector retries it every 5 minutes.
Re-run ./setup.sh any time (a new probe, a moved sensor). It keeps your hub settings and offers your
previous answers as defaults.
A small read-only service for an Android home-screen widget, off unless you turn it on
(./setup.sh widget). Pair each phone by scanning a QR code on the admin page. See
docs/phone-widget.md, including how to see your tanks from away from home safely.
4. Keep it running
hub/backup.sh backs up every reading and dashboard, and hub/restore.sh puts them back. Backups,
upgrades, security and troubleshooting are in docs/operating-the-hub.md.
3.3 V, GND, SDA → GPIO2 (pin 3), SCL → GPIO3 (pin 5). Switch I2C on: sudo raspi-config nonint do_i2c 0, then reboot. Needs no extra Python packages
node_health
The Pi itself
none
CPU temp, undervolt/throttle, voltages, load, memory, disk
synthetic
Realistic made-up data: a tank, a room, a plant, a feeder
none
For demos and the test lab
mock
Simple fake data
none
For testing
Planned: pH and conductivity/TDS (Atlas Scientific EZO), soil moisture sensors for plants, distance sensors for
feeder and reservoir levels, water-leak detection. (The dashboards already chart soil moisture and levels: any
reading named ..._pct appears in the “Plants, feeders and levels” panel.) Adding one: docs/adding-a-sensor.md.
To build your own panels and alerts, see docs/data-model.md for what’s stored and example
queries.
Project status
TankWatch grew out of a working home setup: Raspberry Pi collectors and a Pi 5 hub built to watch three
aquariums, with the status sign on a shelf. The packaged version here is new. What’s been tested so far:
Part
Tested on
Hub setup, dashboards, backup and restore
Docker on a PC, from a fresh clone
Join codes, discovery, a collector finding a moved hub
The test lab: 37 of 37 checks pass (Docker 29 on RHEL 10, SELinux enforcing)
Collector setup wizard
A Debian container on the lab network, with fake DS18B20 probes; re-runs keep the config unchanged
Collector agent in Docker
Docker on a PC, with the synthetic, mock and node_health sensors
Unicorn HAT Mini display
Its web version in the test lab. The real HAT: next, on a Raspberry Pi 4
ds18b20 and node_health sensor code
A Raspberry Pi 3B+ with a real probe
dht in the collector container
A Raspberry Pi 3B+ with a real DHT11, fully locked down
sht4x
A Raspberry Pi 3B+ with a real SHT41, read side by side with an existing logger on the same sensor
dht on a Raspberry Pi 5
Not yet tested. The collector image now includes lgpio, which the Pi 5 needs; please report how it goes
Status sign
This version: its screens and shows on a PC simulator against a real hub. The original, home-specific version it came from runs the real sign every day
Admin page
Against a real InfluxDB with sample collectors (healthy, amber, silent, new), in Chrome. The home setup has run its own version of it for weeks
Hub on a Raspberry Pi 5 in Docker
Not yet: the home hub runs the same InfluxDB and Grafana without Docker
Phone widget service (add-on)
The test lab (19 of its checks): only paired phones answered, statuses agree with the admin page, pairing and revoking from the admin page, cross-site requests refused, management port not published. Also against sample readings for every case (healthy, hot, cold, stale, warning, silent) and the wrong-token lockout. The pairing QR code decodes to the exact link. The Android app: next
If you try a combination that isn’t in this list, please open an issue with what worked and what didn’t.
Roadmap
Containerized hub and sensor node, plug-in sensors, store-and-forward, node health
Status sign (Pimoroni Galactic Unicorn): green / amber / red per collector, red when one goes silent
Join codes, hub discovery and a collector setup wizard
Test lab: a whole install in Docker with synthetic sensors and virtual displays
Unicorn HAT Mini display (tested in its web version)
Admin page on the hub: collector status, adding a sensor Pi, status sign config builder
Phone widget (optional add-on): hub service and pairing by QR code on the admin page done; next,
healthy ranges per location, and the Android app
Alerts (Grafana alerting to email / phone) with sensible defaults per sensor
pH, TDS, soil moisture, level sensors
Network traffic mapping per node (NetFlow)
Automated nightly backups of every node and the hub, with monthly archives
The hub proves its identity to collectors (closes the hub-impersonation gap in SECURITY.md)
Integrations: smart lighting, wearables
Security
TankWatch is for a trusted home network: traffic is plain HTTP, and the hub must never be opened to the internet.
Read SECURITY.md for the trust model and how to report a problem privately.
评论