Hello thanks for helping me,
this is the script i would like to stop or start
Code: Select all
#!/usr/bin/env python
import RPi.GPIO as GPIO
import time, smtplib, sys
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN)
GPIO.setup(18, GPIO.OUT)
GPIO.setup(24, GPIO.OUT)
GPIO.output(18, False)
GPIO.output(24, True)
StatoPulsante = False
smtpserver = 'smtp.gmail.com:587'
fromaddr = 'xxxx'
toaddr = 'xxxx'
header = 'To: ' + toaddr + '\n' + 'From: ' + fromaddr
header = header + '\n' + 'Subject:' + "APIARIO1" + '\n'
msg = header + '\n' + 'ALLARME ATTIVATO' + ' \n\n'
#Aggiungo i dati per l'invio
username = 'xxxx' #inserire proprio indirizzo
password = 'xxxx' #inserire propria password
while True:
if not GPIO.input(23):
StatoPulsante = True
else:
StatoPulsante = False
if StatoPulsante:
GPIO.output(18, True)
GPIO.output(24, False)
StatoPulsante = False
# codice mail
server = smtplib.SMTP(smtpserver)
server.starttls()
server.login(username, password)
server.sendmail(fromaddr, toaddr, msg)
server.quit()
sys.exit()
and this is the code of flask which give me the state of the GPIO
Code: Select all
from flask import Flask, render_template
import datetime
import RPi.GPIO as GPIO
app = Flask(__name__)
GPIO.setmode(GPIO.BCM)
@app.route("/")
def hello():
now = datetime.datetime.now()
timeString = now.strftime("%Y-%m-%d %H:%M")
templateData = {
'title' : 'HELLO!',
'time': timeString
}
return render_template('main.html', **templateData)
@app.route("/readPin/<pin>")
def readPin(pin):
try:
GPIO.setup(int(pin), GPIO.IN)
if GPIO.input(int(pin)) == True:
response = "Pin number " + pin + " is high!"
else:
response = "Pin number " + pin + " is low!"
except:
response = "There was an error reading pin " + pin + "."
templateData = {
'title' : 'Status of Pin' + pin,
'response' : response
}
return render_template('pin.html', **templateData)
if __name__ == "__main__":
app.run(host='0.0.0.0', port=80, debug=True)
i followed the tutorials on that link
http://mattrichardson.com/Raspberry-Pi-Flask/index.html
So at that point i see if the GPIO is high or low but it doesn't stop the script, what happen is just see high or low not stopping the script, as i wrote before i would like to stop the script for a while just to non have mail in the meantime i'm working on that box
Another little thing i'm a beekeeper and here (in Italy) people use to stole the hives i just put a interruptor in each hive so if some try to stole it it send me a mail, but when i'm working on that hive i would stop the script do my job and then restart the script without getting inside terminal via ssh
Hope again to be clear but if you have other question i will be happy to answering the question you asking
in the mean time have a nice day