【发布时间】:2021-07-26 04:13:33
【问题描述】:
我正在尝试通过在网络上切换 RaspberryPi 上的 GPIO 引脚来控制 LED 灯。
index.html(下图)有两个按钮来运行函数,这将触发两个脚本(lighton.cgi 和 lightoff.cgi)直接控制 GPIO。我验证了将打开或关闭 LED 的脚本。但是不知何故,当我单击 index.html 上的按钮时,它不会打开或关闭 LED。
我的 index.html 中是否存在语法错误?还是 html 约定发生了变化?有人可以帮帮我吗?
index.html 代码:
<html>
<head>
</head>
<body>
<button onclick="lighton()">Turn On</button>
<br><br>
<button onclick="lightoff()">Turn Off</button>
<script>
var xmlhttp;
xmlhttp=new XMLHttpRequest();
function lighton()
{
xmlhttp.open("GET","cgi-bin/lighton.cgi",true);
xmlhttp.send();
}
function lightoff()
{
xmlhttp.open("GET","cgi-bin/lightoff.cgi",true);
xmlhttp.send();
}
</script>
</body>
</html>
lighton.cgi 代码:
#!/bin/bash
gpio -g write 10 1
[b]lightoff.cgi 代码:[/b]
#!/bin/bash
gpio -g write 10 0
我基本上按照下面的 MJRoBot 教程进行操作: https://www.hackster.io/mjrobot/iot-controlling-a-raspberry-pi-robot-over-internet-6988d4#toc-step-1--bill-of-material-1
【问题讨论】:
标签: html raspberry-pi iot