I am working on a project which needs relay to be controlled using raspberry pi. I have set up my script to run on boot up but when power is turned off sometimes the relay is left in ON state as the program exits mid way which is not desired. Is it possible to terminate an auto run script safely once power is switched off?
And is there a way to safely shut down pi on power off as the abrupt power off may corrupt my SD card or even damage my pi.
I have googled a bit regarding this and came across this article http://www.raspberry-pi-geek.com/Archive/2013/01/Adding-an-On-Off-switch-to-your-Raspberry-Pi which needs some extra circuitry.
Is there an alternative method which does not needs an extra circuit?