blob: c5a075cab93820c678876c8ecc114aa827c2bf6f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
"""Provide MQTT Functionality for the Package"""
import paho.mqtt.client as mqtt
class MqttService():
"""Bundle for MQTT Functionality"""
def __init__(self, config):
self.config = config
self.client = mqtt.Client()
self.client.on_connect = self.on_connect
def run(self):
self.client.connect(
self.config["mqtt"]["broker"],
self.config["mqtt"]["port"],
60
)
self.client.loop_start()
def on_connect(self, client, userdata, flags, rc):
print("Connected with result code " + str(rc))
client.subscribe(self.config["mqtt"]["topic"])
|