5

When I run vcgencmd measure_temp in the terminal, it gives the temperature reading of the cpu.

But when i use the same command in php exec('vcgencmd measure_temp 2>&1') it gives following error in the browser:

VCHI initialization failed

How can vcgencmdcommand be executed from php?

Rkumar
  • 127
  • 2
  • 3
  • 10
  • I am sure PHP already uses rapid rises and falls in cpu temperature to communicate in primitive SOS language with the Gerbils in your pc. The Gerbils must therefore have an exclusive lock on the cpu temperature. – Sumurai8 May 10 '15 at 13:46
  • https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=34076 <-- this suggests updating the firmware/restarting will fix it. – Sumurai8 May 10 '15 at 13:56
  • Could be permissions issue. Try `exec ('sudo vcgencmd measure_temp 2>&1')`. – Samuel May 10 '15 at 14:21
  • @Samuel Using sudo gives following error in the browser 'sudo: no tty present and no askpass program specified' – Rkumar May 10 '15 at 14:42
  • Check that link, to configure sudoers file: http://stackoverflow.com/a/24107529/524743 – Samuel May 10 '15 at 14:46

1 Answers1

7

You have to add user 'www-data' to group named 'video'. You can do add by executing this command as sudo:

sudo usermod -aG video www-data

It will help after reboot. If it will not help, try to check username of script executor by writing this code:

<?php
echo(exec("whoami"));
?>

And add printed user to group 'video'.

Sorry for my bad english.

ByMsx
  • 108
  • 1
  • 6