av4625 Posted August 6, 2023 Posted August 6, 2023 Hi, I use an OrangePi Zero as a race timer for a car. It is powered from the car. So when the car starts the OrangePi gets power and boots and when the car is turned off the OrangePi loses power and "turns off". This isn't ideal but I don't have a lot of options. I feel like this is a fairly common use case for electronics in cars especially ones like race timers etc. Unless I have a battery as well. I was wondering what are the best things to do to protect against the sudden power loss so that I don't corrupt anything? Is it possible to make parts of the file system read only maybe? All I do with the OrangePi is run a C++ application, it uses two serial ports and runs a server on port 80. The application does read and write its own configuration files and log files. But these are not OS files, only files that the application created itself. I have noticed that after writing or appending to a file from C++, if the power is pulled and then plugged back in the change to the file does not persist. I can ssh on before the power is pulled and `cat` the file and see that it is updated. Seems that the file data is held in RAM for a little while before actually writing. Is there anyway to force file writes to actually be flushed and written straight away? 0 Quote
Gunjan Gupta Posted August 7, 2023 Posted August 7, 2023 Not a c++ person, but generally speaking you need to call sync after you do the write call to make sure its written to disk. Otherwise it will be help in memory. 0 Quote
robertoj Posted August 9, 2023 Posted August 9, 2023 Do a google search for "raspberry overlay filesystem" That way, when you turn from development to testing (under risk of power loss), the OS opens and operates files in an "undoable way". When the power shuts off, it just keeps the data since before it booted 0 Quote
ag123 Posted August 10, 2023 Posted August 10, 2023 (edited) get a phone charging power bank to power the board, charge the battery and power the board, those are the modern UPS otherwise, if it is occasional data, to have it flushed to the disk, the command is usually sync and that does the trick Edited August 10, 2023 by ag123 0 Quote
av4625 Posted August 10, 2023 Author Posted August 10, 2023 Sync has done the trick! I agree that some sort of battery that that has enough capacity to let it shutdown properly is the better solution, but a phone power bank is too big and bulky. It needs to be mounted in a car so needs to be as neat and small as possible 0 Quote
robertoj Posted August 11, 2023 Posted August 11, 2023 A USB battery bank will turn off the 5V for half a second, every time it is plugged or unplugged from the wall or car adapter. And the linux SBC will reset. There are some SBCs that have an onboard lithium charger, such as the Odroid U3 0 Quote
Andrea Posted November 27, 2023 Posted November 27, 2023 You may use the "overlayroot" package: all writes to the / root fs are volatile as they're made into RAM. You may use EEPROM or eMMC to store non volatile data. 0 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.