Skip to content

Commit

Permalink
[ skip ci ] use mosquitto broker for sub topic functionality but for …
Browse files Browse the repository at this point in the history
…crucial system control pub message directly to the venusOS device.
  • Loading branch information
JoshuaDodds committed Apr 8, 2024
1 parent 4c41ef3 commit a8bc598
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/clients/mqtt_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import random
import paho.mqtt.client as mqtt

from lib.constants import retrieve_mqtt_subcribed_topics, logging, DzEndpoints, cerboGxEndpoint, systemId0
from lib.constants import retrieve_mqtt_subcribed_topics, logging, DzEndpoints, mosquittoEndpoint, systemId0
from lib.domoticz_updater import domoticz_update

class VictronClient:
Expand All @@ -18,7 +18,7 @@ def __new__(cls, *args, **kwargs):
cls._instance = super(VictronClient, cls).__new__(cls)
return cls._instance

def __init__(self, client_id=f"victron_client-{random.randint(100000, 999999)}", host=cerboGxEndpoint, keepalive=45, port=1883):
def __init__(self, client_id=f"victron_client-{random.randint(100000, 999999)}", host=mosquittoEndpoint, keepalive=45, port=1883):
# To prevent re-initialization if __init__ is called again
if hasattr(self, '_initialized') and self._initialized:
return
Expand Down
1 change: 1 addition & 0 deletions lib/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def dotenv_config(env_variable):
Basig Configuration
"""
cerboGxEndpoint = dotenv_config('CERBOGX_IP')
mosquittoEndpoint = dotenv_config('MOSQUITTO_IP')
systemId0 = dotenv_config('VRM_PORTAL_ID')
dzEndpoint = dotenv_config('DZ_URL_PREFIX')
PushOverConfig = {"id": dotenv_config('PO_USER_ID'), "key": dotenv_config('PO_API_KEY')}
Expand Down
6 changes: 3 additions & 3 deletions lib/helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from math import floor, ceil

from lib.helpers.base7_math import *
from lib.constants import Topics, logging, cerboGxEndpoint
from lib.constants import Topics, logging, mosquittoEndpoint


def publish_message(topic, message=None, qos=0, retain=False, payload=None) -> None:
Expand Down Expand Up @@ -53,12 +53,12 @@ def on_message(client, _userdata, msg):
completed = True

# Initialize a new temporary MQTT client
temp_client = mqtt.Client()
temp_client = mqtt.Client(client_id="helper-message-retrieval-client")
temp_client.on_connect = on_connect
temp_client.on_message = on_message

# Connect to the broker
temp_client.connect(cerboGxEndpoint, 1883, 60)
temp_client.connect(mosquittoEndpoint, 1883, 60)
temp_client.loop_start()

# Wait for the message to arrive or for the timeout
Expand Down

0 comments on commit a8bc598

Please sign in to comment.