提问人:Gaston Melo 提问时间:8/22/2023 更新时间:8/22/2023 访问量:40
使用 python html armv7 的 libgpiod
libgpiod with python html armv7
问:
python脚本无论如何都会返回
我将 python 和 php apache 一起安装到 armv7(使用 linux 内核 6.5-rc6 和 buildroot 2023.02.3)。我包括 python 扩展。我可以毫无问题地执行 php 脚本,但是当 php 脚本执行 python 脚本时,如下所示:
#!/usr/bin/pytho
import gpiod
import time`
def id_btn():
line_index=32
chip=gpiod.Chip('gpiochip0')
pin=chip.get_line(line_index)
pin.request(consumer="id0",type=gpiod.LINE_REQ_DIR_IN, default_val=0)
state=pin.get_value()
if(state==1):
#pin.set_value(0)
return 'red'
else:
#pin.set_value(1)
return 'lightblue'
color=id_btn()
print(f'{color}')
在我收到的 html 控制台中,它应该返回红色或浅蓝色。但是如果我使用这个其他 python 脚本:
#!/usr/bin/env python
print('lightblue')
只是为了测试是否正在执行 Python 脚本,我得到了正确的输出。未导入 gpiod 库或发生其他情况。 执行 pythons 脚本的 php 脚本是这样的:
<?php
$cmd=escapeshellcmd('python /usr/htdocs/html/id0.py');
$status=shell_exec($cmd);
echo $status;
?>
如果我在控制台中执行 ./id0.py,我会得到正确的输出。我尝试了很多方法,但不知道为什么 id0.py 在html代码中返回空字符串。
我将 apache 配置为像 python 一样运行 CGI 脚本。安装了 gpiod 库,因为我可以在控制台中执行 gpiodetect 并获取 gpiochip0 作为输出。
此外,我已经打印了此脚本的输出:并且在控制台输出中,php 和 python 也得到了相同的结果。
我的猜测,import gpiod 不起作用,但为什么?为什么 libgpiod 没有被执行?
加斯顿import sys print(sys.path)
答: 暂无答案
评论