tar xv*** WebIOPi-0.7.1.tar.gz
cd WebIOPi-0.7.1
sudo ./setup.sh
sudo update-rc.d webiopi defaults
最后还是重启树莓派
第四步:创建自定义界面
现在我们要创建控制喇叭的自定义界面
首先建立文件夹:
sudo mkdir horn
cd horn
sudo mkdir html
sudo mkdir python
然后创建Python文件:
cd python
sudo nano script.py
把下面的复制到Python文件:
import webiopi
GPIO = webiopi.GPIO
HORN = 11 # GPIO pin using BCM numbering
# setup function is automatically called at WebIOPi startup
def setup():
# set the GPIO used by the horn to output
GPIO.setFunction(HORN, GPIO.OUT)
# loop function is repeatedly called by WebIOPi
def loop():
# gives CPU some time before looping again
webiopi.sleep(1)
# destroy function is called at WebIOPi shutdown
def destroy():
GPIO.digitalWrite(HORN, GPIO.LOW)
按ctrl-X 和Y 保存文档
现在我们发出以下命令创建HTML文件:
cd
cd horn
cd html
sudo nano index.html
把下面的复制到文件,按ctrl-X 和Y 保存:
Horn Control!
webiopi().ready(function() {
// Create a "Control Horn" labeled button for GPIO 11
var button = webiopi().createGPIOButton(11, "Annoy People");
// Append button to HTML element with ID="controls" using jQuery
$("#controls").append(button);
// Refresh GPIO buttons
// pass true to refresh repeatedly of false to refresh once
webiopi().refreshGPIO(true);
});