[英]twisted module: I can't work my program from the ip of raspberry pi
我試圖用扭曲的模塊制作一個程序,以便從我的覆盆子pi的ip控制一個led。 我是新手,現在我正在努力學習。 我已經調用了我的程序“lights.py”,並在與此文件相同的文件夾中,我有一個名為“lampwww”的文件夾,其中有一個index.html文件,其中包含以下代碼:
燈火
a href =“http:// ip of raspberry pi / API?light = on”>打開| a href =“http:// ip of raspberry pi / API?light = off”>關閉
因此,當我打開index.html並單擊打開或關閉它不起作用,當我只是在瀏覽器打開覆盆子pi的ip(我已經看到使用ifconfig的ip),它沒有告訴我什么我已經在index.html中寫了,它只是向我顯示“它有效”的文字......
這是我的程序的代碼。 我究竟做錯了什么? 我錯過了什么? 提前致謝!
from twisted.web.server import Site
from twisted.web.resource import Resource
from twisted.internet import reactor
from twisted.web.static import File
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
pin = 17
GPIO.setup(pin, GPIO.OUT)
class lampAPI(Resource):
def render_GET(self, request):
if 'light' in request.args:
if request.args['light'][0] == "off":
GPIO.output(pin, False)
return " light off "
if request.args['light'][0] == "on":
GPIO.output(pin, True)
return " light on "
root = File("/lampwww")
root.putChild("API", lampAPI())
factory = Site(root)
reactor.listenTCP(8080, factory)
reactor.run()
您編寫的HTTP服務器偵聽端口8080.您需要使用http://raspberrypi:8080/
作為任何URL的開頭。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.