troubleshooting Question

Python Script Quits Running on Raspberry Pi

Avatar of dynamicOne
dynamicOne asked on
Programming Languages-OtherProgrammingPythonRaspberry Pi
11 Comments1 Solution899 ViewsLast Modified:
Yesterday an expert help me get my script to stop delivering multiple messages. He did a great job! I would have contacted him directly, but this is the only way I know how to.

My script should run 24/7. However, after a couple of hours (an educated guess at best). It quits working. The way I know it quits working is because I don't receive the text messages the script sends when the garage door opens and closes.

Any ideas?

#! /usr/bin/env python
import commands
import smtplib
from email.MIMEText import MIMEText

ser = 'gpio read 1'  #Change /dev/ttyACM0 to your com port

GMAIL_LOGIN = '***********'
GMAIL_PASSWORD = '************'
SEND_TO = '**********'
def send_email(subject, message, from_addr=GMAIL_LOGIN, to_addr=SEND_TO):
    msg = MIMEText(message)
    msg['Subject'] = subject
    msg['From'] = from_addr
    msg['To'] = to_addr
    server = smtplib.SMTP('',587) #port 465 or 587
    server.sendmail(from_addr, to_addr, msg.as_string())

last_result = ""

while 1: #loop forever
   result = commands.getoutput(ser)
   if result.strip() == "1" and result.strip() != last_result:
    status=open('garage.txt', 'w')
    status.write("Garage door is open")
    send_email('OPEN', 'The garage door is open')
    last_result = result.strip();
#    print("open")

   elif result.strip() == "0" and result.strip() != last_result:
    status=open('garage.txt', 'w')
    status.write("Garage door is closed")
    send_email('CLOSED','The garage door is closed')
    last_result = result.strip();
#    print("closed")
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 11 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros