Skip to content

Commit

Permalink
maj bug fréquence
Browse files Browse the repository at this point in the history
  • Loading branch information
RayanSellou committed Nov 28, 2023
1 parent 0c816a9 commit 6e3f416
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions code/IOT/Python/connect_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ def handler(signum, frame):
# for room, data in pending_data.items():
# ecrire(room, data)
# Programmation d'une nouvelle alarme pour la prochaine écriture
signal.alarm(frequence_affichage)


pass
#signal.alarm(frequence_affichage)

# Association du handler au signal d'alarme
signal.signal(signal.SIGALRM, handler)
Expand Down Expand Up @@ -101,6 +102,10 @@ def ecrire(ecrire_log, nom_fichier, room, data):
os.write(fichier, json.dumps(donnees, indent=4).encode())
# Fermeture du descripteur de fichier
os.close(fichier)
if(ecrire_log):
signal.alarm(frequence_affichage)
signal.pause()

except Exception as e:
print(f"Erreur lors de l'écriture dans le fichier données : {e}")

Expand Down Expand Up @@ -221,4 +226,14 @@ def on_message(client, userdata, msg):
client.connect(broker, port, 60)

# Boucle de traitement des messages
client.loop_forever()
try:
# Boucle de traitement des messages
client.loop_forever()

except KeyboardInterrupt:
print("Interruption du script par l'utilisateur.")

finally:
# Nettoyer et désactiver le signal SIGALRM à la fin du script
signal.alarm(0)
signal.signal(signal.SIGALRM, signal.SIG_DFL)

0 comments on commit 6e3f416

Please sign in to comment.