mirror of
https://gitlab.com/sfz.aalen/infra/fabaccess.git
synced 2025-03-12 06:51:46 +01:00
Update fab_access/mqtt_client.py
This commit is contained in:
parent
82a899fd84
commit
4f52acb51b
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user