Ejemplo n.º 1
0
 def ping_esp(self, name, timeout=5, intervall=1):
     pingback = False
     self.publish_mqtt("ping_snd/{}".format(name), 1)
     self.debug_msg(
         "PING", "Pinged Esp: {} with Timeout: {}sec".format(name, timeout))
     for i in range(timeout):
         if self.mqtt_handler.pingback != None:
             pingback = True
             while self.mqtt_handler.pingback != None:
                 self.mqtt_handler.pingback = None
             break
         self.debug_msg("PING",
                        "no pingback after {}sec".format(i),
                        ol=True)
         sleep(intervall)
     if pingback:
         self.debug_msg(
             "PING", "received ping from {} after {}sec...".format(name, i))
         esp_status_db = _sql.Esp_Status(name)
         esp_status_db.status_aktualisieren(1)
     else:
         self.debug_msg(
             "PING", "did not receive ping from {} after {}sec...".format(
                 name, timeout))
         esp_status_db = _sql.Esp_Status(name)
         esp_status_db.status_aktualisieren(0)
Ejemplo n.º 2
0
 def list_esp(self):
     esp_sql = _sql.Esp_Status()
     esp_list = esp_sql.status_abrufen()
     for esp in esp_list:
         print("Name: {} Status: {}".format(esp[1], esp[0]))
Ejemplo n.º 3
0
    def mqtt_on_message(self, client, userdata, msg):
        msg_str = str(msg.payload.decode("utf-8"))
        topic = msg.topic
        if "ping_rcv" in topic:
            for i in range(len(topic)):
                if topic[i] == "/":
                    name = topic[i + 1:len(topic)]
                    self.pingback = name
                    break

        elif "sicherheit/nachricht" == topic:
            if msg_str == "1":
                self.sicherheit = True
                self.mqtt_msg("Sicherheit :[An]")
            elif msg_str == "0":
                self.sicherheit = False
                self.mqtt_msg("Sicherheit :[Aus]")

        elif "alarm" in topic:
            for i in range(len(topic)):
                if topic[i] == "/":
                    name = topic[i + 1:len(topic)]
                    break
            if self.sicherheit == True:
                self.mqtt_msg(
                    "[KRITSCH]: '{}' wurde ausgelöst...".format(name))
                esp_db = _sql.Alarm_handler("Ausgelöst", name,
                                            str(datetime.datetime.now()))
                esp_db.neuer_alarm()
                self.mqtt_msg(
                    "[DATENBANK]: '{}' Alarm erfolgreich eingetragen...".
                    format(name))
                self.sound_queue.put("leave_or_gas.wav")

        elif topic == "button":
            if msg_str == "power":
                self.publish("power/windows1", "1")
            elif msg_str == "reset":
                if self.sicherheit == True:
                    self.sicherheit = False
                    self.sound_queue.put("male_sicherheit_aus.wav")
                else:
                    self.sicherheit = True
                    self.sound_queue.put("male_sicherheit_an.wav")

        elif "task" in topic:
            if msg_str == "1":
                self.sound_queue.put("windows_xp_startup.wav")

            elif msg_str == "0":
                self.sound_queue.put("cornholio.wav")

        elif "verbindung" in topic:
            for i in range(len(topic)):
                if topic[i] == "/":
                    name = topic[i + 1:len(topic)]
                    if _sql.Esp_Status.suchen_esp(name) != None:
                        self.mqtt_msg(
                            "sql Eintrag: name: '{}' status: {}".format(
                                name, msg_str))
                        esp_status_db = _sql.Esp_Status(name)
                        esp_status_db.status_aktualisieren(int(msg_str))
                    else:
                        esp_status_db = _sql.Esp_Status(name)
                        esp_status_db.neuer_esp()

        elif "gui/data/" in topic:
            if topic == "gui/data/open":
                if msg_str == "esp":
                    self.open_stream(self.list_esp, msg_str)
                elif msg_str == "processes":
                    self.open_stream(self.ssData, msg_str)

            elif topic == "gui/data/close":
                self.gui_stream = False

            elif topic == "gui/data/once":
                if msg_str == "alarms_today":
                    self.open_stream(self.alarme_heute, msg_str)
                if msg_str == "sicherheit":
                    self.publish("gui/server/sicherheit", str(self.sicherheit))

        elif topic == "gui/connection":
            self.publish("gui/connection/callback", "1")
Ejemplo n.º 4
0
 def check_esp(self):
     self.debug_msg("PING", "initializing...")
     esp_sql = _sql.Esp_Status()
     esp_list = esp_sql.status_abrufen()
     for esp in esp_list:
         self.ping_esp(esp[1])
Ejemplo n.º 5
0
 def list_esp(self):
     esp_sql = _sql.Esp_Status()
     return esp_sql.status_abrufen()