Python loop script stops running: why? - Raspberry Pi Forums
hello, fellows!
i've written small scripts check if house door opened , notifications:
works but, during day, stops running (i check ps aux).
how can track down problem?
i've written small scripts check if house door opened , notifications:
code: select all
import smtplib email.mime.text import mimetext import time import rpi.gpio gpio import subprocess gpio.setmode(gpio.bcm) gpio.setup(23,gpio.in) input = gpio.input(23) mp3_path = '/home/pi/scripts/tin.wav' def notificaemail(): messaggio = "attenzione: qualcuno ha aperto la porta di casa..." s = smtplib.smtp('smtp.gmail.com') s.set_debuglevel(1) sender = 'email' password = 'password' recipients = ['email', 'email2'] msg = mimetext(messaggio) msg['subject'] = '!!! allarme porta !!!' msg['from'] = sender msg['to'] = ", ".join(recipients) s.ehlo() s.starttls() s.ehlo s.login(sender, password) s.sendmail(sender, recipients, msg.as_string()) s.quit() #initialise previous input variable 0 (assume button not pressed last) prev_input = 0 while true: #take reading input = gpio.input(23) #if last reading low , 1 high, print if ((not prev_input) , input): notificaemail() subprocess.popen(["/bin/bash", "/home/pi/scripts/pushover.sh", "!!! allarme porta venafro !!!", "qualcuno ha aperto la porta di casa venafro..."]) subprocess.call(['play', mp3_path]) #update previous input prev_input = input #slight pause debounce time.sleep(0.20)
how can track down problem?
it's error causing script stop. use 'try' , 'except' (google if you're unsure, loads of examples) catch , report errors without stopping script.
dave.
dave.
raspberrypi
Comments
Post a Comment