finally the end of the road
This commit is contained in:
@@ -1,207 +0,0 @@
|
||||
|
||||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
import threading
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setwarnings(False)
|
||||
|
||||
PIN_LED_R = 17
|
||||
PIN_LED_G = 22
|
||||
PIN_LED_B = 27
|
||||
PIN_PIR = 15
|
||||
PIN_BUZZER = 18
|
||||
|
||||
# Keypad 4x4 — 4 lignes (sorties) + 4 colonnes (entrées pull-up)
|
||||
ROWS = [5, 6, 13, 19] # R1 R2 R3 R4
|
||||
COLS = [26, 12, 16, 20] # C1 C2 C3 C4
|
||||
|
||||
KEYPAD_MAP = [
|
||||
['1', '2', '3', 'A'],
|
||||
['4', '5', '6', 'B'],
|
||||
['7', '8', '9', 'C'],
|
||||
['*', '0', '#', 'D'],
|
||||
]
|
||||
|
||||
CODE_SECRET = "1234"
|
||||
|
||||
GPIO.setup(PIN_LED_R, GPIO.OUT, initial=GPIO.LOW)
|
||||
GPIO.setup(PIN_LED_G, GPIO.OUT, initial=GPIO.LOW)
|
||||
GPIO.setup(PIN_LED_B, GPIO.OUT, initial=GPIO.LOW)
|
||||
GPIO.setup(PIN_BUZZER, GPIO.OUT, initial=GPIO.LOW)
|
||||
GPIO.setup(PIN_PIR, GPIO.IN)
|
||||
|
||||
for row in ROWS:
|
||||
GPIO.setup(row, GPIO.OUT, initial=GPIO.HIGH)
|
||||
for col in COLS:
|
||||
GPIO.setup(col, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||
|
||||
etat = "desarmee"
|
||||
etat_lock = threading.Lock()
|
||||
|
||||
_stop_buzzer = threading.Event()
|
||||
_thread_buzzer = None
|
||||
|
||||
|
||||
def led(r=False, g=False, b=False):
|
||||
"""Allume la LED RGB avec la couleur voulue."""
|
||||
GPIO.output(PIN_LED_R, GPIO.HIGH if r else GPIO.LOW)
|
||||
GPIO.output(PIN_LED_G, GPIO.HIGH if g else GPIO.LOW)
|
||||
GPIO.output(PIN_LED_B, GPIO.HIGH if b else GPIO.LOW)
|
||||
|
||||
def led_bleu(): led(b=True)
|
||||
def led_vert(): led(g=True)
|
||||
def led_rouge(): led(r=True)
|
||||
def led_off(): led()
|
||||
|
||||
def bip(nb=1, duree=0.08, pause=0.12):
|
||||
"""Émet nb bip(s) courts."""
|
||||
for _ in range(nb):
|
||||
GPIO.output(PIN_BUZZER, GPIO.HIGH)
|
||||
time.sleep(duree)
|
||||
GPIO.output(PIN_BUZZER, GPIO.LOW)
|
||||
time.sleep(pause)
|
||||
|
||||
def _buzzer_continu(stop_event: threading.Event):
|
||||
"""Boucle interne : buzzer ON/OFF jusqu'à stop_event."""
|
||||
while not stop_event.is_set():
|
||||
GPIO.output(PIN_BUZZER, GPIO.HIGH)
|
||||
time.sleep(0.5)
|
||||
GPIO.output(PIN_BUZZER, GPIO.LOW)
|
||||
time.sleep(0.5)
|
||||
GPIO.output(PIN_BUZZER, GPIO.LOW)
|
||||
|
||||
|
||||
def lire_touche():
|
||||
"""
|
||||
Scan matriciel : met chaque ligne à LOW tour à tour
|
||||
et lit les colonnes. Retourne la touche ou None.
|
||||
"""
|
||||
for i, row in enumerate(ROWS):
|
||||
GPIO.output(row, GPIO.LOW)
|
||||
for j, col in enumerate(COLS):
|
||||
if GPIO.input(col) == GPIO.LOW:
|
||||
time.sleep(0.05) # anti-rebond
|
||||
while GPIO.input(col) == GPIO.LOW:
|
||||
pass # attente relâchement
|
||||
GPIO.output(row, GPIO.HIGH)
|
||||
return KEYPAD_MAP[i][j]
|
||||
GPIO.output(row, GPIO.HIGH)
|
||||
return None
|
||||
|
||||
def lire_code(nb_chiffres=4, timeout=30):
|
||||
"""
|
||||
Attend nb_chiffres touches numériques sur le keypad.
|
||||
Retourne la chaîne saisie ou '' si timeout.
|
||||
"""
|
||||
saisi = ""
|
||||
debut = time.time()
|
||||
print(" Code : ", end="", flush=True)
|
||||
while len(saisi) < nb_chiffres:
|
||||
if time.time() - debut > timeout:
|
||||
print("\n [Timeout — saisie annulée]")
|
||||
return ""
|
||||
touche = lire_touche()
|
||||
if touche and touche.isdigit():
|
||||
saisi += touche
|
||||
print("*", end="", flush=True)
|
||||
time.sleep(0.05)
|
||||
print()
|
||||
return saisi
|
||||
|
||||
|
||||
def passer_en_desarmee():
|
||||
global etat, _thread_buzzer
|
||||
_stop_buzzer.set()
|
||||
if _thread_buzzer and _thread_buzzer.is_alive():
|
||||
_thread_buzzer.join()
|
||||
with etat_lock:
|
||||
etat = "desarmee"
|
||||
led_bleu()
|
||||
print("[ÉTAT] ● DÉSARMÉE — LED bleue")
|
||||
|
||||
def passer_en_armee():
|
||||
global etat
|
||||
with etat_lock:
|
||||
etat = "armee"
|
||||
led_vert()
|
||||
bip(nb=2) # 2 petits bips = armée avec succès
|
||||
print("[ÉTAT] ● ARMÉE — LED verte — PIR actif")
|
||||
|
||||
def passer_en_declenchee():
|
||||
global etat, _thread_buzzer
|
||||
with etat_lock:
|
||||
etat = "declenchee"
|
||||
led_rouge()
|
||||
print("[ÉTAT] ● DÉCLENCHÉE — LED rouge — buzzer actif")
|
||||
_stop_buzzer.clear()
|
||||
_thread_buzzer = threading.Thread(
|
||||
target=_buzzer_continu, args=(_stop_buzzer,), daemon=True
|
||||
)
|
||||
_thread_buzzer.start()
|
||||
|
||||
|
||||
def _surveiller_pir(stop_evt: threading.Event):
|
||||
"""Lit le PIR toutes les 100 ms. Déclenche si mouvement et armée."""
|
||||
print("[PIR] Surveillance démarrée")
|
||||
while not stop_evt.is_set():
|
||||
with etat_lock:
|
||||
etat_local = etat
|
||||
if etat_local == "armee" and GPIO.input(PIN_PIR) == GPIO.HIGH:
|
||||
print("[PIR] ⚠ Mouvement détecté !")
|
||||
passer_en_declenchee()
|
||||
time.sleep(0.1)
|
||||
|
||||
|
||||
def boucle_principale():
|
||||
global etat
|
||||
|
||||
# Démarrage : LED bleue (désarmée)
|
||||
passer_en_desarmee()
|
||||
|
||||
# Thread PIR en arrière-plan
|
||||
stop_pir = threading.Event()
|
||||
thread_pir = threading.Thread(
|
||||
target=_surveiller_pir, args=(stop_pir,), daemon=True
|
||||
)
|
||||
thread_pir.start()
|
||||
|
||||
print("\n=== Système d'alarme démarré ===")
|
||||
print(" Tapez le code sur le keypad pour armer / désarmer.\n")
|
||||
|
||||
try:
|
||||
while True:
|
||||
with etat_lock:
|
||||
etat_local = etat
|
||||
|
||||
if etat_local == "desarmee":
|
||||
print(" → Saisir le code pour ARMER :")
|
||||
code = lire_code(nb_chiffres=len(CODE_SECRET))
|
||||
if code == CODE_SECRET:
|
||||
print(" ✔ Code correct → armement")
|
||||
passer_en_armee()
|
||||
elif code != "":
|
||||
print(" ✘ Code incorrect")
|
||||
bip(nb=1, duree=0.4) # 1 bip long = erreur
|
||||
|
||||
elif etat_local == "armee":
|
||||
time.sleep(0.1)
|
||||
|
||||
elif etat_local == "declenchee":
|
||||
print(" → Saisir le code pour DÉSARMER :")
|
||||
code = lire_code(nb_chiffres=len(CODE_SECRET))
|
||||
if code == CODE_SECRET:
|
||||
print(" ✔ Code correct → désarmement")
|
||||
passer_en_desarmee()
|
||||
elif code != "":
|
||||
print(" ✘ Code incorrect — alarme maintenue")
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("\n[INFO] Arrêt demandé (Ctrl+C)")
|
||||
|
||||
finally:
|
||||
stop_pir.set()
|
||||
_stop_buzzer.set()
|
||||
led_off()
|
||||
GPIO.cleanup()
|
||||
print("[INFO] GPIO libérés. Fin du programme.")
|
||||
@@ -1,14 +1,10 @@
|
||||
import Adafruit_DHT as dht
|
||||
|
||||
# On définit juste le capteur et la broche (Rappel : 25 en BCM = broche physique 22)
|
||||
capteur = dht.DHT11
|
||||
pin = 25
|
||||
|
||||
def lire_temperature():
|
||||
humidite, temperature = dht.read_retry(capteur, pin)
|
||||
|
||||
# On renvoie la température au script principal !
|
||||
if temperature is not None:
|
||||
return temperature
|
||||
else:
|
||||
return 0 # Sécurité si le capteur bugge, pour ne pas faire planter l'affichage
|
||||
return 0
|
||||
12
composants/byPanda/LDR.py
Normal file
12
composants/byPanda/LDR.py
Normal file
@@ -0,0 +1,12 @@
|
||||
import RPi.GPIO as GPIO
|
||||
|
||||
LDR_PIN = 20
|
||||
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setup(LDR_PIN, GPIO.IN)
|
||||
|
||||
def lire_etat():
|
||||
if GPIO.input(LDR_PIN) == GPIO.HIGH:
|
||||
return "Nuit"
|
||||
return "Jour"
|
||||
@@ -1,246 +1,194 @@
|
||||
import time
|
||||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
import threading
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
# Configuration initiale
|
||||
GPIO.setmode(GPIO.BOARD) # Utilisation des numéros physiques des pins
|
||||
GPIO.setwarnings(False)
|
||||
|
||||
# --- CONFIGURATION PINS (BOARD) ---
|
||||
PIN_LED_R = 11
|
||||
PIN_LED_G = 15
|
||||
PIN_LED_B = 13
|
||||
PIN_PIR = 10
|
||||
PIN_BUZZER = 12
|
||||
|
||||
class SystemeAlarme:
|
||||
def __init__(self):
|
||||
"""
|
||||
Initialise les composants liés à l'alarme.
|
||||
# Pins Keypad (Vérifie bien tes branchements physiques sur ces numéros)
|
||||
ROWS = [29, 31, 33, 35]
|
||||
COLS = [37, 32, 36, 38]
|
||||
|
||||
Cette classe gère uniquement la logique locale de sécurité :
|
||||
- le capteur PIR
|
||||
- le buzzer
|
||||
- la LED RGB de statut
|
||||
- le clavier 4x4
|
||||
KEYPAD_MAP = [
|
||||
['1', '2', '3', 'A'],
|
||||
['4', '5', '6', 'B'],
|
||||
['7', '8', '9', 'C'],
|
||||
['*', '0', '#', 'D'],
|
||||
]
|
||||
|
||||
Elle ne dépend d'aucune autre partie du projet.
|
||||
"""
|
||||
CODE_SECRET = "1234"
|
||||
|
||||
# -----------------------------
|
||||
# Définition des pins physiques
|
||||
# -----------------------------
|
||||
self.pinPir = 15
|
||||
self.pinBuzzer = 18
|
||||
# --- INITIALISATION GPIO ---
|
||||
GPIO.setup(PIN_LED_R, GPIO.OUT, initial=GPIO.LOW)
|
||||
GPIO.setup(PIN_LED_G, GPIO.OUT, initial=GPIO.LOW)
|
||||
GPIO.setup(PIN_LED_B, GPIO.OUT, initial=GPIO.LOW)
|
||||
GPIO.setup(PIN_BUZZER, GPIO.OUT, initial=GPIO.LOW)
|
||||
GPIO.setup(PIN_PIR, GPIO.IN)
|
||||
|
||||
self.pinLedRouge = 17
|
||||
self.pinLedVerte = 27
|
||||
self.pinLedBleue = 22
|
||||
for row in ROWS:
|
||||
GPIO.setup(row, GPIO.OUT, initial=GPIO.HIGH)
|
||||
for col in COLS:
|
||||
GPIO.setup(col, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||
|
||||
# Clavier 4x4
|
||||
# 4 lignes + 4 colonnes
|
||||
self.lignes = [5, 6, 13, 19]
|
||||
self.colonnes = [26, 12, 16, 20]
|
||||
etat_alarme = "Désarmée"
|
||||
etat_lock = threading.Lock()
|
||||
|
||||
# Disposition classique d'un clavier 4x4
|
||||
self.touches = [
|
||||
["1", "2", "3", "A"],
|
||||
["4", "5", "6", "B"],
|
||||
["7", "8", "9", "C"],
|
||||
["*", "0", "#", "D"]
|
||||
]
|
||||
_stop_buzzer = threading.Event()
|
||||
_thread_buzzer = None
|
||||
|
||||
# -----------------------------
|
||||
# Variables de fonctionnement
|
||||
# -----------------------------
|
||||
self.codeSecret = "1234"
|
||||
self.codeSaisi = ""
|
||||
|
||||
# Etats possibles :
|
||||
# - desarme
|
||||
# - arme
|
||||
# - alarme
|
||||
self.etat = "desarme"
|
||||
|
||||
# Anti-rebond clavier
|
||||
self.derniereLecture = 0
|
||||
self.delaiLecture = 0.25
|
||||
def led(r=False, g=False, b=False):
|
||||
GPIO.output(PIN_LED_R, GPIO.HIGH if r else GPIO.LOW)
|
||||
GPIO.output(PIN_LED_G, GPIO.HIGH if g else GPIO.LOW)
|
||||
GPIO.output(PIN_LED_B, GPIO.HIGH if b else GPIO.LOW)
|
||||
|
||||
self.initialiserGPIO()
|
||||
self.mettreAJourEtat()
|
||||
def led_bleu(): led(b=True)
|
||||
def led_vert(): led(g=True)
|
||||
def led_rouge(): led(r=True)
|
||||
def led_off(): led()
|
||||
|
||||
def initialiserGPIO(self):
|
||||
"""Configure les broches du Raspberry Pi pour l'alarme."""
|
||||
GPIO.setup(self.pinPir, GPIO.IN)
|
||||
GPIO.setup(self.pinBuzzer, GPIO.OUT, initial=GPIO.LOW)
|
||||
def bip(nb=1, duree=0.08, pause=0.12):
|
||||
for _ in range(nb):
|
||||
GPIO.output(PIN_BUZZER, GPIO.HIGH)
|
||||
time.sleep(duree)
|
||||
GPIO.output(PIN_BUZZER, GPIO.LOW)
|
||||
time.sleep(pause)
|
||||
|
||||
GPIO.setup(self.pinLedRouge, GPIO.OUT, initial=GPIO.LOW)
|
||||
GPIO.setup(self.pinLedVerte, GPIO.OUT, initial=GPIO.LOW)
|
||||
GPIO.setup(self.pinLedBleue, GPIO.OUT, initial=GPIO.LOW)
|
||||
def _buzzer_continu(stop_event: threading.Event):
|
||||
while not stop_event.is_set():
|
||||
GPIO.output(PIN_BUZZER, GPIO.HIGH)
|
||||
time.sleep(0.5)
|
||||
GPIO.output(PIN_BUZZER, GPIO.LOW)
|
||||
time.sleep(0.5)
|
||||
GPIO.output(PIN_BUZZER, GPIO.LOW)
|
||||
|
||||
for pin in self.lignes:
|
||||
GPIO.setup(pin, GPIO.OUT, initial=GPIO.LOW)
|
||||
|
||||
for pin in self.colonnes:
|
||||
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
def lire_touche():
|
||||
|
||||
def definirCouleur(self, rouge, vert, bleu):
|
||||
"""
|
||||
Allume la LED RGB selon la couleur voulue.
|
||||
for i, row in enumerate(ROWS):
|
||||
GPIO.output(row, GPIO.LOW)
|
||||
time.sleep(0.01) # Stabilisation électrique
|
||||
for j, col in enumerate(COLS):
|
||||
if GPIO.input(col) == GPIO.LOW:
|
||||
time.sleep(0.05) # Anti-rebond
|
||||
while GPIO.input(col) == GPIO.LOW:
|
||||
time.sleep(0.01)
|
||||
GPIO.output(row, GPIO.HIGH)
|
||||
return KEYPAD_MAP[i][j]
|
||||
GPIO.output(row, GPIO.HIGH)
|
||||
return None
|
||||
|
||||
Paramètres :
|
||||
- rouge : True / False
|
||||
- vert : True / False
|
||||
- bleu : True / False
|
||||
"""
|
||||
GPIO.output(self.pinLedRouge, GPIO.HIGH if rouge else GPIO.LOW)
|
||||
GPIO.output(self.pinLedVerte, GPIO.HIGH if vert else GPIO.LOW)
|
||||
GPIO.output(self.pinLedBleue, GPIO.HIGH if bleu else GPIO.LOW)
|
||||
def lire_code(nb_chiffres=4, timeout=20):
|
||||
saisi = ""
|
||||
debut = time.time()
|
||||
print(" Entrez le code : ", end="", flush=True)
|
||||
while len(saisi) < nb_chiffres:
|
||||
if time.time() - debut > timeout:
|
||||
print("\n [Timeout]")
|
||||
return ""
|
||||
touche = lire_touche()
|
||||
if touche and touche.isdigit():
|
||||
saisi += touche
|
||||
bip(1, 0.05) # Petit bip de confirmation touche
|
||||
print("*", end="", flush=True)
|
||||
time.sleep(0.05)
|
||||
print()
|
||||
return saisi
|
||||
|
||||
def mettreAJourEtat(self):
|
||||
"""
|
||||
Met à jour les sorties selon l'état actuel du système.
|
||||
# --- GESTION DES ÉTATS ---
|
||||
|
||||
- desarme : LED verte, buzzer éteint
|
||||
- arme : LED bleue, buzzer éteint
|
||||
- alarme : LED rouge, buzzer allumé
|
||||
"""
|
||||
if self.etat == "desarme":
|
||||
self.definirCouleur(False, True, False)
|
||||
GPIO.output(self.pinBuzzer, GPIO.LOW)
|
||||
def passer_en_desarmee():
|
||||
global etat_alarme, _thread_buzzer
|
||||
_stop_buzzer.set()
|
||||
if _thread_buzzer and _thread_buzzer.is_alive():
|
||||
_thread_buzzer.join()
|
||||
with etat_lock:
|
||||
etat_alarme = "Désarmée"
|
||||
led_bleu()
|
||||
print("[ÉTAT] ● DÉSARMÉE")
|
||||
|
||||
elif self.etat == "arme":
|
||||
self.definirCouleur(False, False, True)
|
||||
GPIO.output(self.pinBuzzer, GPIO.LOW)
|
||||
def passer_en_armee():
|
||||
global etat_alarme
|
||||
with etat_lock:
|
||||
etat_alarme = "Armée"
|
||||
led_vert()
|
||||
bip(nb=2)
|
||||
print("[ÉTAT] ● ARMÉE")
|
||||
|
||||
elif self.etat == "alarme":
|
||||
self.definirCouleur(True, False, False)
|
||||
GPIO.output(self.pinBuzzer, GPIO.HIGH)
|
||||
def passer_en_declenchee():
|
||||
global etat_alarme, _thread_buzzer
|
||||
with etat_lock:
|
||||
# On ne déclenche que si on était armé
|
||||
if etat_alarme == "Armée":
|
||||
etat_alarme = "Déclenchée"
|
||||
led_rouge()
|
||||
print("[ÉTAT] ● DÉCLENCHÉE !")
|
||||
_stop_buzzer.clear()
|
||||
_thread_buzzer = threading.Thread(target=_buzzer_continu, args=(_stop_buzzer,), daemon=True)
|
||||
_thread_buzzer.start()
|
||||
|
||||
def armer(self):
|
||||
"""Passe le système en mode armé."""
|
||||
self.etat = "arme"
|
||||
self.codeSaisi = ""
|
||||
self.mettreAJourEtat()
|
||||
print("Alarme activée.")
|
||||
# --- SURVEILLANCE ---
|
||||
|
||||
def desarmer(self):
|
||||
"""Passe le système en mode désarmé."""
|
||||
self.etat = "desarme"
|
||||
self.codeSaisi = ""
|
||||
self.mettreAJourEtat()
|
||||
print("Alarme désactivée.")
|
||||
def _surveiller_pir(stop_evt: threading.Event):
|
||||
while not stop_evt.is_set():
|
||||
with etat_lock:
|
||||
local_etat = etat_alarme
|
||||
if local_etat == "Armée" and GPIO.input(PIN_PIR) == GPIO.HIGH:
|
||||
passer_en_declenchee()
|
||||
time.sleep(0.2)
|
||||
|
||||
def declencherAlarme(self):
|
||||
"""
|
||||
Déclenche l'alarme si un mouvement est détecté alors
|
||||
que le système est armé.
|
||||
"""
|
||||
if self.etat != "alarme":
|
||||
self.etat = "alarme"
|
||||
self.codeSaisi = ""
|
||||
self.mettreAJourEtat()
|
||||
print("Intrusion détectée : alarme déclenchée.")
|
||||
def boucle_principale():
|
||||
"""Lancée par board1main dans un thread."""
|
||||
passer_en_desarmee()
|
||||
|
||||
def lireClavier(self):
|
||||
"""
|
||||
Scanne le clavier 4x4.
|
||||
stop_pir = threading.Event()
|
||||
thread_pir = threading.Thread(target=_surveiller_pir, args=(stop_pir,), daemon=True)
|
||||
thread_pir.start()
|
||||
|
||||
Retour :
|
||||
- la touche détectée
|
||||
- None si aucune touche n'est pressée
|
||||
"""
|
||||
maintenant = time.time()
|
||||
print("\n=== Système d'alarme démarré ===")
|
||||
|
||||
if maintenant - self.derniereLecture < self.delaiLecture:
|
||||
return None
|
||||
try:
|
||||
while True:
|
||||
with etat_lock:
|
||||
current = etat_alarme
|
||||
|
||||
for indexLigne, ligne in enumerate(self.lignes):
|
||||
GPIO.output(ligne, GPIO.HIGH)
|
||||
# CAS 1 : L'alarme est éteinte, on attend le code pour l'allumer
|
||||
if current == "Désarmée":
|
||||
print(" [DÉSARMÉE] Entrez code pour ARMER...")
|
||||
code = lire_code(len(CODE_SECRET))
|
||||
if code == CODE_SECRET:
|
||||
passer_en_armee()
|
||||
elif code != "":
|
||||
bip(1, 0.5)
|
||||
|
||||
for indexColonne, colonne in enumerate(self.colonnes):
|
||||
if GPIO.input(colonne) == GPIO.HIGH:
|
||||
GPIO.output(ligne, GPIO.LOW)
|
||||
self.derniereLecture = maintenant
|
||||
# CAS 2 : L'alarme est allumée, on attend le code pour l'éteindre
|
||||
elif current == "Armée":
|
||||
# On réutilise lire_code ici pour permettre le désarmement manuel
|
||||
print(" [ARMÉE] Entrez code pour DÉSARMER...")
|
||||
code = lire_code(len(CODE_SECRET))
|
||||
if code == CODE_SECRET:
|
||||
passer_en_desarmee()
|
||||
elif code != "":
|
||||
bip(1, 0.5)
|
||||
|
||||
# Petite attente pour éviter la lecture multiple
|
||||
time.sleep(0.05)
|
||||
# CAS 3 : L'alarme sonne, on attend le code pour stopper le buzzer
|
||||
elif current == "Déclenchée":
|
||||
print(" [ALERTE] Entrez code pour STOPPER...")
|
||||
code = lire_code(len(CODE_SECRET))
|
||||
if code == CODE_SECRET:
|
||||
passer_en_desarmee()
|
||||
|
||||
return self.touches[indexLigne][indexColonne]
|
||||
|
||||
GPIO.output(ligne, GPIO.LOW)
|
||||
|
||||
return None
|
||||
|
||||
def validerCode(self):
|
||||
"""
|
||||
Vérifie le code saisi.
|
||||
|
||||
Si le code est correct :
|
||||
- alarme désarmée -> armée
|
||||
- alarme armée -> désarmée
|
||||
- alarme déclenchée -> désarmée
|
||||
|
||||
Si le code est faux :
|
||||
- on efface la saisie
|
||||
"""
|
||||
if self.codeSaisi == self.codeSecret:
|
||||
if self.etat == "desarme":
|
||||
self.armer()
|
||||
else:
|
||||
self.desarmer()
|
||||
else:
|
||||
print("Code incorrect.")
|
||||
self.codeSaisi = ""
|
||||
|
||||
def traiterClavier(self, touche):
|
||||
"""
|
||||
Gère la logique du clavier :
|
||||
- chiffres : ajout au code saisi
|
||||
- * : efface la saisie
|
||||
- # : valide le code
|
||||
"""
|
||||
if touche is None:
|
||||
return
|
||||
|
||||
print("Touche appuyée :", touche)
|
||||
|
||||
if touche == "*":
|
||||
self.codeSaisi = ""
|
||||
print("Saisie effacée.")
|
||||
return
|
||||
|
||||
if touche == "#":
|
||||
self.validerCode()
|
||||
return
|
||||
|
||||
if touche.isdigit():
|
||||
if len(self.codeSaisi) < 8:
|
||||
self.codeSaisi += touche
|
||||
print("Code en cours :", "*" * len(self.codeSaisi))
|
||||
|
||||
def surveillerPIR(self):
|
||||
"""
|
||||
Vérifie le capteur de mouvement.
|
||||
|
||||
Si un mouvement est détecté alors que l'alarme est armée,
|
||||
on passe en état d'alarme.
|
||||
"""
|
||||
mouvement = GPIO.input(self.pinPir) == GPIO.HIGH
|
||||
|
||||
if self.etat == "arme" and mouvement:
|
||||
self.declencherAlarme()
|
||||
|
||||
def mettreAJour(self):
|
||||
"""
|
||||
Fonction appelée en boucle dans le programme principal.
|
||||
|
||||
Elle :
|
||||
- lit le clavier
|
||||
- traite la touche appuyée
|
||||
- surveille le PIR
|
||||
- synchronise LED et buzzer avec l'état courant
|
||||
"""
|
||||
touche = self.lireClavier()
|
||||
self.traiterClavier(touche)
|
||||
self.surveillerPIR()
|
||||
self.mettreAJourEtat()
|
||||
|
||||
def cleanup(self):
|
||||
"""
|
||||
Remet les sorties dans un état propre à la fermeture.
|
||||
"""
|
||||
GPIO.output(self.pinBuzzer, GPIO.LOW)
|
||||
self.definirCouleur(False, False, False)
|
||||
time.sleep(0.1)
|
||||
finally:
|
||||
stop_pir.set()
|
||||
_stop_buzzer.set()
|
||||
led_off()
|
||||
246
composants/byPanda/alarme_test.py
Normal file
246
composants/byPanda/alarme_test.py
Normal file
@@ -0,0 +1,246 @@
|
||||
import time
|
||||
import RPi.GPIO as GPIO
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setwarnings(False)
|
||||
|
||||
|
||||
class SystemeAlarme:
|
||||
def __init__(self):
|
||||
"""
|
||||
Initialise les composants liés à l'alarme.
|
||||
|
||||
Cette classe gère uniquement la logique locale de sécurité :
|
||||
- le capteur PIR
|
||||
- le buzzer
|
||||
- la LED RGB de statut
|
||||
- le clavier 4x4
|
||||
|
||||
Elle ne dépend d'aucune autre partie du projet.
|
||||
"""
|
||||
|
||||
# -----------------------------
|
||||
# Définition des pins physiques
|
||||
# -----------------------------
|
||||
self.pinPir = 15
|
||||
self.pinBuzzer = 18
|
||||
|
||||
self.pinLedRouge = 17
|
||||
self.pinLedVerte = 27
|
||||
self.pinLedBleue = 22
|
||||
|
||||
# Clavier 4x4
|
||||
# 4 lignes + 4 colonnes
|
||||
self.lignes = [5, 6, 13, 19]
|
||||
self.colonnes = [26, 12, 16, 20]
|
||||
|
||||
# Disposition classique d'un clavier 4x4
|
||||
self.touches = [
|
||||
["1", "2", "3", "A"],
|
||||
["4", "5", "6", "B"],
|
||||
["7", "8", "9", "C"],
|
||||
["*", "0", "#", "D"]
|
||||
]
|
||||
|
||||
# -----------------------------
|
||||
# Variables de fonctionnement
|
||||
# -----------------------------
|
||||
self.codeSecret = "1234"
|
||||
self.codeSaisi = ""
|
||||
|
||||
# Etats possibles :
|
||||
# - desarme
|
||||
# - arme
|
||||
# - alarme
|
||||
self.etat = "desarme"
|
||||
|
||||
# Anti-rebond clavier
|
||||
self.derniereLecture = 0
|
||||
self.delaiLecture = 0.25
|
||||
|
||||
self.initialiserGPIO()
|
||||
self.mettreAJourEtat()
|
||||
|
||||
def initialiserGPIO(self):
|
||||
"""Configure les broches du Raspberry Pi pour l'alarme."""
|
||||
GPIO.setup(self.pinPir, GPIO.IN)
|
||||
GPIO.setup(self.pinBuzzer, GPIO.OUT, initial=GPIO.LOW)
|
||||
|
||||
GPIO.setup(self.pinLedRouge, GPIO.OUT, initial=GPIO.LOW)
|
||||
GPIO.setup(self.pinLedVerte, GPIO.OUT, initial=GPIO.LOW)
|
||||
GPIO.setup(self.pinLedBleue, GPIO.OUT, initial=GPIO.LOW)
|
||||
|
||||
for pin in self.lignes:
|
||||
GPIO.setup(pin, GPIO.OUT, initial=GPIO.LOW)
|
||||
|
||||
for pin in self.colonnes:
|
||||
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
|
||||
def definirCouleur(self, rouge, vert, bleu):
|
||||
"""
|
||||
Allume la LED RGB selon la couleur voulue.
|
||||
|
||||
Paramètres :
|
||||
- rouge : True / False
|
||||
- vert : True / False
|
||||
- bleu : True / False
|
||||
"""
|
||||
GPIO.output(self.pinLedRouge, GPIO.HIGH if rouge else GPIO.LOW)
|
||||
GPIO.output(self.pinLedVerte, GPIO.HIGH if vert else GPIO.LOW)
|
||||
GPIO.output(self.pinLedBleue, GPIO.HIGH if bleu else GPIO.LOW)
|
||||
|
||||
def mettreAJourEtat(self):
|
||||
"""
|
||||
Met à jour les sorties selon l'état actuel du système.
|
||||
|
||||
- desarme : LED verte, buzzer éteint
|
||||
- arme : LED bleue, buzzer éteint
|
||||
- alarme : LED rouge, buzzer allumé
|
||||
"""
|
||||
if self.etat == "desarme":
|
||||
self.definirCouleur(False, True, False)
|
||||
GPIO.output(self.pinBuzzer, GPIO.LOW)
|
||||
|
||||
elif self.etat == "arme":
|
||||
self.definirCouleur(False, False, True)
|
||||
GPIO.output(self.pinBuzzer, GPIO.LOW)
|
||||
|
||||
elif self.etat == "alarme":
|
||||
self.definirCouleur(True, False, False)
|
||||
GPIO.output(self.pinBuzzer, GPIO.HIGH)
|
||||
|
||||
def armer(self):
|
||||
"""Passe le système en mode armé."""
|
||||
self.etat = "arme"
|
||||
self.codeSaisi = ""
|
||||
self.mettreAJourEtat()
|
||||
print("Alarme activée.")
|
||||
|
||||
def desarmer(self):
|
||||
"""Passe le système en mode désarmé."""
|
||||
self.etat = "desarme"
|
||||
self.codeSaisi = ""
|
||||
self.mettreAJourEtat()
|
||||
print("Alarme désactivée.")
|
||||
|
||||
def declencherAlarme(self):
|
||||
"""
|
||||
Déclenche l'alarme si un mouvement est détecté alors
|
||||
que le système est armé.
|
||||
"""
|
||||
if self.etat != "alarme":
|
||||
self.etat = "alarme"
|
||||
self.codeSaisi = ""
|
||||
self.mettreAJourEtat()
|
||||
print("Intrusion détectée : alarme déclenchée.")
|
||||
|
||||
def lireClavier(self):
|
||||
"""
|
||||
Scanne le clavier 4x4.
|
||||
|
||||
Retour :
|
||||
- la touche détectée
|
||||
- None si aucune touche n'est pressée
|
||||
"""
|
||||
maintenant = time.time()
|
||||
|
||||
if maintenant - self.derniereLecture < self.delaiLecture:
|
||||
return None
|
||||
|
||||
for indexLigne, ligne in enumerate(self.lignes):
|
||||
GPIO.output(ligne, GPIO.HIGH)
|
||||
|
||||
for indexColonne, colonne in enumerate(self.colonnes):
|
||||
if GPIO.input(colonne) == GPIO.HIGH:
|
||||
GPIO.output(ligne, GPIO.LOW)
|
||||
self.derniereLecture = maintenant
|
||||
|
||||
# Petite attente pour éviter la lecture multiple
|
||||
time.sleep(0.05)
|
||||
|
||||
return self.touches[indexLigne][indexColonne]
|
||||
|
||||
GPIO.output(ligne, GPIO.LOW)
|
||||
|
||||
return None
|
||||
|
||||
def validerCode(self):
|
||||
"""
|
||||
Vérifie le code saisi.
|
||||
|
||||
Si le code est correct :
|
||||
- alarme désarmée -> armée
|
||||
- alarme armée -> désarmée
|
||||
- alarme déclenchée -> désarmée
|
||||
|
||||
Si le code est faux :
|
||||
- on efface la saisie
|
||||
"""
|
||||
if self.codeSaisi == self.codeSecret:
|
||||
if self.etat == "desarme":
|
||||
self.armer()
|
||||
else:
|
||||
self.desarmer()
|
||||
else:
|
||||
print("Code incorrect.")
|
||||
self.codeSaisi = ""
|
||||
|
||||
def traiterClavier(self, touche):
|
||||
"""
|
||||
Gère la logique du clavier :
|
||||
- chiffres : ajout au code saisi
|
||||
- * : efface la saisie
|
||||
- # : valide le code
|
||||
"""
|
||||
if touche is None:
|
||||
return
|
||||
|
||||
print("Touche appuyée :", touche)
|
||||
|
||||
if touche == "*":
|
||||
self.codeSaisi = ""
|
||||
print("Saisie effacée.")
|
||||
return
|
||||
|
||||
if touche == "#":
|
||||
self.validerCode()
|
||||
return
|
||||
|
||||
if touche.isdigit():
|
||||
if len(self.codeSaisi) < 8:
|
||||
self.codeSaisi += touche
|
||||
print("Code en cours :", "*" * len(self.codeSaisi))
|
||||
|
||||
def surveillerPIR(self):
|
||||
"""
|
||||
Vérifie le capteur de mouvement.
|
||||
|
||||
Si un mouvement est détecté alors que l'alarme est armée,
|
||||
on passe en état d'alarme.
|
||||
"""
|
||||
mouvement = GPIO.input(self.pinPir) == GPIO.HIGH
|
||||
|
||||
if self.etat == "arme" and mouvement:
|
||||
self.declencherAlarme()
|
||||
|
||||
def mettreAJour(self):
|
||||
"""
|
||||
Fonction appelée en boucle dans le programme principal.
|
||||
|
||||
Elle :
|
||||
- lit le clavier
|
||||
- traite la touche appuyée
|
||||
- surveille le PIR
|
||||
- synchronise LED et buzzer avec l'état courant
|
||||
"""
|
||||
touche = self.lireClavier()
|
||||
self.traiterClavier(touche)
|
||||
self.surveillerPIR()
|
||||
self.mettreAJourEtat()
|
||||
|
||||
def cleanup(self):
|
||||
"""
|
||||
Remet les sorties dans un état propre à la fermeture.
|
||||
"""
|
||||
GPIO.output(self.pinBuzzer, GPIO.LOW)
|
||||
self.definirCouleur(False, False, False)
|
||||
@@ -1,36 +1,27 @@
|
||||
import time
|
||||
from ALARM_V1 import *
|
||||
import threading
|
||||
import alarme
|
||||
from porterfid import SystemePorteRFID
|
||||
import RPi.GPIO as GPIO
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# board1main.py
|
||||
# ------------------------------------------------------------
|
||||
# Ce fichier lance uniquement la logique locale de la board 1.
|
||||
# Il ne dépend pas du site web, de la base de données ni de Flask.
|
||||
# Son rôle est simplement de faire tourner :
|
||||
# - le système d'alarme
|
||||
# - le système de porte RFID
|
||||
# ------------------------------------------------------------
|
||||
|
||||
alarme = SystemeAlarme()
|
||||
porte = SystemePorteRFID()
|
||||
|
||||
|
||||
|
||||
def call_board1():
|
||||
# 1. On lance l'alarme dans son propre thread pour qu'elle ne bloque pas le reste
|
||||
thread_alarme = threading.Thread(target=alarme.boucle_principale, daemon=True)
|
||||
thread_alarme.start()
|
||||
|
||||
print("[BOARD 1] Système d'alarme lancé en arrière-plan.")
|
||||
|
||||
try:
|
||||
# 2. La boucle principale ne gère plus que le RFID
|
||||
while True:
|
||||
# Mise à jour des deux modules locaux
|
||||
ALARM_V1.boucle_principale()
|
||||
porte.mettreAJour()
|
||||
time.sleep(0.05)
|
||||
time.sleep(0.3)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
porte.cleanup()
|
||||
alarme.cleanup()
|
||||
print("\nArrêt manuel du programme.")
|
||||
|
||||
finally:
|
||||
# On remet les sorties dans un état propre avant de quitter
|
||||
alarme.cleanup()
|
||||
# On utilise GPIO.cleanup() directement car alarme.cleanup n'existe pas
|
||||
porte.cleanup()
|
||||
GPIO.cleanup()
|
||||
@@ -35,7 +35,7 @@ def test_boutons():
|
||||
|
||||
afficher_temperature(temperature_DHT, temperature_cible)
|
||||
etatPrecedent_up = etat_up
|
||||
-
|
||||
|
||||
if etat_down != etatPrecedent_down:
|
||||
if etat_down == 0:
|
||||
print("Bouton DOWN Appuyé ⬇️")
|
||||
@@ -48,9 +48,3 @@ def test_boutons():
|
||||
|
||||
t.sleep(0.05)
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
test_boutons()
|
||||
except KeyboardInterrupt:
|
||||
print("\nFin du test")
|
||||
GPIO.cleanup()
|
||||
@@ -1,43 +1,12 @@
|
||||
import RPi.GPIO as GPIO
|
||||
import time as t
|
||||
|
||||
GPIO.setmode(GPIO.BOARD)
|
||||
GPIO.setwarnings(False)
|
||||
servo = 12
|
||||
GPIO.setup(servo, GPIO.OUT)
|
||||
LDR_PIN = 20
|
||||
|
||||
pwm = GPIO.PWM(servo, 50)
|
||||
pwm.start(0)
|
||||
bouton_up = 13
|
||||
bouton_down = 36
|
||||
GPIO.setup(bouton_up, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||
GPIO.setup(bouton_down, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||
def setup_ldr():
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setup(LDR_PIN, GPIO.IN)
|
||||
|
||||
def test_boutons():
|
||||
etatPrecedent_up = GPIO.input(bouton_up)
|
||||
etatPrecedent_down = GPIO.input(bouton_down)
|
||||
|
||||
print("Test lancé ! Appuie sur UP (23) pour monter, DOWN (24) pour descendre.")
|
||||
|
||||
while True:
|
||||
etat_up = GPIO.input(bouton_up)
|
||||
etat_down = GPIO.input(bouton_down)
|
||||
if etat_up != etatPrecedent_up:
|
||||
if etat_up == 0:
|
||||
print("Bouton UP Appuyé ⬆️")
|
||||
print("Volet ouvert")
|
||||
pwm.ChangeDutyCycle(2)
|
||||
etatPrecedent_up = etat_up
|
||||
if etat_down != etatPrecedent_down:
|
||||
if etat_down == 0:
|
||||
print("Bouton DOWN Appuyé ⬇️")
|
||||
print("Volet fermé")
|
||||
pwm.ChangeDutyCycle(7)
|
||||
etatPrecedent_down = etat_down
|
||||
t.sleep(0.05)
|
||||
|
||||
if name == "main":
|
||||
try:
|
||||
test_boutons()
|
||||
except KeyboardInterrupt:
|
||||
print("\nFin du test")
|
||||
def lire_etat():
|
||||
if GPIO.input(LDR_PIN) == GPIO.HIGH:
|
||||
return "Nuit"
|
||||
return "Jour"
|
||||
15
composants/byPanda/ledRGB.py
Normal file
15
composants/byPanda/ledRGB.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import RPi.GPIO as GPIO
|
||||
import time as t
|
||||
|
||||
GPIO.setmode(GPIO.BOARD)
|
||||
|
||||
r, g, b = 11, 13, 15
|
||||
|
||||
GPIO.setup(r, GPIO.OUT)
|
||||
GPIO.setup(g, GPIO.OUT)
|
||||
GPIO.setup(b, GPIO.OUT)
|
||||
|
||||
while True:
|
||||
GPIO.output(r, 1); t.sleep(1); GPIO.output(r, 0)
|
||||
GPIO.output(g, 1); t.sleep(1); GPIO.output(g, 0)
|
||||
GPIO.output(b, 1); t.sleep(1); GPIO.output(b, 0)
|
||||
@@ -1,26 +0,0 @@
|
||||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
|
||||
# Configuration
|
||||
LDR_PIN = 20# Broche GPIO connectée au circuit LDR
|
||||
SEUIL = 500 # Valeur de seuil à ajuster (0-1024)
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setup(LDR_PIN, GPIO.IN)
|
||||
|
||||
|
||||
def lire_ldr():
|
||||
# Simulation de lecture analogique (nécessite MCP3008 ou circuit RC)
|
||||
# Pour cet exemple, on simplifie par une lecture numérique
|
||||
return GPIO.input(LDR_PIN)
|
||||
|
||||
try:
|
||||
while True:
|
||||
luminosite = lire_ldr()
|
||||
if luminosite < SEUIL:
|
||||
print("Nuit : Allumage lumière")
|
||||
else:
|
||||
print("Jour : Extinction lumière")
|
||||
time.sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
GPIO.cleanup()
|
||||
@@ -18,9 +18,14 @@ current_user = None
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
composants = os.path.join(BASE_DIR, "composants", "byPanda")
|
||||
sys.path.insert(0, composants)
|
||||
from alarme import SystemeAlarme
|
||||
|
||||
from lumieres import SystemeLumieres
|
||||
from board1main import *
|
||||
from board1main import call_board1
|
||||
import alarme
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def index():
|
||||
@@ -76,10 +81,13 @@ def check_rfid_login():
|
||||
return jsonify({"success": True, "username": user})
|
||||
|
||||
return jsonify({"success": False})
|
||||
"""
|
||||
@app.route("/alarme",methods=["POST"])
|
||||
def armer_alarme():
|
||||
SystemeAlarme.armer()
|
||||
return jsonify({"success": True})
|
||||
|
||||
"""
|
||||
@app.route("/admin")
|
||||
def admin_page():
|
||||
return render_template("admin.html")
|
||||
@@ -87,8 +95,6 @@ def admin_page():
|
||||
@app.route("/admin/logs")
|
||||
def logs_page():
|
||||
return render_template("log.html")
|
||||
|
||||
|
||||
@app.route("/admin/logs/data")
|
||||
def get_logs():
|
||||
try:
|
||||
@@ -114,32 +120,29 @@ def get_users():
|
||||
users = auth.get_users()
|
||||
return jsonify({"success": True, "users": users})
|
||||
|
||||
@app.route("/alarme_status")
|
||||
def get_alarme_status_info(): # Nom différent de l'import 'alarme'
|
||||
try:
|
||||
# On accède à la variable du fichier
|
||||
statut = alarme.etat_alarme
|
||||
return jsonify({"success": True, "status": statut})
|
||||
except Exception as e:
|
||||
return jsonify({"success": False, "message": str(e)}), 500
|
||||
|
||||
@app.route("/api/<action>", methods=["GET"])
|
||||
def relais_pi2(action):
|
||||
url_pi2 = f"https://pi32.local:8000/{action}"
|
||||
print(f"\n[RELAIS] 1. Tentative de contact avec le Pi 2 : {url_pi2}")
|
||||
|
||||
try:
|
||||
reponse = requests.get(url_pi2, timeout=5, verify=False)
|
||||
print(f"[RELAIS] 2. Code HTTP reçu du Pi 2 : {reponse.status_code}")
|
||||
print(f"[RELAIS] 3. Texte brut reçu du Pi 2 : {reponse.text}")
|
||||
if not reponse.ok:
|
||||
return jsonify({
|
||||
"success": False,
|
||||
"message": f"Le Pi 2 a refusé la requête (Code {reponse.status_code})"
|
||||
}), reponse.status_code
|
||||
return jsonify({"success": False, "message": "Erreur Pi 2"}), reponse.status_code
|
||||
|
||||
# Si tout va bien, on tente d'extraire le JSON
|
||||
try:
|
||||
data = reponse.json()
|
||||
return jsonify(data)
|
||||
except ValueError:
|
||||
print("[RELAIS] 4. ERREUR : Le Pi 2 n'a pas renvoyé de JSON valide.")
|
||||
return jsonify({"success": False, "message": "Réponse invalide du Pi 2"}), 502
|
||||
return jsonify(reponse.json())
|
||||
|
||||
except Exception as e:
|
||||
print(f"[RELAIS] ERREUR CRITIQUE : Impossible de joindre le Pi 2. Raison : {e}")
|
||||
return jsonify({"success": False, "message": f"Erreur de connexion : {str(e)}"}), 500
|
||||
# On ne garde que l'erreur si vraiment ça plante
|
||||
print(f"[RELAIS] ERREUR : {e}")
|
||||
return jsonify({"success": False, "message": str(e)}), 500
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -5,204 +5,38 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||
<title>Loustiques Home — Dashboard</title>
|
||||
<style>
|
||||
/* Style conservé pour l'interface sombre et moderne */
|
||||
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
|
||||
body {
|
||||
font-family: system-ui, sans-serif;
|
||||
background: #1f1f1f;
|
||||
color: #f0f0f0;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 18px 32px;
|
||||
border-bottom: 1px solid #2e2e2e;
|
||||
background: #1a1a1a;
|
||||
}
|
||||
|
||||
.logo {
|
||||
font-size: 17px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.header-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.status-dot {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 12px;
|
||||
color: #888;
|
||||
}
|
||||
|
||||
.dot {
|
||||
width: 7px;
|
||||
height: 7px;
|
||||
border-radius: 50%;
|
||||
background: #4ade80;
|
||||
animation: pulse 2s infinite;
|
||||
}
|
||||
|
||||
body { font-family: system-ui, sans-serif; background: #1f1f1f; color: #f0f0f0; min-height: 100vh; }
|
||||
header { display: flex; align-items: center; justify-content: space-between; padding: 18px 32px; border-bottom: 1px solid #2e2e2e; background: #1a1a1a; }
|
||||
.logo { font-size: 17px; font-weight: 700; }
|
||||
.header-right { display: flex; align-items: center; gap: 20px; }
|
||||
.status-dot { display: flex; align-items: center; gap: 8px; font-size: 12px; color: #888; }
|
||||
.dot { width: 7px; height: 7px; border-radius: 50%; background: #4ade80; animation: pulse 2s infinite; }
|
||||
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
|
||||
|
||||
.logout {
|
||||
font-family: inherit;
|
||||
font-size: 12px;
|
||||
color: #888;
|
||||
background: none;
|
||||
border: 1px solid #3a3a3a;
|
||||
padding: 6px 14px;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
transition: color 0.15s, border-color 0.15s;
|
||||
}
|
||||
.logout { font-family: inherit; font-size: 12px; color: #888; background: none; border: 1px solid #3a3a3a; padding: 6px 14px; border-radius: 6px; cursor: pointer; transition: color 0.15s, border-color 0.15s; }
|
||||
.logout:hover { color: #f0f0f0; border-color: #666; }
|
||||
|
||||
main {
|
||||
max-width: 1100px;
|
||||
margin: 0 auto;
|
||||
padding: 36px 32px;
|
||||
}
|
||||
|
||||
.welcome {
|
||||
margin-bottom: 36px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.welcome .label {
|
||||
font-size: 14px;
|
||||
letter-spacing: 0.15em;
|
||||
text-transform: uppercase;
|
||||
color: #2563eb;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.welcome h1 {
|
||||
font-size: 30px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
|
||||
gap: 14px;
|
||||
margin-bottom: 32px;
|
||||
}
|
||||
|
||||
.card {
|
||||
background: #2a2a2a;
|
||||
border: 1px solid #333;
|
||||
border-radius: 8px;
|
||||
padding: 22px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.card-label {
|
||||
font-size: 11px;
|
||||
letter-spacing: 0.1em;
|
||||
text-transform: uppercase;
|
||||
color: #888;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.card-value {
|
||||
font-size: 22px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.card-sub {
|
||||
font-size: 12px;
|
||||
color: #666;
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
.card-icon {
|
||||
position: absolute;
|
||||
top: 20px;
|
||||
right: 20px;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
opacity: 0.15;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 11px;
|
||||
letter-spacing: 0.15em;
|
||||
text-transform: uppercase;
|
||||
color: #666;
|
||||
margin-bottom: 14px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
main { max-width: 1100px; margin: 0 auto; padding: 36px 32px; }
|
||||
.welcome { margin-bottom: 36px; text-align: center; }
|
||||
.welcome .label { font-size: 14px; letter-spacing: 0.15em; text-transform: uppercase; color: #2563eb; margin-bottom: 8px; }
|
||||
.welcome h1 { font-size: 30px; font-weight: 700; }
|
||||
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-bottom: 32px; }
|
||||
.card { background: #2a2a2a; border: 1px solid #333; border-radius: 8px; padding: 22px; position: relative; }
|
||||
.card-label { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: #888; margin-bottom: 10px; }
|
||||
.card-value { font-size: 22px; font-weight: 700; }
|
||||
.card-sub { font-size: 12px; color: #666; margin-top: 6px; }
|
||||
.card-icon { position: absolute; top: 20px; right: 20px; width: 28px; height: 28px; opacity: 0.15; }
|
||||
.section-title { font-size: 11px; letter-spacing: 0.15em; text-transform: uppercase; color: #666; margin-bottom: 14px; display: flex; align-items: center; gap: 10px; }
|
||||
.section-title::after { content: ''; flex: 1; height: 1px; background: #2e2e2e; }
|
||||
|
||||
.actions {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
background: #2a2a2a;
|
||||
border: 1px solid #333;
|
||||
border-radius: 8px;
|
||||
padding: 18px 20px;
|
||||
cursor: pointer;
|
||||
text-align: left;
|
||||
color: #f0f0f0;
|
||||
position: relative;
|
||||
transition: border-color 0.15s, background 0.15s;
|
||||
}
|
||||
.actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
|
||||
.action-btn { background: #2a2a2a; border: 1px solid #333; border-radius: 8px; padding: 18px 20px; cursor: pointer; text-align: left; color: #f0f0f0; position: relative; transition: border-color 0.15s, background 0.15s; }
|
||||
.action-btn:hover { border-color: #2563eb; background: #2e2e3a; }
|
||||
.action-btn:active { transform: scale(0.98); }
|
||||
|
||||
.action-btn .a-label {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
display: block;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
.action-btn .a-sub {
|
||||
font-size: 12px;
|
||||
color: #ffffff;
|
||||
}
|
||||
.action-btn .a-arrow {
|
||||
position: absolute;
|
||||
right: 16px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
color: #555;
|
||||
font-size: 18px;
|
||||
transition: color 0.15s, right 0.15s;
|
||||
}
|
||||
.action-btn .a-label { font-size: 14px; font-weight: 600; display: block; margin-bottom: 4px; }
|
||||
.action-btn .a-sub { font-size: 12px; color: #ffffff; }
|
||||
.action-btn .a-arrow { position: absolute; right: 16px; top: 50%; transform: translateY(-50%); color: #555; font-size: 18px; transition: color 0.15s, right 0.15s; }
|
||||
.action-btn:hover .a-arrow { color: #2563eb; right: 12px; }
|
||||
|
||||
.toast {
|
||||
position: fixed;
|
||||
bottom: 24px;
|
||||
right: 24px;
|
||||
background: #2a2a2a;
|
||||
border: 1px solid #333;
|
||||
border-radius: 8px;
|
||||
padding: 12px 18px;
|
||||
font-size: 13px;
|
||||
color: #f0f0f0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
transform: translateY(20px);
|
||||
opacity: 0;
|
||||
transition: transform 0.3s, opacity 0.3s;
|
||||
z-index: 100;
|
||||
}
|
||||
.toast { position: fixed; bottom: 24px; right: 24px; background: #2a2a2a; border: 1px solid #333; border-radius: 8px; padding: 12px 18px; font-size: 13px; color: #f0f0f0; display: flex; align-items: center; gap: 10px; transform: translateY(20px); opacity: 0; transition: transform 0.3s, opacity 0.3s; z-index: 100; }
|
||||
.toast.show { transform: translateY(0); opacity: 1; }
|
||||
.toast-dot { width: 6px; height: 6px; border-radius: 50%; background: #4ade80; flex-shrink: 0; }
|
||||
</style>
|
||||
@@ -224,66 +58,74 @@
|
||||
</div>
|
||||
|
||||
<div class="grid">
|
||||
<div class="card">
|
||||
<svg class="card-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/><polyline points="9 22 9 12 15 12 15 22"/></svg>
|
||||
<div class="card-label">Statut</div>
|
||||
<div class="card-value" style="color:#4ade80;">En ligne</div>
|
||||
<div class="card-sub">Serveur opérationnel</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<svg class="card-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>
|
||||
<div class="card-label">Heure locale</div>
|
||||
<div class="card-value" id="clock">--:--</div>
|
||||
<div class="card-sub" id="date-display">--</div></div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-label">Température</div>
|
||||
<div class="card-value" id="temp-display">-- °C</div>
|
||||
|
||||
|
||||
<div class="card"></div>
|
||||
<div class="card-label">Porte</div>
|
||||
<div class="card-sub" id="date-display">--</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<svg class="card-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><rect x="2" y="3" width="20" height="14" rx="2"/><line x1="8" y1="21" x2="16" y2="21"/><line x1="12" y1="17" x2="12" y2="21"/></svg>
|
||||
<div class="card-label">Raspberry Pi 1 (actuelle)</div>
|
||||
<div class="card-value" style="color:green;">Actif</div>
|
||||
<div class="card-sub">Flask 3.1</div>
|
||||
<svg class="card-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/></svg>
|
||||
<div class="card-label">Température</div>
|
||||
<div class="card-value" id="temp-display">-- °C</div>
|
||||
<div class="card-sub">Capteur DHT11 (Pi 2)</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<svg class="card-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><rect x="2" y="3" width="20" height="14" rx="2"/><line x1="8" y1="21" x2="16" y2="21"/><line x1="12" y1="17" x2="12" y2="21"/></svg>
|
||||
<div class="card-label">Raspberry Pi 2 distant </div>
|
||||
<div class="card-value" style="color:green;">Actif</div>
|
||||
<div class="card-sub">FastAPi</div>
|
||||
</div>
|
||||
<svg class="card-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
|
||||
<path d="M12 3v1m0 16v1m9-9h-1M4 12H3m15.364-6.364l-.707.707M6.343 17.657l-.707.707m12.728 0l-.707-.707M6.343 6.343l-.707-.707M12 8a4 4 0 100 8 4 4 0 000-8z"/>
|
||||
</svg>
|
||||
<div class="card-label">Luminosité</div>
|
||||
<div class="card-value" id="ldr-display">--</div>
|
||||
<div class="card-sub">Capteur LDR (Pi 2)</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<svg class="card-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M23 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/></svg>
|
||||
<div class="card-label">Session</div>
|
||||
<div class="card-value" style="color: green;">Authentifiée</div>
|
||||
<div class="card-sub">Accès autorisé</div>
|
||||
<svg class="card-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect><line x1="9" y1="3" x2="9" y2="21"></line></svg>
|
||||
<div class="card-label">Porte / Volet</div>
|
||||
<div class="card-value" id="door-display">--</div>
|
||||
<div class="card-sub">État du moteur (Pi 2)</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<svg class="card-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/></svg>
|
||||
<div class="card-label">Alarme</div>
|
||||
<div class="card-value" id="alarm-display">--</div>
|
||||
<div class="card-sub">Sécurité (Pi 1)</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<svg class="card-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><rect x="2" y="3" width="20" height="14" rx="2"/><line x1="8" y1="21" x2="16" y2="21"/><line x1="12" y1="17" x2="12" y2="21"/></svg>
|
||||
<div class="card-label">Raspberry Pi 1</div>
|
||||
<div class="card-value" id="status-pi44">Vérification...</div>
|
||||
<div class="card-sub">Serveur Flask</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<svg class="card-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><rect x="2" y="3" width="20" height="14" rx="2"/><line x1="8" y1="21" x2="16" y2="21"/><line x1="12" y1="17" x2="12" y2="21"/></svg>
|
||||
<div class="card-label">Raspberry Pi 2</div>
|
||||
<div class="card-value" id="status-pi32">Vérification...</div>
|
||||
<div class="card-sub">Serveur FastAPI</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section-title">Actions rapides</div>
|
||||
|
||||
<div class="actions">
|
||||
<button class="action-btn" onclick="call_led_up()">
|
||||
<span class="a-label">💡 UP LED</span>
|
||||
<span class="a-sub">Allumer la LED</span>
|
||||
<span class="a-sub">Allumer la LED (Pi 2)</span>
|
||||
<span class="a-arrow">›</span>
|
||||
</button>
|
||||
<button class="action-btn" onclick="call_led_down()">
|
||||
|
||||
<button class="action-btn" onclick="call_led_down()">
|
||||
<span class="a-label">💡 DOWN LED</span>
|
||||
<span class="a-sub">Éteindre la led</span>
|
||||
<span class="a-arrow">›</span></button>
|
||||
<button class="action-btn" onclick="callAlarm()">
|
||||
<span class="a-label">🚨 Alarme</span>
|
||||
<span class="a-sub">Désarmer l'alarme</span>
|
||||
<span class="a-arrow">›</span></button>
|
||||
<span class="a-sub">Éteindre la LED (Pi 2)</span>
|
||||
<span class="a-arrow">›</span>
|
||||
</button>
|
||||
|
||||
<button class="action-btn" onclick="go_admin()">
|
||||
<span class="a-label">Administration</span>
|
||||
<span class="a-sub">Administrer les loustiques</span>
|
||||
<span class="a-sub">Gérer les utilisateurs</span>
|
||||
<span class="a-arrow">›</span>
|
||||
</button>
|
||||
</div>
|
||||
@@ -297,78 +139,89 @@
|
||||
<script>
|
||||
function updateClock() {
|
||||
const now = new Date();
|
||||
document.getElementById("clock").textContent =
|
||||
now.toLocaleTimeString("fr-FR", { hour: "2-digit", minute: "2-digit" });
|
||||
document.getElementById("date-display").textContent =
|
||||
now.toLocaleDateString("fr-FR", { weekday: "long", day: "numeric", month: "long" });
|
||||
document.getElementById("clock").textContent = now.toLocaleTimeString("fr-FR", { hour: "2-digit", minute: "2-digit" });
|
||||
document.getElementById("date-display").textContent = now.toLocaleDateString("fr-FR", { weekday: "long", day: "numeric", month: "long" });
|
||||
}
|
||||
updateClock();
|
||||
setInterval(updateClock, 1000);
|
||||
updateClock();
|
||||
async function updateAll() {
|
||||
console.log("Rafraîchissement des données...");
|
||||
|
||||
|
||||
/*
|
||||
async function callAlarm() {
|
||||
try {
|
||||
const res = await fetch('/alarme', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
});
|
||||
showToast("alarme activée !");
|
||||
} catch {
|
||||
showToast("Erreur lors de l'appel alarme.");
|
||||
}*/
|
||||
const resA = await fetch('/alarme_status');
|
||||
const dataA = await resA.json();
|
||||
const elA = document.getElementById("alarm-display");
|
||||
const elS1 = document.getElementById("status-pi44");
|
||||
|
||||
async function get_temperature() {
|
||||
try {
|
||||
const res = await fetch('/api/temperature', {
|
||||
method: 'GET',
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
});
|
||||
|
||||
const data = await res.json();
|
||||
|
||||
|
||||
if (data.success) {
|
||||
document.getElementById("temp-display").textContent = data.temperature + " °C";
|
||||
} else {
|
||||
document.getElementById("temp-display").textContent = "Erreur";
|
||||
console.error("Erreur de température :", data.message);
|
||||
if (dataA.success) {
|
||||
elA.textContent = dataA.status;
|
||||
elA.style.color = (dataA.status === "desarmee") ? "#4ade80" : "#f87171";
|
||||
elS1.textContent = "Actif";
|
||||
elS1.style.color = "#4ade80";
|
||||
}
|
||||
} catch (e) {
|
||||
document.getElementById("temp-display").textContent = "Hors ligne";
|
||||
console.error("Impossible de joindre le relais pour la température.");
|
||||
document.getElementById("status-pi44").textContent = "Hors ligne";
|
||||
document.getElementById("status-pi44").style.color = "#f87171";
|
||||
}
|
||||
}
|
||||
get_temperature();
|
||||
setInterval(get_temperature, 60000);
|
||||
async function call_led_down() {
|
||||
try {
|
||||
const res = await fetch('/api/down_led', {
|
||||
method: 'GET',
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
});
|
||||
showToast("led activée !");
|
||||
} catch {
|
||||
showToast("Erreur lors de l'appel board1.");
|
||||
}}
|
||||
const resL = await fetch('/api/luminosite');
|
||||
const dataL = await resL.json();
|
||||
const elL = document.getElementById("ldr-display");
|
||||
|
||||
if (dataL.success) {
|
||||
elL.textContent = dataL.status;
|
||||
elL.style.color = (dataL.status === "Jour") ? "#fbbf24" : "#818cf8";
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("Erreur de lecture luminosité");
|
||||
document.getElementById("ldr-display").textContent = "Erreur";
|
||||
}
|
||||
|
||||
try {
|
||||
const resV = await fetch('/api/volet_status');
|
||||
const dataV = await resV.json();
|
||||
const elV = document.getElementById("door-display");
|
||||
const elS2 = document.getElementById("status-pi32");
|
||||
|
||||
if (dataV.success) {
|
||||
elV.textContent = dataV.status;
|
||||
elV.style.color = (dataV.status === "Ouvert") ? "#4ade80" : "#f87171";
|
||||
elS2.textContent = "Actif";
|
||||
elS2.style.color = "#4ade80";
|
||||
} else {
|
||||
elS2.textContent = "Injoignable";
|
||||
elS2.style.color = "#fbbf24";
|
||||
}
|
||||
} catch (e) {
|
||||
document.getElementById("status-pi32").textContent = "Hors ligne";
|
||||
document.getElementById("status-pi32").style.color = "#f87171";
|
||||
}
|
||||
try {
|
||||
const resT = await fetch('/api/temperature');
|
||||
const dataT = await resT.json();
|
||||
if (dataT.success) {
|
||||
document.getElementById("temp-display").textContent = dataT.temperature + " °C";
|
||||
}
|
||||
} catch (e) {
|
||||
document.getElementById("temp-display").textContent = "-- °C";
|
||||
}
|
||||
}
|
||||
setInterval(updateAll, 15000);
|
||||
updateAll();
|
||||
async function call_led_up() {
|
||||
try {
|
||||
const res = await fetch('/api/up_led', {
|
||||
method: 'GET',
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
});
|
||||
await fetch('/api/up_led');
|
||||
showToast("LED allumée !");
|
||||
} catch {
|
||||
showToast("Erreur lors de l'appel Pi 2.");
|
||||
}
|
||||
} catch { showToast("Erreur Pi 2"); }
|
||||
}
|
||||
|
||||
|
||||
function go_admin() {
|
||||
window.location.href = "/admin";
|
||||
async function call_led_down() {
|
||||
try {
|
||||
await fetch('/api/down_led');
|
||||
showToast("LED éteinte !");
|
||||
} catch { showToast("Erreur Pi 2"); }
|
||||
}
|
||||
|
||||
function go_admin() { window.location.href = "/admin"; }
|
||||
function showToast(msg) {
|
||||
const toast = document.getElementById("toast");
|
||||
document.getElementById("toast-text").textContent = msg;
|
||||
|
||||
Reference in New Issue
Block a user