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


                                           RELATED LINKS

                                          How to

                                          Connect Raspberry PLC to Wi-Fi


                                          Raspberry PLC

                                          Family products


                                          Basics about

                                          Raspberry Pi PLC
                                          Analog Outputs


                                          Touchberry Pi

                                          Family products



                                           REQUIREMENTS

                                                                                                                           Function

                                                                                                                          In all the Raspberry PLC Family products, the UPS has its own configuration file called rpishutdown and service named rpishutdown-service. The placement of both files can be consulted in the Section 15.3 of the Raspberry PLC UserGuide. To execute specific commands before finishing the Power Off process, you must follow the next steps:

                                                                                                                              -    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 file type can be anyone 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 script execution time cannot surpass 6 seconds (aprox.), as it is the Raspberry’s Power Off period. Take into account that this code only can be things that do not depend on the external power supply, like creating a file or things directly related with 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 Raspberry Power Off.

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

                                                                                                                          Looking for your ideal PLC?

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

                                                                                                                          Do you want more information?

                                                                                                                          Just fill the form!

                                                                                                                          Tell me more!