我想通过关闭翻转开关的帮助从网页控制一个led,我在网上找到它。我用一个翻转开关制作了一个简单的网页,检查GPIO x是高还是低,并将其调整到翻转开关,但我没有任何结果,有什么帮助吗?
我的php脚本:
<?php
$read_gpio13 = shell_exec("/usr/local/bin/gpio read 13");
$red_checked = ($read_gpio13 == 1) ? "checked=\"\"" : "";
?>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="Flip2.css">
</head>
<script>
$(document).ready(function() {
$("#myonoffswitch").change(function() {
var isChecked = $("#myonoffswitch").is(":checked") ? 1:0;
if (isChecked){
$.ajax({
url: 'red.php',
type: 'POST',
});
}
else {
$.ajax({
url: 'redoff.php',
type: 'POST',
});
}
});
});
</script>
<form>
<div class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox"
id="myonoffswitch" <?php echo $red_checked; ?>>
<label class="onoffswitch-label" for="myonoffswitch">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
</form>
</html>
red.php:
<?php
shell_exec("/usr/local/bin/gpio -g mode 13 out");
shell_exec("/usr/local/bin/gpio -g write 13 1");
?>
redoff.php:
<?php
// set to output
shell_exec("/usr/local/bin/gpio -g write 13 0");
?>
答案 0 :(得分:0)
哦,我明白了! jquery在哪里? :D你忘了jquery!把它放在头上或之前 身体的尽头!
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>