import paho.mqtt.client as mqtt
from settings import Settings, historical_settings
import json
import sqlite3
from printer import a_print
from config import Config

class MyMQTTClass(mqtt.Client):

    def on_connect(self, mqttc, flags, rc):
        if rc==0:
            print("connected OK")
        else:
            print("Bad connection Returned code=",rc)

    def on_message(self, mqttc, obj, msg):
        # print(msg.topic+" "+str(msg.qos)+" "+str(msg.payload))
        # print('Appending to historical_settings')
        a_print('Recieved new settings', 'mqtt')
        a_print(msg.topic+" "+str(msg.qos)+" "+str(msg.payload), 'mqtt')
        received_data = json.loads(msg.payload)
        historical_settings.append(Settings(received_data, insert=True))
        a_print('Appended to historical_settings', 'mqtt')

    def on_publish(self, mqttc, obj, mid):
        # print("mid: "+str(mid))
        a_print("mid: "+str(mid), 'mqtt')

    def on_subscribe(self, mqttc, obj, mid, granted_qos):
        # print("Subscribed: "+str(mid)+" "+str(granted_qos))
        a_print("Subscribed: "+str(mid)+" "+str(granted_qos), 'mqtt')

    def on_log(self, mqttc, obj, level, string):
        # print(string)
        a_print(string, 'mqtt')

    def run(self):
        while True:
            try:
                self.connect(Config.broker)
                break
            except:
                pass
        self.subscribe(Config.topic, 1)
        self.loop_start()

75ace70625d0652fb163b4239d9182f3e84496dd
<mask token>


class MyMQTTClass(mqtt.Client):
    <mask token>

    def on_message(self, mqttc, obj, msg):
        a_print('Recieved new settings', 'mqtt')
        a_print(msg.topic + ' ' + str(msg.qos) + ' ' + str(msg.payload), 'mqtt'
            )
        received_data = json.loads(msg.payload)
        historical_settings.append(Settings(received_data, insert=True))
        a_print('Appended to historical_settings', 'mqtt')

    def on_publish(self, mqttc, obj, mid):
        a_print('mid: ' + str(mid), 'mqtt')
    <mask token>

    def on_log(self, mqttc, obj, level, string):
        a_print(string, 'mqtt')

    def run(self):
        while True:
            try:
                self.connect(Config.broker)
                break
            except:
                pass
        self.subscribe(Config.topic, 1)
        self.loop_start()

<mask token>


class MyMQTTClass(mqtt.Client):

    def on_connect(self, mqttc, flags, rc):
        if rc == 0:
            print('connected OK')
        else:
            print('Bad connection Returned code=', rc)

    def on_message(self, mqttc, obj, msg):
        a_print('Recieved new settings', 'mqtt')
        a_print(msg.topic + ' ' + str(msg.qos) + ' ' + str(msg.payload), 'mqtt'
            )
        received_data = json.loads(msg.payload)
        historical_settings.append(Settings(received_data, insert=True))
        a_print('Appended to historical_settings', 'mqtt')

    def on_publish(self, mqttc, obj, mid):
        a_print('mid: ' + str(mid), 'mqtt')
    <mask token>

    def on_log(self, mqttc, obj, level, string):
        a_print(string, 'mqtt')

    def run(self):
        while True:
            try:
                self.connect(Config.broker)
                break
            except:
                pass
        self.subscribe(Config.topic, 1)
        self.loop_start()

<mask token>


class MyMQTTClass(mqtt.Client):

    def on_connect(self, mqttc, flags, rc):
        if rc == 0:
            print('connected OK')
        else:
            print('Bad connection Returned code=', rc)

    def on_message(self, mqttc, obj, msg):
        a_print('Recieved new settings', 'mqtt')
        a_print(msg.topic + ' ' + str(msg.qos) + ' ' + str(msg.payload), 'mqtt'
            )
        received_data = json.loads(msg.payload)
        historical_settings.append(Settings(received_data, insert=True))
        a_print('Appended to historical_settings', 'mqtt')

    def on_publish(self, mqttc, obj, mid):
        a_print('mid: ' + str(mid), 'mqtt')

    def on_subscribe(self, mqttc, obj, mid, granted_qos):
        a_print('Subscribed: ' + str(mid) + ' ' + str(granted_qos), 'mqtt')

    def on_log(self, mqttc, obj, level, string):
        a_print(string, 'mqtt')

    def run(self):
        while True:
            try:
                self.connect(Config.broker)
                break
            except:
                pass
        self.subscribe(Config.topic, 1)
        self.loop_start()

import paho.mqtt.client as mqtt
from settings import Settings, historical_settings
import json
import sqlite3
from printer import a_print
from config import Config


class MyMQTTClass(mqtt.Client):

    def on_connect(self, mqttc, flags, rc):
        if rc == 0:
            print('connected OK')
        else:
            print('Bad connection Returned code=', rc)

    def on_message(self, mqttc, obj, msg):
        a_print('Recieved new settings', 'mqtt')
        a_print(msg.topic + ' ' + str(msg.qos) + ' ' + str(msg.payload), 'mqtt'
            )
        received_data = json.loads(msg.payload)
        historical_settings.append(Settings(received_data, insert=True))
        a_print('Appended to historical_settings', 'mqtt')

    def on_publish(self, mqttc, obj, mid):
        a_print('mid: ' + str(mid), 'mqtt')

    def on_subscribe(self, mqttc, obj, mid, granted_qos):
        a_print('Subscribed: ' + str(mid) + ' ' + str(granted_qos), 'mqtt')

    def on_log(self, mqttc, obj, level, string):
        a_print(string, 'mqtt')

    def run(self):
        while True:
            try:
                self.connect(Config.broker)
                break
            except:
                pass
        self.subscribe(Config.topic, 1)
        self.loop_start()

import paho.mqtt.client as mqtt
from settings import Settings, historical_settings
import json
import sqlite3
from printer import a_print
from config import Config

class MyMQTTClass(mqtt.Client):

    def on_connect(self, mqttc, flags, rc):
        if rc==0:
            print("connected OK")
        else:
            print("Bad connection Returned code=",rc)

    def on_message(self, mqttc, obj, msg):
        # print(msg.topic+" "+str(msg.qos)+" "+str(msg.payload))
        # print('Appending to historical_settings')
        a_print('Recieved new settings', 'mqtt')
        a_print(msg.topic+" "+str(msg.qos)+" "+str(msg.payload), 'mqtt')
        received_data = json.loads(msg.payload)
        historical_settings.append(Settings(received_data, insert=True))
        a_print('Appended to historical_settings', 'mqtt')

    def on_publish(self, mqttc, obj, mid):
        # print("mid: "+str(mid))
        a_print("mid: "+str(mid), 'mqtt')

    def on_subscribe(self, mqttc, obj, mid, granted_qos):
        # print("Subscribed: "+str(mid)+" "+str(granted_qos))
        a_print("Subscribed: "+str(mid)+" "+str(granted_qos), 'mqtt')

    def on_log(self, mqttc, obj, level, string):
        # print(string)
        a_print(string, 'mqtt')

    def run(self):
        while True:
            try:
                self.connect(Config.broker)
                break
            except:
                pass
        self.subscribe(Config.topic, 1)
        self.loop_start()
