Five weeks of air in one room

For five weeks a small program on my desk machine listened to one Bluetooth CO₂ meter and wrote down what it heard, about once a minute, into SQLite. By the time we sat down to read it, the table held 50,933 rows.
I wanted charts. Before the charts, I wanted something duller: an honest answer to “how much of this is actually there?” This post is about that answer, and why it took two independent passes, a log archaeology session and one uncomfortable admission about what a row is.
It’s not about what the air was like. That part stays at home.
The writer, and what “once a minute” really means
The daemon is small. It listens for the meter’s Bluetooth advertisements, keeps the latest one in memory, and every 60 seconds a tick decides whether to write a row. The rule is the part that matters: a tick writes only if a fresh advertisement arrived since the last row. If nothing new came in, the tick writes nothing. So rows don’t land every 60 seconds. They jitter around it, and now and then there’s a 120-second step where one tick found nothing new.
That’s by design. A copied reading pretending to be new would be worse than a missing one. But it means “one row a minute” is a target, not a fact, and the first job was to measure the distance.
Counting the holes
We fixed a read bound first: every query stops at the same second. The writer keeps appending while you count, and without a bound, two people running the same query an hour apart get two different answers and both are right. With the bound, the numbers stay put.
Then the arithmetic. The observed span, at one row per 60 seconds, should have produced 51,902 rows. It produced 50,933. That’s 98.1%. Per day, across the 35 full days, coverage ran from 94.9% to 99.5%, with a median of 98.4%. The first and last days are partial and were prorated, not counted as failures.
98.1% sounds like “a few outages”. It isn’t. When we listed every gap longer than 180 seconds, three missed ticks in a row, there were only 8 of them, adding up to 65.1 minutes in total. About 969 rows are missing, and most of them aren’t in those gaps at all. They’re single skipped ticks, spread thinly across five weeks. The table of row-to-row intervals shows the shape: 20,066 steps between 66 and 180 seconds (a skipped tick, or just a late timestamp) against 8 steps longer than that.
So the series has two kinds of missing data, and they mean different things:
- Single skipped minutes, hundreds of them. That’s the design doing its job: no fresh advertisement, no row.
- Real holes, eight of them. Only one is longer than four minutes: 41.3 minutes on 3 October, when the daemon was stopped and started again. The log has the “stopped” line and the “serving” line and nothing between them. Why it was down is not recorded, and I’m not going to guess.
The other seven are all short. Five of them are 189 to 195 seconds long with no log line of any level inside them: three ticks in a row with no new advertisement. Whether the meter went quiet or the scanner missed it can’t be told from these logs, because advertisements themselves aren’t logged.
Restarts that didn’t leave a mark
The logs show 15 daemon starts in the period. Ten of them left no gap over 180 seconds at all: stop, start, carry on, within a second or two. Five sit inside or right after a gap. I like this number more than the 98.1%. It means a restart isn’t automatically a hole, and a hole isn’t automatically a restart. You have to look at both lists side by side.
We also grepped every log for Bluetooth errors: scan failed to start, scan didn’t stop cleanly, anything from the Bluetooth stack. Zero, across all of it. The holes aren’t radio failures, at least not ones the daemon could see.
And one hole sits outside the table entirely. The writer landed on 1 September. The first stored row is from 5 September. Four days are just missing, and no log from that period survives. That stays on the “unknown” list. The series starts on the 5th, and every number above uses the 5th.
Two passes, one answer
Every figure came out of plain SQL against the store, opened read-only. Then a second pass did the same work independently in Python: its own time-zone handling, its own sorting, the same rank rules. The per-day counts from both came out byte-identical, and so did the summary figures. We checked with a hash, not by eye.
The rank rules were chosen on purpose. Percentiles use nearest-rank: the value at a fixed position in the sorted list, never an average of two neighbours. That’s the same rule the daemon’s own dashboard uses. A p95 in a report and a p95 on the screen have to mean the same thing, or one of them is lying. Medians are the lower median, so a median is always a value the meter actually reported.
Day boundaries are local time, set explicitly for every query. Forget that once and the first and last hours of every day slide into the neighbouring day, and nothing in the output warns you.
The uncomfortable part: rows are not measurements
Here’s what nearly slipped past us. The meter doesn’t refresh all its numbers at the same rate. Temperature and humidity advertisements keep arriving, and each one makes a row “fresh” by the writer’s rule. CO₂, though, comes in flat steps that hold for 10 to 17 minutes. That fits a sensor that republishes CO₂ only every quarter or half hour, though we haven’t measured the cadence directly.
In one high stretch, 37 rows turned out to be roughly four distinct CO₂ measurements, each repeated many times.
That changes how to read every percentile in the series. Rows over-count CO₂ measurements, by a factor we don’t know exactly. “98.1% coverage” is true for rows. For CO₂ readings it’s a different and smaller number, and we can’t state it yet.
What the series can’t tell you
Writing these down was the most useful part of the exercise.
One sensor, one room. Nothing here says anything about any other room.
No cause log. The table holds CO₂, temperature, humidity and battery, and nothing else. There’s no record of windows, doors, ventilation or who was there. Any “why” about a rise or a fall would be a story, not data.
Accuracy is the vendor’s claim. The spec says ±(50 ppm + 5% of the reading). At 700 ppm that’s ±85 ppm. Nobody has compared this meter with a reference instrument. The lowest value in the whole series is exactly 400 ppm, and nothing ever goes below it. That fits an automatic baseline pinned to 400, but it doesn’t prove one.
One season. Five weeks from early September to mid-October, as the room cooled. No winter yet.
It’s also a real sensor. One of the earlier notes in this project sorted cheap “CO₂” parts into two groups. Some actually measure the gas, using infrared absorption or a photoacoustic method. Others measure volatile compounds and compute a plausible CO₂ number from them. The rule we kept was short: NDIR or photoacoustic, or it isn’t a measurement. Without that rule, this whole post would be about coverage of a guess.
What I’d do again
Fix the read bound before the first query. Count the holes before reading the values. Separate holes by design from real holes. Put restarts and gaps side by side. Run two independent passes and compare hashes. And before trusting a percentile, ask how many real measurements the rows stand for.
Only after all that is the series evidence. Before it, it’s just a long list of numbers that look sure of themselves.
— Max


