적외선 센서가 달린 나무 딸기 파이가 있습니다. 내 파이썬 스크립트에는 imap 서버를 청취하는 스레딩 클래스가 있습니다 (START 또는 STOP과 같은 명령을 catch합니다). 내 아이디어는 이제 전자 메일을 통해 명령을 보내고 스크립트가 명령을 받자 마자 새 명령을받을 때까지 일부 기능을 사용하지 않아야합니다. 하지만 주요 쟁점은 이제 어떻게 구현해야할지 모르겠다는 것입니다. 유용하고 유용한 아이디어에 감사드립니다.Python : 함수를 사용하거나 사용하지 않도록 설정하는 방법은 무엇입니까?
def take_picture():
...
def take_video():
...
class EmailThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
while True:
....
if get_mail == 1:
if var_subject == 'STOP':
#TODO: stop take_picture(), take_video()
pass
elif var_subject == 'START':
#TODO: start take_picture(), take_video()
pass
else:
print u'Wrong command'
time.sleep(600) #google doesn't like many connections within 10min
def main():
# Start eMail Thread
email = EmailThread()
email.start()
try:
print "Waiting for PIR to settle ..."
# Loop until PIR output is 0
while GPIO.input(GPIO_PIR) == 1:
Current_State = 0
print "Ready"
# Loop until threadingusers quits with CTRL-C
while True :
# Read PIR state
Current_State = GPIO.input(GPIO_PIR)
if Current_State == 1 and Previous_State == 0:
counter = counter + 1
# PIR is triggered
start_time = time.time()
log_to_file('Motion Nr. %s detected!' % counter)
take_picture()
# Record previous state
Previous_State = 1
elif Current_State == 0 and Previous_State == 1:
# PIR has returned to ready state
stop_time=time.time()
print " Ready ",
elapsed_time=int(stop_time-start_time)
print " (Elapsed time : " + str(elapsed_time) + " secs)"
Previous_State = 0
except KeyboardInterrupt:
print "Quit "
# Reset GPIO settings
GPIO.cleanup()
if __name__ == '__main__':
main()
'python2'를 사용해야하는 구체적인 이유가 없다면'python3'을 사용하여 sugest합니다. 'python2'를 사용하기로 결정했다 할지라도'print'를 함수로 사용하는 것이 좋습니다. –
일부 모듈은 picamera와 같이 python2에서만 실행되기 때문에 python2.7을 사용하고 있습니다 – Seppo
멋진 아키텍처를 찾으십니까? 나는 전자 메일 스레드에 bool 플래그를 설정하고 메인 루프에'if email.enable_picture :'를 넣을 것이다. – dornhege