All workbench notes

Project update

FieldHub — When Storage Fills Up

Two ways the FieldHub could lose readings without saying so turned up on the bench this week. A full SD card reported rows as saved, and a full flash crashed the hub. Both are fixed, and the hub now shows the card's state on its own pages.

The SD card is becoming the FieldHub's main record of readings, so that an outage of the mobile connection doesn't lose anything. Before building on it I wanted to know how it fails, so I tested the failures on the bench: a full card, a missing card, a card in the wrong format and a full flash.

The first finding was a bad one. On a full card the hub carried on reporting each row as saved. In the test, 2,000 rows were counted as written after the card was full, and the file ended with a torn row. The Arduino core holds a file's writes in a 4 KB buffer and only sends them to the card when the file is closed, and nothing checked the result of that step. Rows are now written without the buffer, so a full or failing card fails the write and the hub knows about it. The full-card test that failed now passes.

The hub now names the card's state: OK, no card, unreadable (wrong format or damaged), read-only, full or write failed. The Data page shows it in full, the overview shows a short chip only when something is wrong, every wake prints it, and it is sent with the hub's status upload. It also keeps two counts, readings that never reached the card and readings dropped from flash before they were uploaded. I checked the missing-card case on the phone by taking the card out and putting it back between sync windows, and covered the others with bench tests: a card in the wrong format, a full card and a read-only file. The card's readings are now kept in one file per month with a small summary, so the Data page can list and download each month without reading the whole record.

The second finding was in the flash, not the card. Testing a full flash, I crashed the bench hub into a reboot loop. The cause was one line in the filesystem library that ships with the ESP32 Arduino core (version 2.0.17): it divides by a block count that is zero in this setup, so every out-of-space error became a crash instead of an error. I now link a copy of that library with the one line changed, and the repository's check fails if the core's copy ever comes back. A test fills the flash on purpose. The stock library crashes, the patched one fails the write cleanly, and the stored readings are untouched. Then I ran the patched build for almost six hours, 19 sync windows with one node, and the hub acknowledged 337 readings with no crash and no storage error.

This is groundwork. Uploads still read from flash. Uploading from the card, removing the oldest files when it fills, and cutting the power in the middle of writes are next, followed by an outage test at the rate of a 16-node hub.