Page 1 of 1

Remote shutdown Retropie via Domoticz

Posted: Tuesday 06 December 2016 12:39
by nosehook
Since I got my RetroPie setup with a HS100 plug from TP-Link I want to do the following with a dummy switch:

On: switch the HS100 on (and RetroPie will boot automatically).
Off: remote shutdown RetroPie and when it is off, switch off the HS100.

The problem is the remote shutdown.
I know how to log in with Putty and send the shutdown command, however, I do not know how to write a script to have my Domoticz Raspberry pi ogin and shut it down and what additional packages might be needed for that.

Can some-one please tell me how this should be done?

Thanks,

Freek

Re: Remote shutdown Retropie via Domoticz

Posted: Tuesday 06 December 2016 12:47
by emme
you can try a remote ssh session with no password and issue the shutdown command
have a look to this site about how to connect via ssh and with no password

http://www.linuxproblem.org/art_9.html

Re: Remote shutdown Retropie via Domoticz

Posted: Tuesday 06 December 2016 13:41
by Egregius
Isn't there a auto shutdown option in retropie?
Otherwise I have a script that detects when a network device is offline and switches it's power off. I use it for a Libreelec-Pi.

Re: Remote shutdown Retropie via Domoticz

Posted: Tuesday 06 December 2016 18:31
by nosehook
Egregius wrote:Isn't there a auto shutdown option in retropie?
Otherwise I have a script that detects when a network device is offline and switches it's power off. I use it for a Libreelec-Pi.
If there is an auto shutdown I can not find it...

Could you share your script please?

Re: Remote shutdown Retropie via Domoticz

Posted: Tuesday 06 December 2016 18:35
by Egregius
Sure, part of my pass2php script:

Code: Select all

if($s['kodi']=='On'&&strtotime($t['kodi'])<time-298)
        {
            $devcheck='Kodi';
            if(pingDomain('192.168.2.7',1597)==1)
            {
                $prevcheck=cget('check'.$devcheck);
                if($prevcheck>0)
                    cset('check'.$devcheck,0);
            }
            else
            {
                $check=cget('check'.$devcheck)+1;
                if($check>0)
                    cset('check'.$devcheck,$check);
                if($check>=5)
                    sw($i['kodi'],'Off','kodi');
            }
        }
 function pingDomain($domain,$port)
{
    $file=fsockopen($domain,$port,$errno,$errstr,10);
    $status=0;
    if(!$file)
        $status=-1;
    else
    {
        fclose($file);
        $status=1;
    }
    return $status;
}       
If my Kodi isn't listening anymore, for 5 runs I shutdown it's power.
The 5 runs is in there to enable updates of Libreelec, otherwise power is killed during update... Can't be good.