1

I want to be able to turn HDMI on and off from a web page. I have written this script:

$power = $_GET['power'];
if ($power === 'on') {
  echo "<h1>Switching TV on</h1>";

  $output = shell_exec('tvservice -p');
  echo "<pre>$output</pre>";
}
else  {
  echo "<h1>Switching TV off</h1>";

  $output = shell_exec('tvservice -o');
 echo "<pre>$output</pre>";
}

The script doesn't have any effect, and doesn't produce any output. When I execute a tvservice command as user PI, it works:

pi@loungepi /home/mike $ tvservice -p
Powering on HDMI with preferred settings

When I run the same command as www-data, it fails:

$ tvservice -p
[E] Failed to initialize VCHI (ret=-1)

What do I have to do so that www-data can execute tvservice commands?

  • add user www-data to the video group ... i.e. sudo adduser www-data video – Jaromanda X May 11 '17 at 1:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.