16BitDoggo
16BitDoggo

Reputation: 11

What is the most likely issue in my RPI OS script

So, my issue is: I made a script partially copied from: https://issuu.com/themagpi/docs/issue27final/17?e=1 to send an email when a pin on the RPI's GPIO goes high. I had to manually fix everything that broke between Python1 to Python3, it doesn't change from 0s to 1s in the prompt. I have tried replacing the wires but that's about it since I'm a beginner. Here's my code:

#/usr/bin/python

# Note: you must change lines 25-27

# Import Stuff
import subprocess

import RPi.GPIO as GPIO, feedparser
from time import sleep
import smtplib, os, sys
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.image import MIMEImage

GPIO.setwarnings (False)
GPIO.setmode(GPIO.BOARD)

# Set up GPIO Inputs
# Yellow Input
GPIO.setup(7, GPIO.IN)

# Send email message and photo from Gmail
def send_email(msg):
 # Change these 3 lines to your details.
 USERNAME = "[email protected]"
 PASSWORD = "your Gmail password"
 MAILTO = "[email protected]"
 
 msg['From'] = USERNAME
 msg['To'] = MAILTO
 
 server = smtplib.SMTP('smtp.gmail.com:587')
 server.ehlo_or_helo_if_needed()
 server.starttls()
 server.ehlo_or_helo_if_needed()
 server.login(USERNAME, PASSWORD)
 server.sendmail(USERNAME, MAILTO, msg.as_string())
 server.quit()

 print("Email sent to: " + MAILTO)
 
 # Send email when fire alarm activated
 def Send_firealarm_email():
     print("Fire Alarm Activated")
     msg - MIMEMultipart()
     msg.attach(MIMEText('Fire Alarm on Zone 1'))
     msg['Subject'] - 'Fire Alarm Notification'
     send_email(msg)
     
     player = subprocess.Popen(["mplayer", "song.mp3", "-ss", "30"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     
 # Send email when fire alarm off
 def Send_cancel_email():
     print("Fire Alarm Reset")
     msg - MIMEMultipart()
     msg.attach(MIMEText('Fire Alarm Canceled'))
     msg['Subject'] - 'Fire Alarm Canceled'
     send_email(msg)
     
     player.stdin.write("q")

# Main control loop
while True:
    Input_yellow = GPIO.input(7)
    print(Input_yellow)
    if Input_yellow == True:
        Send_firealarm_email()

    # if Input_yellow == False:
        # Send_cancel_email()

Upvotes: 0

Views: 60

Answers (0)

Related Questions