簡體   English   中英

使用 Dweet.io 時,循環卡在 Raspberry PI 上的 python

[英]Loop getting stuck on python on Raspberry PI when using Dweet.io

我對 python 很陌生,所以請耐心等待。 我正在嘗試更改 GPIO 引腳的 state 以控制基於 dweet.io 變量的 state 的繼電器。 變量是命令,它可以是 on、off 或 done。 程序檢查 dweet 直到它不等於完成,這意味着它要么打開要么關閉,並相應地更改繼電器的 state。 然后,它將 dweet 改回,使命令等於完成,然后重新執行。 但是,它只能工作一次。 之后,它只是不斷地將 dweet 改回完成。

import RPi.GPIO as GPIO
import time
import dweepy
import os

GPIO.setmode(GPIO.BOARD)
GPIO.setup(7,GPIO.OUT)

dweepy.dweet_for('my_thing', {'command': 'done'})
url = dweepy.get_latest_dweet_for("my_thing")
dict = url[0]
command = dict["content"][str("command")]


while True:
        1 == 1

        while command == "done":
                time.sleep(2)
                url = dweepy.get_latest_dweet_for("my_thing")
                dict = url[0]
                command = dict["content"][str("command")]


        else:
                if command == "on":
                        GPIO.output(7,GPIO.LOW)
                        time.sleep(2)
                        dweepy.dweet_for('my_thing', {'command': 'done'})

                else:
                        GPIO.output(7,GPIO.HIGH)
                        time.sleep(2)
                        dweepy.dweet_for('my_thing', {'command': 'done'})

我認為既然它工作一次,我應該能夠在將 dweet 更改回 done 並擺脫無限循環之后再次啟動程序。 這可行,但是當 Pi 啟動時我無法運行它。

import RPi.GPIO as GPIO
import time
import dweepy
import os

GPIO.setmode(GPIO.BOARD)
GPIO.setup(7,GPIO.OUT)

dweepy.dweet_for('my_thing', {'command': 'done'})
url = dweepy.get_latest_dweet_for("my_thing")
dict = url[0]
command = dict["content"][str("command")]




while command == "done":
        time.sleep(2)
        url = dweepy.get_latest_dweet_for("my_thing")
        dict = url[0]
        command = dict["content"][str("command")]


else:
        if command == "on":
                GPIO.output(7,GPIO.LOW)
                time.sleep(2)
                dweepy.dweet_for('my_thing', {'command': 'done'})
                execfile('dweetrelay.py')

        else:
                GPIO.output(7,GPIO.HIGH)
                time.sleep(2)
                dweepy.dweet_for('my_thing', {'command': 'done'})
                execfile('dweetrelay.py')

所以我要么需要弄清楚為什么循環會卡住,要么需要弄清楚為什么第二個版本不在后台運行。

在此先感謝,我很感激任何線索。

如果您將命令設置為完成,則從那時起它將始終完成。 因此循環。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM