Reboot when a GPIO input is triggered

Hodgy1993
2014-04-10
2021-04-19
  • Hodgy1993 - 2014-04-10

    Good Morning,

    Is there a simple way to reboot the "Pi" when an GPIO input contact is closed?
    I'm planning on having a "System Reboot" button on the front panel of the completed system and can't seem to find the "CODESYS" way of commanding this as oppose to generating a seperate script on the Pi.

     
  • eschwellinger

    eschwellinger - 2014-04-16

    Hi,
    you need to do the following steps:
    1. Pi side
    add the section and command which you want to execute in CODESYSControl.cfg (this is under /etc)

    See Screenshot config.jpg

    1. CODESYS Project

    In CODESYS Library Manager you need to add Sysprocess.library and SysTypes.library

    PROGRAM PLC_PRG
    VAR
       xReboot: BOOL:
       Result: RTS_IEC_RESULT;
    END_VAR
    

    See screenshot reboot.jpg - how to execute it in CODESYS:

    Thats it!

    BR
    Edwin

    IMG: config.jpg

    IMG: reboot.jpg

    IMG: Libs.jpg

     
  • Hodgy1993 - 2014-04-17

    You are the man Edwin.
    Cheers!

     
  • brub - 2014-07-18

    Hello,
    I would like executing a script via "Sys Process Execute Command" or another Function out of the library.
    I tried different commands in the .cfg file but it doesnt work.
    Could anyone tell me how i can start a script sucessfully?

    Thanks!

     
  • plcmax - 2014-07-18

    Hi, which command did you add to the config and what do you call in the codesys code exactly?
    Regards plcmax

     
  • brub - 2014-07-18

    The Function in Codesys was "Sys Process Execute command " pzsCommand "switch"
    In CODESYSControl.cfg i ve insert :
    [SysProcess]
    /home/pi/switch.sh=switch

     
  • plcmax - 2014-07-19

    Hi,

    for me the solution was to move my script 'script_run' to /usr/bin

    and in the CODESYSControl.cfg you enable it by

    [SysProcess]
    Command.0=script_run

    In Codesys I call it by:

    Regards
    plcmax

    IMG: run.jpg

     
  • brub - 2014-07-19

    Thanks plcmax!

    Now again the Beginning:
    I made a new script switch.sh, then I set it executeable.
    The Script sends a 433 Mhz Signal , GPIO17
    On the Raspberry Pi i can execute the Script and the Signal generates sucessfully
    I moved my Script "switch.sh" to /usr/bin/ and set up the Codesys Program.

    Now i set the Bit START_SCRIPT but nothing happend,
    has anyone a idea what went wrong?

    IMG: Configuration.png

     
  • eschwellinger

    eschwellinger - 2014-07-19

    Hi,

    either call 'script.sh' in CODESYS or rename your script in /usr/bin to script

    you could check if the script is executed with cat /tmp/codesyscontrol.log

    BR
    Edwin

     
  • brub - 2014-07-19

    Thanks a lot!!!

    Finally it works i think i was mentally blocked...

    How easy

    ->Solved

     
  • eschwellinger

    eschwellinger - 2014-07-22

    Hi,

    may I ask what exactly you are realize with the 433 Mhz Signal on GPIO17?

    BR
    Edwin

     
  • AlexB - 2014-11-05

    If nothing is configured, Sys Execute Command will always fail.
    In addition to that, it is also possible to ignore the above white list and allow all commands by: Command=AllowAll
    ATTENTION: If Command=AllowAll is set, there is no further verification done, before a command is executed. Please check your security requirements carefully before activating this. For the same reason you should also choose the allowed commands in the list accurately.

    [SysProcess]
    Command=AllowAll
    Command.0=script_run
    Command.1=reboot

    IF xRun THEN
       SysProcess.S ysProcessE xecuteCommand('echo test > /dev/ttyO1', ADR(Result));
       xRun := FALSE;
    END_IF
    
     
  • mauskopf - 2014-12-27

    Habe ein Problem bekomme immer 25 als rückgabe von Result

     
  • plcmax - 2014-12-27

    Hallo,
    was hast du in der CODESYSControl.cfg eingetragen und welches Kommando
    rufst du denn auf in Codesys?

    Grüße
    plcmax

     
  • mauskopf - 2014-12-27

    Ich habe das Skript unter /usr/bin/ angelegt und ausführbar gemacht!(in Putty funktioniert das skript)
    In der CODESYSControl.cfg habe ich folgende Einträge gemacht
    [SysProcess]
    Command=AllowAll
    Command.0=cs_mail

    Der Aufruf in Codesys sieht so aus
    IF (xSendMail) THEN
    _('cs_mail' , ADR(Result) );
    xSendMail:=FALSE;
    END_IF

    Result ist nach dem Ausführen auf 25
    Was mache ich falsch?

     
  • McBain - 2016-03-13

    Hallo

    hast du das script mit dem gleichen User und Rechten über Putty ausgeführt wie codesys es ausführt?

    MFG

    McBain

     
  • aceron76 - 2016-04-26

    Hi, I know its an older thread and it was helping me a lot, but in my case when pi reboots all my data are lost. How was it in your case or do you know how to solve such an issue?
    BR
    Erwin

     
    • laruso - 2021-04-19

      Offtopic!
      But: To retain the variables, the variables have to be declared as retain ;-) and are only reliable saved, if the system process "shutdown/reboot" is used.

       

Log in to post a comment.