From eb956e38aba6a6a4004930849486b735d8fd9891 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thierry=20Pell=C3=A9?= Date: Mon, 27 Mar 2023 14:37:11 +0200 Subject: [PATCH] =?UTF-8?q?Code=20pour=20d=C3=A9buter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- actions.py | 13 +++++++++++++ serveur-capteur.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 actions.py create mode 100644 serveur-capteur.py diff --git a/actions.py b/actions.py new file mode 100644 index 0000000..4c90cd5 --- /dev/null +++ b/actions.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python3 +""" +Fonctions de traitement des actions lors d'une impulsion +""" + +import inspect + +def stocker(): + print(inspect.getframeinfo(inspect.currentframe()).function," non encore fonctionnel") + +def créer_graphe(): + print(inspect.getframeinfo(inspect.currentframe()).function," non encore fonctionnel") + diff --git a/serveur-capteur.py b/serveur-capteur.py new file mode 100644 index 0000000..0795af2 --- /dev/null +++ b/serveur-capteur.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 +""" +Serveur écoutant les impulsions de l'objet capteur. +""" + +import socketserver + +from actions import stocker +from actions import créer_graphe + +# Paramètres +HOST = "localhost" +PORT = 10000 + +class gestionnaire_impulsion(socketserver.BaseRequestHandler): + """ + Classe de gestionnaire du serveur. + + Est instanciée à chaque implusion envoyée de par le capteur de pluie. + Le traitement est réalisé en surchargeant la méthode .handle(). + """ + + def handle(self): + # self.request est la socket TCP connectée au client (le capteur de pluie). + if self.request: + print("Impulsion") + stocker() + créer_graphe() + +if __name__ == "__main__": + # Création de l'instance serveur attaché à IP/TCP + socketserver.TCPServer.allow_reuse_address = True + with socketserver.TCPServer((HOST, PORT), gestionnaire_impulsion) as serveur_pluviomètre: + # Lance le server. Il est arrêté par Ctrl-C + print("Lancement du serveur") + serveur_pluviomètre.serve_forever()