blob: 2b0ece1d04c3a590b30aa1b43a40c5236f724d33 (
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
|
"""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):
client.subscribe(self.config["mqtt"]["topic"])
|