Exemple #1
0
        self.services.append(service)
        # Must use reload function to start new service

    def stop(self):
        Message.out("\nCleaning ...")
        # Stop Measurement Service Thread
        [service.stop() for service in self.services]
        # TODO Clean GPIO
        Message.out("Stopped !")


# execute only if run as a script
if __name__ == "__main__":
    # If pid file already exists
    if os.path.isfile('smart4l.pid'):
        Message.err("File pid already exists")
        sys.exit(1)
    else:
        open("smart4l.pid", "w+").write(str(os.getpid()))

    app = Smart4l()
    try:
        app.start()
        # Si on sort de la boucle, l'exception KeyboardInterrupt n'est plus gérée
        #while not input() == Status.STOP.value:
        run = True

        switcher = {
            "measure":
            lambda: Message.out(app.lastMeasure),
            "add":
Exemple #2
0
    if os.path.isfile('smart4l.lock'):
        # TODO check if python process run with this pid
        Message.wrn("PID file  already exists")
        os.remove("smart4l.lock")
    open("smart4l.lock", "w+").write(str(os.getpid()))
    # --- === ---

    app = Smart4l()

    app.persistent = Persistent(app)
    app.httpApi = FlaskAPI(app.persistent)
    app.socket = Smart4lServeur(app.update_measure)

    app.add_service(
        Service(Sensor(DHT11(), "DHT11", app.update_measure), 1,
                "Temperature"))
    app.add_service(Service(app.persistent, 20, "DB"))
    app.add_service(Service(app.httpApi, "API Http"))

    app.reload()

    try:
        # Infinite loop for keyboard interuption
        while True:
            continue
    except KeyboardInterrupt:
        app.stop()
        os.remove("smart4l.lock")
else:
    Message.err(f"{__name__} : must be run as a script\n")
Exemple #3
0

if __name__ == "__main__":
    services = []
    lastMeasure = {}
    capteurs = [Capteur(DHT11(), "DHT11 EXT RPI2", lastMeasure), Capteur(DHT11(), "DHT11 INT RPI2", lastMeasure)]
    [services.append(Service(service_object=capteur, timeout=2, name=capteur.uid)) for capteur in capteurs]
    [service.__start__() for service in services if not service.is_alive()]
    try:
        while True:
            Message.out(lastMeasure)
            time.sleep(2)
    except KeyboardInterrupt:
        [service.stop() for service in services]
else:
    Message.err("POC_network.py : must be run as a script\n")



"""
Socket Ressource :
socketserver lib : https://docs.python.org/3/library/socketserver.html
socker lib : https://fiches-isn.readthedocs.io/fr/latest/FicheReseauxClient01.html
pickle module allow to pass python object via socket

https://www.youtube.com/watch?v=Lbfe3-v7yE0
https://www.youtube.com/watch?v=3QiPPX-KeSc

https://www.framboise314.fr/utiliser-le-protocole-mqtt-pour-communiquer-des-donnees-entre-2-raspberry-pi/