connection blah
This commit is contained in:
parent
d754bb0861
commit
3d9dece330
|
@ -43,7 +43,7 @@ class Value:
|
|||
|
||||
if remote_update_callback is not None:
|
||||
_logger.debug("Subscribing to topic %s", self.topic)
|
||||
self.client.message_callback_add(self.topic, remote_update_callback)
|
||||
self.client.my_message_callback_add(self.topic, remote_update_callback)
|
||||
while self.client.subscribe(self.topic, 2)[1] is None:
|
||||
time.sleep(0.5)
|
||||
_logger.warning("Retrying...")
|
||||
|
@ -84,8 +84,17 @@ class Value:
|
|||
def reconnecting_client(host: str, *, keepalive: int = 60):
|
||||
_logger.debug("Creating MQTT client with keepalive interval %d", keepalive)
|
||||
client = Client()
|
||||
client.on_connect = lambda client, userdata, flags, rc: \
|
||||
client.mmcbdata = {}
|
||||
def mmcb(topic, cb):
|
||||
client.mmcbdata[topic] = cb
|
||||
client.message_callback_add(topic, cb)
|
||||
def on_connect(client, userdata, flags, rc):
|
||||
_logger.debug("Connected to mqtt host")
|
||||
for topic, cb in client.mmcbdata.items():
|
||||
_logger.debug("Re-adding subscription for %s", topic);
|
||||
client.message_callback_add(topic, cb)
|
||||
client.my_message_callback_add = mmcb
|
||||
client.on_connect = on_connect
|
||||
client.on_disconnect = lambda client, userdata, rc: \
|
||||
_logger.debug("Disconnected from mqtt host")
|
||||
# client.enable_logger(_logger.getChild("paho"))
|
||||
|
|
Loading…
Reference in New Issue
Block a user