使用 php exec 读取 gpio 在 rc.local 树莓派上失败

reading gpio with php exec failing on rc.local raspberry

我在 PHP 脚本中有一个无限循环,它以这种方式读取我的 gpio(使用 wiringPI)

$newstatus = trim(exec("gpio read ".$gpioline[$i]));

rc.local 中的这一行在启动时启动

php /root/CheckGPIO.php &

问题是,当脚本在启动时自动启动时,$newstatus 是一个空字符串变量,而不是在我有终端访问权限后从终端执行 php /root/CheckGPIO.php &,一切正常,我得到$newstatus

中的 gpio 值

什么会导致问题?

PS。查看输出 exec("whoami") 脚本曾经以 root

身份执行

当从 rc.local

调用脚本时,问题是 PATH 未定义