gpt4 book ai didi

javascript - 树莓派 PHP GPIO 读取

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:28:40 28 4
gpt4 key购买 nike

我有这个脚本来检查 the GPIO引脚状态:

<script type="text/javascript">

$(document).ready(function () {
// This is the init function
// Runs when the page has completed loading

$('#statusCheck').click(function() {
//console.log('checking status');

$.ajax({
url: "check.php",
success: function (data) {
if(data != 1 )
{
// Door is closed
$('#sttext').html('<span style= color:green;>Closed</span>');
}
else if(data == 1)
{
// Door is open
$('#sttext').html('<span style= color:green;>Open</span>Open');
}
//$('#debug').html(''); // Print null string to clear message
//$('#debug').html(data); // Debug message, printing out read back status.
}

});
});
});
</script>

连接到一个按钮和 span:

   <strong>Status: <span id="sttext"></span></strong></p>
<button id="statusCheck" class="green-btn">Check Status </button>

检查PHP代码是:

<?php
system(exec ( "GPIO read 1", $status ));
system(print_r ( $status ));
?>

我一直输出 Closed,尽管 pin 设置为 1...当我从 Raspberry Pi 上的命令行运行读取时,它给了我 1...但是我认为 PHP 脚本不起作用...

最佳答案

我认为问题出在您的 PHP 脚本上。试试这个:

<?php
exec("gpio read 1", $status);
print_r($status); //or var_dump($status);
?>

关于javascript - 树莓派 PHP GPIO 读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25103386/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com