Pi software: bayforge-monitor and bayforge-fan
What it is
Two small, free programs for the Raspberry Pis in your rack, from the same signed apt repo.
- bayforge-monitor shows every Pi in the rack on one dashboard: CPU, RAM, temperature, disks, network, undervoltage and throttling, failed units, pending updates and reboots, and the fans. One Pi, the hub, watches the others and your services, and can send alerts to your phone. It is for anyone with a few Pis, in a Bayforge rack or not.
- bayforge-fan runs the rack's fans from the Pi's CPU temperature. Today that means a PWM fan on GPIO18 of a Pi 3, 4 or Zero 2 (one transistor, wiring below), or a Pi 5's own fan header. The Bayforge fan shield, with four fans each read and set on their own, is coming; the parts of this page marked fan shield are for it.
Each is one Python 3 file with no other dependencies, plus a config file and a systemd unit. They need Raspberry Pi OS Bullseye or newer.
Everything runs on your own Pis. The dashboard loads no fonts or scripts from elsewhere, and neither program checks for updates of its own (apt does that). Only the hub connects to anything: the Pis in the rack, the services you list under checks, and an ntfy server if you set one. ntfy is off by default, and it is the only connection that can leave your network. bayforge-fan runs with no network access at all.
Quick install
On every Pi you want on the dashboard, add the repo and install the monitor:
sudo install -d -m 0755 /etc/apt/keyrings
sudo curl -fsSLo /etc/apt/keyrings/bayforge.gpg https://bayforge.app/apt/bayforge.gpg
sudo curl -fsSLo /etc/apt/sources.list.d/bayforge.sources https://bayforge.app/apt/bayforge.sources
sudo apt update && sudo apt install bayforge-monitorIt starts at once: open http://<pi>.local:8780, for example http://pi1.local:8780. Then pick one Pi as the hub and give the others its token.
On a Pi that drives fans, also:
sudo apt install bayforge-fanand follow Setup before you reboot.
The repo is signed with the key 44A8 3547 E213 ED4E 86B8 9C85 D3A1 824F A6D5 6E22 (ed25519, “Bayforge apt signing”). To compare it with the one you downloaded: gpg --show-keys /etc/apt/keyrings/bayforge.gpg. The sources file trusts that key for this repo only (Signed-By:).
Which Pi needs which package:
- bayforge-monitor: every Pi you want on the dashboard.
- bayforge-fan: only a Pi that drives fans: a Pi with a GPIO PWM fan, a Pi 5 using its fan header, or the Pi wired to a fan shield (the hub, for the fan map). bayforge-monitor doesn't pull it in, so install it there. Without it the monitor shows no fan reading and the fan map does nothing.
bayforge-monitor
Every Pi runs the same package. The one with hub = yes finds the others, tracks when each is up or down, watches your services and sends the alerts; that is the one you open. It also sets bayforge-fan's curve.
Token
Reading is open on your network; changing a fan curve needs the token. Each Pi makes its own on install.
sudo bayforge-monitor token # print it; the dashboard asks for it the first time you saveEvery Pi in the rack must have the hub's token. It is how a Pi proves it belongs to your rack:
sudo bayforge-monitor token VALUE # on each peer, with the hub's token (32 to 512 hex characters)The right token always works. A wrong one less than a second after another wrong one from the same address gets 429. With private = yes, reading needs the token too.
The hub
On one Pi, set this in /etc/bayforge-monitor.conf, then run sudo systemctl restart bayforge-monitor:
hub = yes
With the default peers = auto, the hub looks for the rest of the rack every 5 minutes:
- on the LAN through avahi: each Pi announces
_bayforge._tcpon port 8780 (/etc/avahi/services/bayforge-monitor.service, which the package installs). The hub needsavahi-browse, from avahi-utils, which apt installs with the monitor unless you turned off recommended packages; thensudo apt install avahi-utils. - on the tailnet through
tailscale status: every online peer of this Pi.
Add any it can't find by name: peers = auto pi9.example pi3.local:8781. Leave out auto to use only the ones you list.
One Pi is one card, however many ways the hub finds it. Each Pi has an id (see /api/self in the API), and the hub groups the names it answers at by it: one card, or one Ignored row, with its other names as “also at”. The hub polls a Pi at one name, the LAN one first (192.168.x, 10.x, 172.16–31.x, 169.254.x, .local), then its tailnet one (100.64.0.0/10, .ts.net), then any other. It stays on that name while it answers; when it doesn't, the hub tries the next in the same round, so a Pi goes down only when none of its names answers for two polls in a row. A Pi older than 0.2.4 has no id, so it is one card per name until you upgrade it. Two Pis cloned from one SD card share a machine-id, so one id, and show as one: on the copy, run sudo rm /etc/machine-id && sudo systemd-machine-id-setup && sudo reboot.
A Pi joins only after it proves it holds the token. The hub sends it a random challenge, and it answers with an HMAC of the challenge, the ip:port the hub reached and its id, keyed with the token, so a stranger can't pass on a real Pi's answer as its own. After that the hub signs each request that needs the token (reading a private Pi, saving a curve through ?host=) with it, over the request, the time and that ip:port. The token never travels between Pis, so a stranger announcing _bayforge._tcp gets nothing it can use. The signature is good for a minute, so the Pis' clocks must agree to within one (NTP, which Pi OS has on by default). A Pi with a different token, or none, is listed under Ignored with the reason. ?host= reaches only Pis that have proved themselves, so it can't be pointed anywhere else.
The hub polls every Pi every 30 s. A Pi is down after 2 missed polls in a row (60 s) and up again on its first answer. Each change goes into /var/lib/bayforge-monitor/events.jsonl, which keeps 30 days, so the availability figures and the event list survive a restart. A Pi with private = yes shows only as up or down, unless the hub has private = yes too.
Service checks
The hub can watch other things in the rack too, with the same 2-poll rule, the same events and the same alerts:
checks = tcp://nas.local:445 http://pihole.local/admin/ https://proxmox.local:8006/
A tcp:// check connects. An http:// or https:// check sends one GET, follows no redirects, and passes on any status below 400. https:// doesn't check the certificate, because homelab services are often self-signed. No check is ever sent the token.
Names. Put [Name] right before a check to name it on the dashboard, in the events and in the alerts: checks = [My NAS]tcp://nas.local:445 [Audiobookshelf]http://abs.local:13378/. A name is 1 to 40 characters, spaces allowed, with no brackets, no # and no control or invisible characters; anything else is refused (a 400 from Settings, a start-up error from the file). Without a name, an http(s) check takes its page's <title> (from the first 16 KB of a 2xx answer, with entities decoded, whitespace collapsed and cut to 40), unless it is empty or just the host name. The hub keeps that in memory, picks up a change at the next answer, and falls back to the URL until it has one. A tcp check is named host:port. A title is cleaned before use: control characters (C0, DEL, C1) and bidi controls are dropped, so a page can't break a log line, an ntfy header or the dashboard's order. The dashboard shows the name with the URL beside it.
Settings takes up to 32 checks, each at most 200 characters.
Alerts
The hub can push alerts to your phone through ntfy. Install the ntfy app, subscribe to a topic, and set it on the hub:
ntfy = https://ntfy.sh/your-long-random-topic
ntfy_token = # only for a protected topic on your own server
Anyone who knows an ntfy.sh topic name can read it. Use a long random one (openssl rand -hex 16), or run your own ntfy server on the tailnet.
ntfy is off until you set it, and it is the only connection the monitor ever makes outside your rack. An https:// topic is sent with its certificate checked. The dashboard's Send test notification button checks the setup.
You get one message when something starts, and nothing more until it ends and starts again. The hub watches its own readings as well as its peers'.
- a Pi or a check goes down, or comes back up;
- a Pi's CPU is over
alert_temp(80 °C) for 2 polls; it ends 5 °C below that; - undervoltage, right now;
- a disk over
alert_disk(90 %) full; it ends 2 % below that; - a fan stalls: 0 RPM while its duty is above 0. This only counts for a fan that has read RPM before, so an empty fan header stays quiet;
- more security updates are pending than when it last told you, at most once a day for each Pi.
On your phone
Over Tailscale, on the hub:
sudo tailscale serve --bg 8780 # https://<hub>.<tailnet>.ts.net, on your tailnet onlyNever use tailscale funnel: that puts the dashboard on the public internet.
Behind serve you can set bind = 127.0.0.1. In Safari or Chrome, use Share → Add to Home Screen. It then opens full screen, like an app.
Warnings
Each Pi's card shows its warnings as pills: undervoltage and throttling, failed units, pending and security updates, a reboot needed, stale apt lists and fan trouble. On a Pi's page they are in Status, and the ones that need explaining are buttons. Each opens a short note under it; the button, Esc or Close shuts it again, and a tap does the same on the rack screen.
- Updates list each package: the version now and the one pending, whether it is a security update, the repo, and how long ago this Pi first saw it pending, with how old the apt lists are. “Seen” is when the hourly check first noticed that version, so it can be up to an hour late, or more if
apt updatehasn't run. Each Pi keeps those times in/var/lib/bayforge-monitor/updates-seen.json({"package version": unix time}, only the ones still pending, written atomically). A Pi sends its first 200 packages, the security ones first; the hub checks each field and drops anything that doesn't fit. Nothing is ever installed, and the monitor never runsapt updateitself: the note suggestssudo apt update && sudo apt full-upgrade. - Throttling says what the flag means, whether it is happening now or happened since boot (a since-boot flag stays until the Pi reboots), the likely causes and what helps: the supply and cable for undervoltage, and cooling (the fan curve, a fan assigned to the Pi, the bay's airflow, dust) for the temperature ones. The thresholds differ by model, and the notes say so. The dashboard doesn't know when a flag first appeared, because the 24 h history doesn't keep throttle readings.
Rack screen
A small screen on the hub can show the rack full time (the #kiosk view, 480×320 to 1280×800):
sudo apt install cage chromium
sudo systemctl enable --now bayforge-monitor-kioskOn Bullseye the browser package is chromium-browser. The unit takes over tty1 and always opens port 8780. It hasn't been tried on a real screen yet; if the screen stays black, see journalctl -u bayforge-monitor-kiosk.
Settings
The settings live in /etc/bayforge-monitor.conf; after a change, run sudo systemctl restart bayforge-monitor.
Or use Settings at the top of the dashboard (it needs the token, and isn't on the rack screen). It saves to /var/lib/bayforge-monitor/settings.conf (0600), and each key there wins over the same key in /etc/bayforge-monitor.conf. The page shows where each value comes from, and Reset to file drops that key from the override. Saving restarts the monitor (the 24 h graphs start again), and the log says at start-up which keys are overridden. It only changes the Pi whose dashboard you opened, never a peer's through ?host=. A bad hand-edit of settings.conf is moved aside to settings.conf.bad and the monitor starts on /etc alone.
port, bind and private are set only in /etc/bayforge-monitor.conf: a wrong value there would lock you out of the page you'd need to fix it.
- port: default 8780. If you change it, change it in
/etc/avahi/services/bayforge-monitor.servicetoo. The rack screen always opens 8780. - bind: default
0.0.0.0(every IPv4 interface). - private:
yesmakes reading need the token too. - hub:
yeson one Pi only. The settings below only matter there. - peers:
auto(the default), hostnames with an optional:port, or both. - checks:
tcp://host:port,http://host[:port]/pathandhttps://host[:port]/path, space-separated, each with an optional[Name]right before it (see Service checks). - ntfy, ntfy_token: the topic URL and an optional access token. Empty: no alerts.
- alert_temp, alert_disk: default 80 (°C) and 90 (%). Settings takes whole numbers, 40 to 100 °C and 50 to 99 %; the file takes 20 to 120 and 1 to 100.
- fan_map: see The fan map.
autoby default. - pi_colors: each Pi's colour on the fan curve charts,
name:#rrggbbby spaces, up to 16 (pi1:#e0a030 pi2:#2a9d8f). Settings has a colour picker per Pi. A Pi left out gets one of eight colours by its place among the names, so a Pi joining can shift the others'; save them to pin them. A bad value from Settings gets a 400; a bad hand-edit is logged and the defaults are used.
The fan curve isn't set here. The dashboard writes it to /var/lib/bayforge-monitor/fan-curve, which bayforge-fan reads in place of its own curve =. “Use config curve” deletes that file. On a Pi 5 whose fans are on the fan header, the kernel owns the curve, so the dashboard only shows it. On the hub, the chart marks every Pi's CPU temperature in that Pi's colour, with its name and the fans of the map that follow it (“pi2 · fan 2”); a Pi that is down or has no reading is left off. The name is always there, so the colour is never the only cue. Other Pis mark only their own CPU. With a fan shield on the hub, the overview shows the same chart, read-only.
Fan shield: when bayforge-fan ships newer shield firmware than the shield runs, the Pi's card and Fans panel say so in one line: “Shield firmware 1, 2 available: sudo bayforge-fan update”. Nothing flashes on its own: you run that on the Pi.
The fan map (fan shield)
On the hub, each fan of its own fan shield can follow other Pis' temperatures. fan_map = auto (the default, also when the key is left out) works out which fan cools which Pi; see Auto-assign. Or set it by hand: fan_map = 1:self 2:pi2 3:pi2,pi3 (in Settings or the conf). A manual map always wins over auto, and an explicit empty fan_map = turns the map off. Fans are 1 to 4, each at most once, with up to 8 names: self (the hub) or hostnames as the dashboard shows them, case aside. After each poll round (every 30 s, and never before the first), each fan takes the hottest CPU of the Pis it follows and runs it through the fan curve the dashboard set, else bayforge-fan.conf's, with bayforge-fan's own maths. A fan left out follows self.
Fail-safe: a fan whose Pi is down, isn't in the rack or has no temperature reading runs at 100 %, and the Fans panel says why (“pi2 is down: 100 %”). That raises no alert of its own: the down alert covers it.
The hub writes the four duties to /var/lib/bayforge-monitor/fan-targets (60 100 100 45, one line, 0644, atomically). bayforge-fan runs the shield on it while it is under 90 s old; missing, stale or garbled, it goes back to its own curve, so a stopped monitor can't hold the fans low. An empty map deletes the file at once; so does a hub without bayforge-fan or a curve, and the panel gives the reason. With hub = no the map is ignored and nothing is written (a file left from when it was the hub goes stale in 90 s).
Per-fan duty needs shield firmware 2. On firmware 1 all four fans share one duty: the firmware line above asks for sudo bayforge-fan update, or, with a bayforge-fan too old to ship firmware 2, the panel asks to upgrade it first (sudo apt update && sudo apt upgrade). If the map is set and bayforge-fan's status still doesn't say curve=targets a minute after the first write, the panel asks for bayforge-fan 0.4.0 or later.
Limitation: the map drives only a shield wired to the hub. A shield on another Pi would need the hub to push signed targets to it.
Auto-assign (fan shield)
With fan_map = auto and a fan shield on the hub, the hub finds out which fan cools which Pi by running each fan flat out in turn. It runs once by itself, when the shield answers on firmware 2, at least one other Pi is up with a temperature and there is no saved result. It runs again only from Re-run auto-assign in Settings. On firmware 1 all four fans share one duty, so there is nothing to tell apart: the panel says so and asks for sudo bayforge-fan update.
Until a run finishes, every fan follows every Pi (the hottest wins, and a Pi down means 100 %). After a run, the result is used exactly like the same map by hand.
The run takes about 28 minutes, and the overview and Settings show its phase, which fan and the time left:
- All four fans at the baseline for 3 min.
- Fan 1 at 100 % for 4 min.
- All at the baseline for 3 min.
- Fan 2, and so on to fan 4.
The baseline is the fan curve at the hottest Pi, but never under 50 %. If the curve takes it over 50 %, the result says so, since the fan at 100 % then stands out less.
Each Pi's reading is the mean of the last two polls of a step. A fan's drop for a Pi is the settle before it minus its own step. The fan goes to the Pi whose drop is furthest over the average drop, so a Pi that cools whatever runs doesn't take every fan. If that Pi cooled by under 1 °C, the fan follows self. It is one reading per fan and greedy, so a load change mid-run skews it, and two fans can land on one Pi. Re-run it if the result looks wrong, or set the map by hand.
The run stops, logs an event and runs all four fans at 100 % for 60 s if:
- a Pi reaches the curve's first 100 % point or
alert_temp; - a Pi taking part goes down or loses its reading;
- a poll is missed (a stall);
- bayforge-fan isn't on the targets (
curve=targets) 90 s in; - the monitor restarts mid-run.
It doesn't retry by itself. The fans move only through fan-targets, like a map by hand. The result is kept in /var/lib/bayforge-monitor/fan-auto.json, written atomically. A bad file is logged and ignored. A re-run keeps the old result until the new one finishes.
API
Every response is JSON. Writes need Authorization: Bearer <token>, and so does everything with private = yes.
GET /- the dashboard
GET /api/self- this Pi's latest reading, with
instance(this run's; new at each restart) andid(this Pi's, for good).updates.listis up to 200{name, from, to, repo, security, seen_age}, security first;fromisnullfor a new package,seen_ageis seconds since it was first seen pending. GET /api/self/history- the last 24 h, one point a minute:
{t[], cpu[], temp[], mem[], rx[], tx[], duty[]}. In memory: a restart clears it. GET /api/rack{hub, now, ntfy, hosts[], checks[], ignored[]}from the hub's last poll;nowis the hub's clock, which the dashboard counts “down 12 min” from.hostsis this Pi, then the peers, each withstate(up,downornullbefore the first answer),since,uptime_pct: {24h, 7d}andbar(the last 24 h as[t, state]changes); a peer also hasat(the name the hub polls it at) andalso(its other names); a down peer is{host, peer, error, at, also, ...}.checksare{target, name, title, state, since, uptime_pct, bar, detail}(name: the[Name], the page title, or the URL or host:port;title: the page's cleaned<title>, ornull);ignoredare{host, why, also}.ntfyis only true or false. The top level also hascolors, the savedpi_colorsas{name: "#rrggbb"}.
On the hub, its own entry hasfan_auto:{on, state, phase, fan, started, left, total, result, why, note, pis, blocked}.stateisidle,running,doneoraborted.resultis four{fan, pi, drop}ornull.blockedis why a run can't start now, ornull. It also hasfan_map:nullwith no map, else{plan, why, written}:planis four{fan, follows[], temp, duty, reason}(reasonset when it is forced to 100 %), ornullwithwhywhen nothing is written;writtenis when it first wrote fan-targets. Eachfanhasduty(the highest),duties(the four, on shield firmware 2, elsenull),fw,fw_bundled(the firmware bayforge-fan ships, ornull) andrpm[].GET /api/events?days=N- the hub's up/down/alert log, oldest first:
[{t, host, event, detail, key}], N from 1 to 30 (default 30) POST /api/fan/auto- on the hub: a new auto-assign run from the next poll,
202 {ok, detail}, or 409 with the reason it can't run (seefan_auto.blocked) POST /api/ntfy/test- sends a test message:
{ok, detail}, or 409 whenntfyisn't set GET /api/fan/curve{controllable, why, source, curve, conf_curve}PUT /api/fan/curve{"curve": "45:30 60:60 70:100"}, checked by bayforge-fan's own rules, and the last point must be 100 % at 85 °C or lower, so the fans are flat out before the Pi throttlesDELETE /api/fan/curve- back to the curve in bayforge-fan.conf
GET /api/settings- always needs the token:
{host, instance, conf, override, file_only, settings: {key: {value, source}}},sourcebeingfileordashboard.ntfy_token's value is only true or false. PUT /api/settings{"hub": "yes", "checks": "tcp://nas:445"}: a string sets a key,nullgoes back to the file's value, a key left out stays (sontfy_tokenleft out keeps it,""clears it). 400 names the field. Then the monitor restarts.
On the hub, ?host=<peer> sends any of the /api/self and /api/fan/curve requests on to that peer (its peer in /api/rack), signed when it is a write or the rack is private. Only a peer that is up and has proved it holds the token can be reached this way.
GET /api/self?challenge=<32 hex>&v=2 adds proof, even to a 401: HMAC-SHA256, keyed with the token, of "<challenge> <ip:port the request reached> <id>" (without v=2, as a hub older than 0.2.4 asks, "<challenge> <ip:port>"). The 401 carries id and instance too.
id is 32 hex, the same at every address and across restarts: HMAC-SHA256, keyed with /etc/machine-id, of bayforge-monitor, cut to 32 hex, the way systemd makes an app-specific machine id. It tells nothing about the machine-id itself, which never leaves the Pi. Without a machine-id it is a random one kept in /var/lib/bayforge-monitor/id. The hub trusts a Pi's id only once the proof covers it; an ignored Pi's id is unproven, and only groups its names into one row.
In place of the Bearer token, the hub sends X-Bayforge-Sig: <unix time>.<32 hex nonce>.<HMAC-SHA256, keyed with the token, of method, path, time, nonce, ip:port the request reached and the SHA-256 hex of the body, one per line>. A peer takes it within 60 s of its own clock, and each nonce once.
Errors: 400 (a bad value; the message names the field), 401 (token needed or wrong), 429 (a wrong token again within a second), 409 (this fan's curve can't be set, or no ntfy), 503 (bayforge-fan isn't installed or its config can't be read, or this Pi has no token), 502 (the peer is down, rejected the hub, or ntfy didn't answer), 404 (?host= isn't a proven peer). Also 405 (a method the path doesn't take), 411, 413 and 415 (a body with no length, too big, or not application/json), and 500 (the settings or curve file couldn't be written).
bayforge-fan
Runs the rack's fans from the Pi's CPU temperature. It has two backends, set with backend = in /etc/bayforge-fan.conf:
backend = gpio: what works today, with no extra board. The fans' PWM wire is driven at 25 kHz.- Pi 3/4/Zero 2: hardware PWM on GPIO18, through one transistor (see the wiring).
- Pi 5: the fans go on the Pi's own fan header and the kernel runs them. The daemon does nothing there.
backend = shield(the default in the config file), for the Bayforge fan shield, which is coming. It talks to the shield on the UART at 115200 8N1. Every 5 s it sends a duty from your curve, or one per fan from bayforge-monitor's targets file, and the shield holds them for 30 s. If the Pi stops, the shield goes back to its own curve, which runs on the intake temperature. When the daemon stops it sendsauto.- It listens first: nothing goes out on the UART until a shield status line arrives (one comes every second), and it stops sending when the shield has been quiet for 5 s. A Pi with nothing on the UART therefore gets no writes, and with no serial port at all the daemon idles and retries every 30 s.
- One consequence: if the shield's TX → Pi wire is broken, the shield never gets a command. It stays on its own NTC curve, which is safe, and
bayforge-fan statussaysshield silent.
Which Pi needs it
- bayforge-fan goes only on a Pi that drives fans: a Pi with a GPIO PWM fan (
backend = gpio), a Pi 5 using its fan header, or the Pi wired to a fan shield. - bayforge-monitor goes on every Pi you want on the dashboard.
- With the hub's fan map, the hub sets each shield fan from its bay's temperature, so the other Pis don't need bayforge-fan.
Install
From the apt repo (skip the first three lines if the Pi already has bayforge-monitor):
sudo install -d -m 0755 /etc/apt/keyrings
sudo curl -fsSLo /etc/apt/keyrings/bayforge.gpg https://bayforge.app/apt/bayforge.gpg
sudo curl -fsSLo /etc/apt/sources.list.d/bayforge.sources https://bayforge.app/apt/bayforge.sources
sudo apt update && sudo apt install bayforge-fanThis needs Raspberry Pi OS Bullseye or newer, on any Pi. A fresh install enables the service but doesn't start it: run setup, then reboot, and it starts with the Pi.
Setup
For the gpio backend, first set backend = gpio in /etc/bayforge-fan.conf (for example with sudo nano /etc/bayforge-fan.conf). Do this before setup: with the default shield, setup turns on the UART and takes the serial console out of cmdline.txt instead. Then run:
sudo bayforge-fan setup # prints what it will change in config.txt / cmdline.txt, asks, keeps *.bayforge-bak copies
sudo rebootWhat setup does (in /boot/firmware/, or /boot/ on older systems; --yes skips the question):
| Backend | Pi 3/4/Zero 2 | Pi 5 |
|---|---|---|
| gpio | dtoverlay=pwm,pin=18,func=2 | dtparam=cooling_fan=on |
| shield | enable_uart=1; takes console=serial0,… out of cmdline.txt | dtparam=uart0=on (GPIO14/15 is /dev/ttyAMA0); takes the console out of cmdline.txt |
On a Pi 3, the analogue audio jack uses the same PWM block. Don't use the jack together with backend = gpio.
Fan shield: on a Pi 3 or Zero 2, Bluetooth uses the full UART, so the shield gets the mini UART. That is fine at 115200.
Check it
bayforge-fan status
sudo bayforge-fan test # steps the fans 0 to 100 % in 10 % steps of 5 s, then a verdicttest pauses the daemon while it runs (that is what it needs sudo for) and starts it again after. Ctrl-C stops it early.
- gpio, Pi 3/4/Zero 2: the backend reads no RPM, so watch or listen to the fans speed up. At the end it leaves the pin low, which runs the fans at full speed until the daemon takes over again.
- gpio, Pi 5: the kernel drives the fan header, so there is nothing to test.
- Fan shield: after each step it prints the shield's status line, ends with
auto, and gives a verdict:ok: rpm rose;shield silent;shield garbled;shield ignores the Pi;FANn did not speed up; orno fan reports any rpm.
Fan shield: an example of bayforge-fan status:
backend=shield device=/dev/serial0 cpu=52.5 sent=30,30,80,100 curve=targets ok
shield: t=27.4 duty=30,30,80,100 mode=pi rpm=1230,1200,2400,0 fw=2
(2s ago)
fan duty rpm
1 30 % 1230
2 30 % 1200
3 80 % 2400
4 100 % 0
On fw=1 the shield has one duty for all four fans: the table shows it on every row and says sudo bayforge-fan update brings per-fan control.
mode=pi means the shield is following the Pi. Some cases to know about:
- If the intake air is at 45 °C or above, or the shield's sensor has failed, the shield ignores the Pi. It still reports
mode=pi, but its duty is its own. - If the output says “shield silent”, the Pi can't hear the shield, and so sends it nothing (
sent=-). Most often TX and RX are swapped: the shield's TX must go to the Pi's RXD (GPIO15, pin 10) and its RX to the Pi's TXD (GPIO14, pin 8), crossed over. Swap those two jumpers first, then check GND and the shield's USB-C power. - If the output says “ignores the Pi”, the shield can't hear the Pi. Check the Pi's TXD (GPIO14, pin 8) → the shield's RX, crossed, not RX to RX.
If none of that helps, run journalctl -u bayforge-fan.
Settings
The settings live in /etc/bayforge-fan.conf. After changing them, run sudo systemctl restart bayforge-fan.
- backend:
gpioorshield(see above). Runsudo bayforge-fan setupagain after changing it. - curve:
curve = 45:30 60:60 70:100maps CPU °C to fan %. Between points it is linear, and past the ends it stays flat. If the CPU temperature can't be read, the fans run at 100 %. - interval: how often, in seconds, the duty is resent: 1 to 20. Default 5.
- device: the serial port for the shield.
auto(the default) is/dev/ttyAMA0on a Pi 5 and/dev/serial0on the others. - curve_file: a file that overrides
curvewhile it exists, default/var/lib/bayforge-monitor/fan-curve. It holds one line in the same syntax ascurve; bayforge-monitor's dashboard writes it. The daemon re-reads it when it changes, so it needs no restart. If it is bad or deleted,curveapplies again.bayforge-fan statusshowscurve=fileorcurve=conf. Leave it empty to turn it off. - targets_file: per-fan duties from bayforge-monitor, default
/var/lib/bayforge-monitor/fan-targets. See per-fan control. Leave it empty to turn it off.
On a Pi 5 with the gpio backend, the curve is the kernel's. Set it in config.txt with dtparam=fan_temp0=50000,fan_temp0_speed=75, and so on up to fan_temp3.
gpio wiring (no shield)
Noctua's 5 V PWM fans have their own pull-up on the PWM wire, to 3.3 V or 5 V depending on the model. Noctua's numbers:
- the pull-up limits a short-circuit current to 5 mA or less;
- low is 0.8 V or less;
- the line can reach 5.25 V;
- the PWM frequency is 25 kHz.
That pull-up rules out wiring the PWM wire to the GPIO directly:
- GPIO driving high: each fan pushes up to (5 − 3.3) V / 1.05 kΩ ≈ 1.6 mA into the Pi's 3.3 V rail.
- GPIO as an input (booting, or the Pi powered off while the fan supply is on): the line rises to about 3.8 V. Up to about 1 mA per fan flows through the pin's protection diode, and with the Pi off that current back-powers it. The GPIO pins are not 5 V tolerant.
A series resistor doesn't fix this either. To still read below 0.8 V against the fan's pull-up, it would have to be under about 200 Ω.
Sink the line with a transistor instead. The fan only needs the line pulled low; its own pull-up makes the high.
GPIO18 (pin 12) ──1 kΩ──┬── B 2N3904 / BC547 (NPN)
100 kΩ C ── every fan's PWM wire (blue)
GND (pin 14) ───────────┴── E ── GND, shared with the fans' 5 V supply
- Base current: (3.3 − 0.7) V / 1 kΩ ≈ 2.6 mA. The worst-case collector current is 5 mA per fan, so 20 mA for 4 fans and 40 mA for 8. That keeps Vce(sat) at 0.3 V or less, under the 0.8 V low threshold.
- The 100 kΩ resistor holds the transistor off while GPIO18 floats. During boot, and with the Pi off, the fans therefore run at full speed, and nothing flows into the Pi.
- Inversion: the stage inverts, so the daemon drives pin duty = 100 − fan duty. When the daemon stops, it leaves the pin low, which also gives full speed.
- Tach: the tach (green) wires stay unconnected. The gpio backend doesn't read RPM.
- Pi 5: use the 4-pin fan header instead of this circuit. It is built for 5 V PWM fans, like the official Active Cooler. A Noctua fan needs an adapter cable to the header's 1 mm JST-SH plug.
With Noctua's USB cable and PC fan splitters
This setup uses three things:
- an NF-A4x10 5V PWM (rated 4–5.5 V, 0.07 A max);
- Noctua's NA-AC7 USB power cable, which provides 5 V and GND and leaves PWM unconnected;
- passive 4-pin PWM splitters, such as Cable Matters 104040: one input and two outputs, with tach on the first output only.
The 4-pin fan pinout:
| Pin | Signal | Noctua wire colour |
|---|---|---|
| 1 | GND | black |
| 2 | +5 V | yellow |
| 3 | tach | green |
| 4 | PWM | blue |
Splitter wires are often all black. To find the pins, plug a fan into one output and see where its blue and black wires land; the same positions on the other output are PWM and GND. On a splitter output with no tach wire, pin 3 is the empty slot.
Chain (up to 2 fans plus the PWM tap, using both splitters from the 2-pack):
NA-AC7 (USB, ideally a Pi USB port) ─► splitter A in
splitter A out 1 ─► fan 1
splitter A out 2 ─► splitter B in
splitter B out 1 ─► fan 2
splitter B out 2 ─► tap: pin 4 (PWM) to the transistor's collector, pin 1 (GND) to the Pi's GND (pin 14)
How the tap works:
- The tap is two female Dupont jumpers pushed onto the pins of that spare output (2.54 mm pitch, the same as the GPIO header).
- The GND jumper is required. It joins the Pi's ground to the fans' ground, which the transistor needs. It matters most when the NA-AC7 is plugged into a charger rather than the Pi.
- Each extra fan adds at most 5 mA through the transistor. Five fans is 25 mA, which the 2.6 mA base current still saturates.
- The fans together draw 0.07 A each, well inside a Pi 4 USB port.
Tach: a splitter or hub passes PWM to every fan, but returns tach from only one fan (the first output here), or from none. The gpio backend reads no RPM at all, so with this setup nothing notices a stalled fan. For RPM per fan you need the fan shield, which has its own tach input for each of its four fans. If a tach line is ever read on a Pi GPIO, pull it up to 3.3 V, never 5 V. It is open collector.
Generic “1 to 5” 3/4-pin hubs: most of them take SATA power and feed the fans its 12 V rail. 12 V destroys these 5 V fans, whose maximum is 5.5 V. Never connect such a hub's SATA or Molex lead with 5 V fans.
A SATA-fed hub's fan lead usually doesn't carry power to the ports either. Before using one, check it with a meter:
- Continuity from the input's pin 2 to every output's pin 2 means it is passive. It is then usable at 5 V, like the splitters above.
- If an output's pin 2 connects only to the SATA lead, don't use the hub with these fans.
Parts beyond the fans, the NA-AC7 and the splitters:
- one NPN transistor, 2N3904 or BC547 (TO-92). The pinouts differ: with the flat face toward you and the legs down, a 2N3904 reads E-B-C and a BC547 reads C-B-E.
- one 1 kΩ resistor and one 100 kΩ resistor, ¼ W.
- either a mini breadboard and 4 female-to-male Dupont jumpers (GPIO18, Pi GND, fan GND, fan PWM), or 4 female Dupont jumpers with the three parts soldered inline under heatshrink.
Update the shield's firmware (fan shield)
sudo bayforge-fan update # flashes /usr/share/bayforge-fan/fanshield.bin, the firmware this package ships
sudo bayforge-fan update FILE.bin # or a fanshield.bin you built; --yes skips the questionIt pauses the daemon, sends the shield boot, writes and verifies the firmware through the CH32V003's factory bootloader over the same UART, and waits for a status line with the new fw=. The fans run at full meanwhile.
The updater passes its tests against a fake bootloader but hasn't been tried on a real shield yet.
apt upgrade and bayforge-fan status say when the shield's firmware is older than the one the package ships (Shield firmware 1, 2 available: sudo bayforge-fan update). Nothing flashes by itself: an upgrade can run unattended, so flashing stays manual.
- The shield needs firmware fw=1 or later, flashed once over SWIO with a WCH-LinkE. On older firmware
updatesays so and changes nothing. - If it fails after the erase, run it again within 60 s, while the shield still waits in its bootloader. After that the shield needs SWIO; its fans run at full until then.
Per-fan control (fan shield)
bayforge-monitor on the hub can tie each shield fan to a bay and set it from that bay's temperature. It writes targets_file (default /var/lib/bayforge-monitor/fan-targets) every 30 s: one line of four duties, 0 to 100, for fans 1–4, separated by single spaces, such as 30 30 80 100.
- The daemon re-reads the file every interval. It uses it only while it is fresh: exactly that form, and written 0 to 90 s ago (three of the monitor's polls).
bayforge-fan statusthen showscurve=targets. - If the file is missing, unreadable, malformed, older than 90 s or dated in the future, the daemon ignores it and runs the curve (
curve_file, elsecurve) for all four fans, as before. It logs each change once, not every interval. - Shield firmware fw=2 and later gets the four duties (
sent=30,30,80,100). When they are all equal it gets one duty, which means the same thing. - fw=1 has one duty for all four fans, so it gets the highest of the four (
sent=100): no fan runs slower than its bay asked for.sudo bayforge-fan updateflashes fw=2. Until the daemon has heard the shield's status line, it doesn't know the firmware; it sends nothing then anyway. - backend = gpio has one PWM wire for every fan, so it also uses the highest of the four.
- The shield's own safety still wins on every fan: at 45 °C intake or with no sensor, all four follow its curve; and 30 s after the last command, all four go back to it.
Updates and removal
Upgrade
sudo apt update && sudo apt upgradeBoth packages restart themselves on upgrade, and keep their settings. An edited /etc/bayforge-monitor.conf or /etc/bayforge-fan.conf is a config file to apt, so it asks before replacing it. Fan shield: if the new bayforge-fan ships newer shield firmware, it says so; run sudo bayforge-fan update when you are ready.
Remove
sudo apt remove bayforge-monitor bayforge-fan # stop and remove the programs, keep the settings
sudo apt purge bayforge-monitor bayforge-fan # also delete the settings and saved state- bayforge-monitor, remove: stops and disables the monitor and the rack screen, and deletes the fan curve, fan targets, auto-assign result and update times it wrote. It keeps
/etc/bayforge-monitor.conf, the token, the dashboard's settings, the event log and the Pi's id, so a reinstall picks up where it left off. It also keeps the avahi file, so the Pi still announces_bayforge._tcpon the LAN until you purge. - bayforge-monitor, purge: also deletes
/etc/bayforge-monitor.conf, the avahi file,/etc/bayforge-monitor/(the token) and/var/lib/bayforge-monitor/. Thebayforge-monitorsystem user stays;sudo deluser --system bayforge-monitorremoves it. - bayforge-fan, remove: stops and disables the daemon. A shield goes back to its own curve; on gpio the fans run at full speed. It keeps
/etc/bayforge-fan.conf. - bayforge-fan, purge: also deletes
/etc/bayforge-fan.confand/var/lib/bayforge-fan/. - Neither undoes what
bayforge-fan setupchanged in config.txt and cmdline.txt. To go back, copy the*.bayforge-bakfiles it left next to them over the originals, or take out the lines under# bayforge-fan setup, then reboot.
Questions or trouble: support@bayforge.app.