def start(self): Message.out("Started !") # Run thread [ service.__start__() for service in self.services if not service.is_alive() ] Message.out("Running ...")
def do(self): # TODO DB registration con = sqlite3.connect('smart4l.db') cur = con.cursor() cur.execute( 'insert into smart4l(date, data) values(?,?)', [str(time.time()), json.dumps(self.app.data)]) cur.close() con.commit() con.close() Message.out("DB registration")
def __init__(self): # TODO implement message Queue Message.out("Started !") self.socket = None self.persistent = None self.httpApi = None self.websocket = None self.data = {} self.services = [] Message.out("Running ...")
def do(self): # TODO DB registration self.con = sqlite3.connect('smart4l.db') cur = self.con.cursor() cur.execute( 'insert into smart4l(date, data) values(?,?)', [str(time.time()), json.dumps(app.lastMeasure)]) cur.close() self.con.commit() self.con.close() # TODO Close connection here too Message.out("DB registration")
def stop(self): Message.out("\nCleaning ...") [service.stop() for service in self.services] self.services = [] Message.out("Stopped !")
def __start__(self): Message.out(f"Service \"{self.serviceObject.uid}\" now started" ) if hasattr(self.serviceObject, 'uid') else None self.start()
def stop(self): Message.out("\nCleaning ...") # Stop Measurement Service Thread [service.stop() for service in self.services] # TODO Clean GPIO Message.out("Stopped !")
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": lambda: app.addService( Service( Capteur(DHT11(), str(randint(100, 999)), lambda x, y: app. update_measure(x, y)), 5)), "reload": app.reload, "service": lambda: Message.out(app.services) } while run: try: Message.out(switcher.get(input("Saisir une action : "))()) except KeyboardInterrupt:
def __start__(self): Message.out(f"Service \"{self.name}\" is now started") self.start()
pass def receive_message(self): pass 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