mqtt-sensord/mqtt_sensord/mqttlib/paho_mqtt.py

16 lines
378 B
Python
Raw Normal View History

2019-07-09 22:01:39 +02:00
import json
import paho.mqtt.client as mqtt
from .base import MQTTClientBase
class MQTTClient(MQTTClientBase):
def _connect(self):
self._mqtt = mqtt.Client(self.client_id)
self._mqtt.username_pw_set(self.user, self.password)
self._mqtt.connect(self.host)
def send_data(self, topic, data):
self._mqtt.publish(topic, json.dumps(data))