nus-sps / earth-sensors-article

SP3275 Raspberry Pi and CO2 + BME688 sensor codebase
https://sps.nus.edu.sg/sp3275/raspberrypi-and-sensors/
GNU General Public License v3.0
1 stars 1 forks source link

Higher occurence of last line corrupted files #3

Open SungMatt opened 1 year ago

SungMatt commented 1 year ago

An addition for an index was added to the measurement code. This repeated writing and flushing (while keeping the file open) has unintended consequences when power is forcibly removed from the Pi, and the Pi shuts down without closing the file properly.

@mingyi456 pointed out that this is likely due to flush() being used, and opening and closing the file at every loop would probably prevent this.

Issue should be quickly solved by repeatedly fopen() and fclose() file upon write success!

https://github.com/nus-sps/earth-sensors-article/commit/ca6275b850a0332163c8b61dddd3e83914a9197f

mingyi456 commented 1 year ago

I believe your proposed explanation is inaccurate. I am pretty sure many people were facing this even when properly shutting down, given how common it was. Last iteration of this fieldwork, there was no flush commands used, and most people did not properly shut down, and yet file corruption was still less common.