1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
from Testmail import mail
from Testmail2 import maill
import time
import pigpio
import vw
import mysql.connector
import time
#!/usr/bin/env python
# -*- coding: utf-8 -*-
ILS = "Alerte_capteur_ILS"
IR = "Alerte_capteur_IR"
REPOS = "Repos_capteur"
RX=11
BPS=2000
pi = pigpio.pi()
rx = vw.rx(pi, RX, BPS)
conn = mysql.connector.connect(host="localhost", user="root", password="raspberry", database="alarme")
cursor = conn.cursor()
while test ton paramètre:
#definir un test
cursor.execute("""SELECT * FROM etat_capteurs""")
rows = cursor.fetchall()
for row in rows:
etat_alarme = row[1]
print(etat_alarme)
**if (etat_alarme == 1):
print("Activation de l'alarme...")
# time.sleep(3)
print ("Chargement du programme, veuillez patienter...")
# time.sleep(3)
start = time.time()
print("En attente de la reception des données !")
print (" ")
un_mail_repos = 0
temps_repos = time.time()
temps_mail = time.time()
while (etat_alarme == 1):
# tu n'as pas peur de spamer ton destinataire en bouclant sur cette partie ?
while rx.ready():
reception = "".join(chr (c) for c in rx.get())
if (reception == str(REPOS)):
temps_repos = time.time()
elif (reception == str(ILS) and (time.time()-temps_mail) > 3):
print("ILS actif")
temps_repos = time.time()
mail()
temps_mail = time.time()
elif (reception == str(IR) and (time.time()-temps_mail) > 3):
print("IR actif")
temps_repos = time.time()
mail()
temps_mail = time.time()
if (un_mail_repos == 0):
if (time.time()-temps_repos) > 15:
maill()
print ("MAIL REPOS")
temps_repos = time.time()
un_mail_repos = 1
break
pi.stop()
rx.cancel()
conn.close() |
Partager