[Python] What is the most likely issue in my RPI OS script

Discussão em 'Python' iniciado por Stack, Dezembro 7, 2024.

  1. Stack

    Stack Membro Participativo

    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:

    #1/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 = "elislagle2012@gmail.com"
    PASSWORD = "your Gmail password"
    MAILTO = "elislagle2012@gmail.com"

    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)
    return

    #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)
    return

    #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")
    return

    #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()


    Hopefully you can read the gibberish. Thank you in advance, 16BitDoggo

    Continue reading...

Compartilhe esta Página