Hello,
I am currently working on a project where I need to ensure a safe shutdown of my Ubiquity MCB 5.0 after the Raspberry Pi is powered off. This is to prevent any potential SD card corruption caused by an abrupt energy cut.
I was wondering if the Raspberry Pi image includes a specific protocol or mechanism similar to how computers are shut down, where the operating system is completely off before the computer itself is powered down.
If such a protocol exists within the Raspberry Pi image or if you have any suggestions on how I can achieve this, I would greatly appreciate your guidance. I thought of implementing a controlled shutdown using relays connected to the PI GPIO, however I’m not sure how to implement it. I’m using the 2020-11-07-ubiquity-xenial-lxde if that helps.
Thank you for your time and any assistance you can provide. I look forward to your response.
This is a problem we have only addressed with one specific customer and it involved having custom hardware to support this feature. We have no ‘off the shelf’ software only solution for this complex problem. In short it requires residual power to the Pi and then notification of power loss to cause an event. Then a shutdown can happen but only if hardware is able to continue to supply 5.1V to the PI for as long as it takes to do the shutdown. A standard Magni cannot do this sort of advanced power off scheme.
Hmmmm, do you think that booting the raspberry pi through USB or a SSD would be a good option to circumvent this problem then?
USB based flash has same issue. If your system was fully read only there would not be a problem but the corruption is due to writes going on from things like logging and your own app perhaps.
My solution to this issue is to minimize the risk of corruption by use of a root background monitor that starts and stops the system. I made such a system and you can explore if it would suit your needs but this is my own code. I use it on all my own robots and have used it in non-robotic IoT systems as well.
This sort of approach will NOT help those who cold power off the unit. The basic idea is this script is started by the linux os on bootup and then runs your own application. The system forever waits for medium press on a single key then does reboot or longer press on that key and does shutdown. This approach could be used on Magni but with a slight twist.
For a magni it is very hard to you yourself start all the ROS code and nodes so I would suggest use of this approach that is only responsible for watching the key and issuing a shutdown or reboot perhaps even stopping magni first.
The Magni is fine if you do a ‘shutdown -h now’ then let it stop then power off but we have no keyboard. We only long ago issues something to listen to a switch then cold shutdown but that too would corrupt disk if certain writes are in progress.
So you can take a look at this which is my own code and use of it is not ‘blessed’ by Magni team although I have always wanted to get something like this as part of our distribution, it is not.
You can find it on my personal github here: https://github.com/mjstn/MarkWorldCodeModules
Then go into RaspberryPiUtilities and look at my (humble) docs on that page AND in the actual script which is sys_monitor.py
I offer this ‘offline’ from Magni but as a magni core senior dev I will say this is what I would look at doing and have been meaning to for a few years just never got to it.
Hope this offers some assist to get you going. Again, this cannot prevent corruptions that are due to hard power off cases, this is only an option if you can have organized shutdown from a button (that button being from a human or some home brew RF device or whatever)