I have 2 Raspberry pi boards:
- pi@PLC with the codesys project
- pi@raspberrypi (the other one)
I already made two buttons to shutdown and restart pi@PLC without problems.
Then I made a 3rd button to shutdown pi@raspberrypi with the following code:
_xDoExecuteShell : BOOL;
_pResult : Systypes.RTS_IEC_RESULT;
_sCommand : STRING;
IF _xDoExecuteShell THEN
_xDoExecuteShell := FALSE;
_sCommand := 'ssh pi@raspberrypi -t sudo shutdown -h -P now';
_RetVal := Sysprocess.SysProcessExecuteCommand(pszComand:= _sCommand, pResult:= ADR(_pResult));
Both RP boards share a private generated key. When I use Putty to log in via SSH to pi@PLC and execute: ssh pi@raspberrypi -t sudo shutdown -h -P now, it shuts down perfectly without asking for passwords or anything. Just as intended.
However it does not work via Codesys.
I use the same syntax above to shutdown(sudo shutdown -h now & disown) and restart(sudo reboot) pi@PLC without problems, however the code above does not seem to do anything regarding pi@raspberrypi.
Anyone have any idea what I am doing wrong?
Thanks in advance.
I would give this a try:
generate a script for example ssh-shutdown.sh with your command:
ssh pi@raspberrypi -t sudo shutdown -h -P now
and just execute then ssh-shutdown.sh by the codesys command.
Hello, look to the side.
pRes: POINTER TO SysProcess.SysTypes.RTS_IEC_RESULT;
StrName_Shutdown: STRING(255):= 'sudo shutdown now ';
SysProcessExecuteCommand((StrName_Shutdown) , pRes );
If you haven't done so, maybe add ssh to /etc/CODESYSControl_User.cfg:
shutdown is default. There's another option to allow all via Command=AllowAll, but this is way too permissive.
Thank you all for the feedback.
I used Edwin's suggestion and created a python script.
This seems to do the trick.
Log in to post a comment.