How to execute commands before the Raspberry Pi industrial PLC Power Off process

Learn to execute commands before the shutdown process thanks to Raspberry Pi automation
September 17, 2021 by
How to execute commands before the Raspberry Pi industrial PLC Power Off process
Boot & Work Corp. S.L., Quesada Dani Salvans

                                           Related links

                                          How to

                                          Connect Raspberry PLC to Wi-Fi


                                          Read  

                                          Basics about

                                          Raspberry Pi PLC Analog Outputs


                                          Read  

                                          Raspberry PLC

                                          Family products


                                          See  

                                          Touchberry Pi

                                          Family products


                                          See  

                                          How to

                                          Install Mosquitto on Raspberry PLC thanks to industrial automation


                                          Read   

                                          How to

                                          Send a warning message when the Raspberry PLC is powered off


                                          Read   

                                           Requirements

                                                                                                                           Function

                                                                                                                          In all industrial Raspberry Pi PLC controller Family products, the UPS has its own configuration file called rpishutdown and service named rpishutdown-service. The placement of both files can be found in Section 15.3 of the industrial Raspberry PLC User Guide. To execute specific commands before completing the Power Off process, you must follow the steps below:

                                                                                                                              -    Create this path inside the /etc folder:

                                                                                                                                      sudo mkdir -p rpishutdown/hooks/

                                                                                                                              -    Inside this folder, create a file called pre-poweroff:

                                                                                                                                      sudo nano pre-poweroff

                                                                                                                          The type of file can be whatever you want (Bash Scripts, Python, C++, etc.) but the most important thing is that it must be called pre-poweroff without any extension (you must indicate the file type with the corresponding Shebang). The execution time of the script cannot exceed 6 seconds (aprox.), as this is the Power Off period of the Raspberry. Note that this code can only be for things that do not depend on the external power supply, such as creating a file or things directly related to the Raspberry. (Following this rule, you cannot do things such as enabling an output, so it depends on the external power supply).

                                                                                                                              -    Give the execution permissions to the file:

                                                                                                                                    sudo chmod ugo+x pre-poweroff

                                                                                                                          Following these steps, the file must be executed before the open source PLC Raspberry Pi shuts down.

                                                                                                                          ​Search in our Blog

                                                                                                                          How to execute commands before the Raspberry Pi industrial PLC Power Off process
                                                                                                                          Boot & Work Corp. S.L., Quesada Dani Salvans September 17, 2021

                                                                                                                          Looking for your ideal Programmable Logic Controller?

                                                                                                                          Take a look at this product comparison with other industrial controllers Arduino-based. 

                                                                                                                          We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.


                                                                                                                          Industrial PLC comparison >>>