You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Would it be possible to add client_id variable to the MQTT connection? I needed to troubleshoot some unrelated issues to docker-wyze-bridge and while doing so I noticed that docker-wyze-bridge uses a random client id on every connection, which seems to be every 20 seconds. I'm not a coder but after feeding the code to chatgpt it seems to be an easy fix, I'm just not sure if this 2 line change would break anything else.
Existing code:
`def mqtt_sub_topic(m_topics: list, callback) -> Optional[paho.mqtt.client.Client]:
"""Connect to mqtt and return the client."""
def on_connect(client, *_):
"""Callback for when the client receives a CONNACK response from the server."""
client.publish(f"{MQTT_TOPIC}/state", "online", retain=True)
for topic in m_topics:
# Clear Retain Flag
client.publish(f"{MQTT_TOPIC}/{topic}", retain=True)
client.subscribe(f"{MQTT_TOPIC}/{topic}")
client = paho.mqtt.client.Client(paho.mqtt.client.CallbackAPIVersion.VERSION2)
client.username_pw_set(MQTT_USER, MQTT_PASS or None)
client.user_data_set(callback)
client.on_connect = on_connect
client.will_set(f"{MQTT_TOPIC}/state", payload="offline", qos=1, retain=True)
client.connect(MQTT_HOST, int(MQTT_PORT or 1883), 30)
client.loop_start()
return client`
new code suggested by gpt
`def mqtt_sub_topic(m_topics: list, callback) -> Optional[paho.mqtt.client.Client]:
"""Connect to mqtt and return the client."""
def on_connect(client, *_):
"""Callback for when the client receives a CONNACK response from the server."""
client.publish(f"{MQTT_TOPIC}/state", "online", retain=True)
for topic in m_topics:
client.publish(f"{MQTT_TOPIC}/{topic}", retain=True)
client.subscribe(f"{MQTT_TOPIC}/{topic}")
# Add a custom client_id here
client_id = "YourUniqueClientID"
client = paho.mqtt.client.Client(client_id, paho.mqtt.client.CallbackAPIVersion.VERSION2)
client.username_pw_set(MQTT_USER, MQTT_PASS or None)
client.user_data_set(callback)
client.on_connect = on_connect
client.will_set(f"{MQTT_TOPIC}/state", payload="offline", qos=1, retain=True)
client.connect(MQTT_HOST, int(MQTT_PORT or 1883), 30)
client.loop_start()
return client`
The text was updated successfully, but these errors were encountered:
Would it be possible to add client_id variable to the MQTT connection? I needed to troubleshoot some unrelated issues to docker-wyze-bridge and while doing so I noticed that docker-wyze-bridge uses a random client id on every connection, which seems to be every 20 seconds. I'm not a coder but after feeding the code to chatgpt it seems to be an easy fix, I'm just not sure if this 2 line change would break anything else.
Existing code:
`def mqtt_sub_topic(m_topics: list, callback) -> Optional[paho.mqtt.client.Client]:
"""Connect to mqtt and return the client."""
new code suggested by gpt
`def mqtt_sub_topic(m_topics: list, callback) -> Optional[paho.mqtt.client.Client]:
"""Connect to mqtt and return the client."""
The text was updated successfully, but these errors were encountered: