Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connect only on init #146

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
await 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