首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RaspberryPi webiopi脚本错误不起作用

RaspberryPi webiopi脚本错误不起作用
EN

Stack Overflow用户
提问于 2014-05-09 22:12:14
回答 1查看 983关注 0票数 0

我想对RaspberryPi进行实验,但是.py代码不起作用。它给我带来了很多错误。

  • 空间误差
  • 缩进错误:expected an indented block " global VELUX_STATE, AUTO_mode "

我只复制了官方论坛的代码,这对其他人是有效的。

链接:http://egrasland.blogspot.fr/2014/01/control-your-velux-roller-shutter-with.html

我复制代码并粘贴到"sudo nano script.py“中。

我做错什么了?

此外,来自RaspberryPi的官方webiopi的代码也不适用于我。调试会导致错误,程序不会启动。

链接:Basis

EN

回答 1

Stack Overflow用户

发布于 2014-05-10 09:29:10

谢谢你的回答。

我使用的代码是:

Python服务器脚本:

代码语言:javascript
复制
import webiopi import datetime

GPIO = webiopi.GPIO     
VELUX_UP = 17 # GPIO pin using BCM numbering VELUX_DOWN = 18 # GPIO pin using BCM numbering VELUX_STOP = 27 # GPIO pin using BCM numbering     
VELUX_STATE = 0 # DOWN AUTO_MODE = 1     
HOUR_UP  = 9   # Turn Velux UP at HOUR_DOWN = 19 # Turn Velux Down at     
# setup function is automatically called at WebIOPi startup 
def setup():   global VELUX_STATE, AUTO_MODE     
    # set the GPIO used for VELUX command to output  
    GPIO.setFunction(VELUX_UP, GPIO.OUT)   
    GPIO.setFunction(VELUX_DOWN,GPIO.OUT)

    # STOP function not used at this time   
    GPIO.setFunction(VELUX_STOP,GPIO.OUT)
    GPIO.digitalWrite(VELUX_STOP, GPIO.LOW)

    # retrieve current datetime   now = datetime.datetime.now()     
    if (AUTO_MODE==1):
        # test time
        if ((now.hour >= HOUR_UP) and (now.hour < HOUR_DOWN)):
            GPIO.digitalWrite(VELUX_UP, GPIO.HIGH)
            webiopi.sleep(0.2)
            GPIO.digitalWrite(VELUX_UP, GPIO.LOW)
            VELUX_STATE = 1
        else: 
            GPIO.digitalWrite(VELUX_DOWN, GPIO.HIGH)
            webiopi.sleep(0.2)
            GPIO.digitalWrite(VELUX_DOWN, GPIO.LOW)
            VELUX_STATE = 0

# loop function is repeatedly called by WebIOPi  
def loop():   global VELUX_STATE, AUTO_MODE     
    # retrieve current datetime   now = datetime.datetime.now()     
    if (AUTO_MODE==1):
        # toggle VELUX UP all days at the correct time
        if ((now.hour == HOUR_UP) and (now.minute == 0) and (VELUX_STATE == 0)):
            GPIO.digitalWrite(VELUX_UP, GPIO.HIGH)
            webiopi.sleep(0.2)
            GPIO.digitalWrite(VELUX_UP, GPIO.LOW)
            VELUX_STATE = 1 #UP

        # toggle VELUX DOWN all days at the correct time
        if ((now.hour == HOUR_DOWN) and (now.minute == 0) and (VELUX_STATE == 1)):
            GPIO.digitalWrite(VELUX_DOWN, GPIO.HIGH)
            webiopi.sleep(0.2)
            GPIO.digitalWrite(VELUX_DOWN, GPIO.LOW)
            VELUX_STATE = 0 #DOWN
            # gives CPU some time before looping again   webiopi.sleep(1)

# destroy function is called at WebIOPi shutdown 
def destroy():   
    GPIO.digitalWrite(VELUX_UP, GPIO.LOW)   
    GPIO.digitalWrite(VELUX_DOWN, GPIO.LOW)   
    GPIO.digitalWrite(VELUX_STOP, GPIO.LOW)


@webiopi.macro def getHours():
    return "%d;%d" % (HOUR_UP, HOUR_DOWN)

@webiopi.macro def setHours(on, off):
    global HOUR_UP, HOUR_DOWN
    HOUR_UP = int(on)
    HOUR_DOWN = int(off)
    return getHours()

@webiopi.macro def getAutoMode():
    return "%d" % (AUTO_MODE)

@webiopi.macro def setAutoMode():
    global AUTO_MODE

    if AUTO_MODE:
        AUTO_MODE=0
    else:
        AUTO_MODE=1
    return getAutoMode()

调试不能在这里发布,因为它在我的RaspberryPi和浏览器上缓慢:),但是他给出的第一个错误是注释VELUX "HOUR_UP =9#转过Velux“在”我解决了这个问题,但是它是错误"def VELUX_STATE():全局VELUX_STATE,AUTO_MODE“

为什么?

谢谢!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23574728

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档