From 4f52acb51bde472c29a4fad21b426ba7ce4ec6fd Mon Sep 17 00:00:00 2001 From: Luca Lutz Date: Sat, 12 Nov 2022 16:04:24 +0000 Subject: [PATCH] Update fab_access/mqtt_client.py --- fab_access/mqtt_client.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/fab_access/mqtt_client.py b/fab_access/mqtt_client.py index e64d9e5..9062e5f 100644 --- a/fab_access/mqtt_client.py +++ b/fab_access/mqtt_client.py @@ -1,8 +1,17 @@ from paho.mqtt import client as mqtt_client from config import Config import json +import random +import string class MqttHandler: + @staticmethod + def get_random_string(length): + # choose from all lowercase letter + letters = string.ascii_lowercase + result_str = ''.join(random.choice(letters) for i in range(length)) + return(result_str) + @staticmethod def setup(msg_handler): MqttHandler.msg_handler = msg_handler @@ -16,7 +25,7 @@ class MqttHandler: else: print('Failed to connect, return code %d\n', rc) - MqttHandler.client = mqtt_client.Client(Config.mqtt_client_id) + MqttHandler.client = mqtt_client.Client(Config.mqtt_client_id+get_random_string(5)) MqttHandler.client.username_pw_set('admin', 'user') MqttHandler.client.on_connect = on_connect MqttHandler.client.username_pw_set(Config.mqtt_user_name, Config.mqtt_password)