Jump to content

How can I protect against power loss?


av4625

Recommended Posts

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?

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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 by ag123
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines