Skip to content

Commit

Permalink
connect only on init
Browse files Browse the repository at this point in the history
  • Loading branch information
MP91 committed Aug 13, 2024
1 parent 8bfb550 commit 5cf00d1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion velocitas_sdk/native/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self) -> None:
self.pubsub_client = MqttClient(hostname=_hostname, port=_port)

async def start(self):
pass
self.pubsub_client.init()

async def wait_until_ready(self):
pass
Expand Down
18 changes: 8 additions & 10 deletions velocitas_sdk/native/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ def __init__(self, hostname: str, port: Optional[int] = None):
self._sub_client.on_connect = self.on_connect
self._sub_client.on_disconnect = self.on_disconnect

if self._port is None:
self._sub_client.connect(self._hostname)
self._pub_client.connect(self._hostname)
else:
self._sub_client.connect(self._hostname, self._port)
self._pub_client.connect(self._hostname, self._port)

def on_connect(self, client, userdata, flags, rc):
if rc == 0:
logger.debug("Mqtt native connection OK!")
Expand All @@ -64,13 +57,18 @@ def on_connect(self, client, userdata, flags, rc):
def on_disconnect(self, client, userdata, rc):
logger.debug("Mqtt native is disconnected with reason: %d", rc)

async def init(self):
if self._port is None:
self._sub_client.connect(self._hostname)
self._pub_client.connect(self._hostname)
else:
self._sub_client.connect(self._hostname, self._port)
self._pub_client.connect(self._hostname, self._port)

async def run(self):
self._sub_client.loop_start()
self._pub_client.loop_start()

async def init(self):
"""Do nothing"""

async def subscribe_topic(self, topic, coro):
self._topics_to_subscribe.append(MqttTopicSubscription(topic, coro))
if self._sub_client.is_connected():
Expand Down

0 comments on commit 5cf00d1

Please sign in to comment.