Added user+password MQTT authorization

This commit is contained in:
Marco Raber 2022-05-14 23:45:33 +02:00
parent 05af470cae
commit b46728cddd
2 changed files with 7 additions and 0 deletions

View File

@ -3,6 +3,8 @@ from tracker import Tracker
mqtt_address = os.environ.get("MQTT_ADDRESS", "10.1.1.100") mqtt_address = os.environ.get("MQTT_ADDRESS", "10.1.1.100")
mqtt_port = int(os.environ.get("MQTT_PORT", 1883)) mqtt_port = int(os.environ.get("MQTT_PORT", 1883))
mqtt_username = os.environ.get("MQTT_USERNAME", "username")
mqtt_passwd = os.environ.get("MQTT_PASSWD", "password")
mqtt_client_id = os.environ.get("MQTT_CLIENT_ID", "cvzone_tracker_01") mqtt_client_id = os.environ.get("MQTT_CLIENT_ID", "cvzone_tracker_01")
min_face_score = float(os.environ.get("MIN_FACE_SCORE", 0.5)) min_face_score = float(os.environ.get("MIN_FACE_SCORE", 0.5))
rotate_img = int(os.environ.get("ROTATE_IMAGE", 0)) rotate_img = int(os.environ.get("ROTATE_IMAGE", 0))
@ -10,6 +12,8 @@ rotate_img = int(os.environ.get("ROTATE_IMAGE", 0))
tracker = Tracker( tracker = Tracker(
mqtt_address=mqtt_address, mqtt_address=mqtt_address,
mqtt_port=mqtt_port, mqtt_port=mqtt_port,
mqtt_passwd=mqtt_passwd,
mqtt_username=mqtt_username,
mqtt_client_id=mqtt_client_id, mqtt_client_id=mqtt_client_id,
min_face_score=min_face_score, min_face_score=min_face_score,
rotate_img=rotate_img == 1, rotate_img=rotate_img == 1,

View File

@ -11,6 +11,8 @@ class Tracker(object):
self, self,
mqtt_address="", mqtt_address="",
mqtt_port=1883, mqtt_port=1883,
mqtt_username="",
mqtt_passwd="",
mqtt_client_id="", mqtt_client_id="",
min_face_score=0.5, min_face_score=0.5,
rotate_img=False, rotate_img=False,
@ -29,6 +31,7 @@ class Tracker(object):
self.mqtt_client_id = mqtt_client_id self.mqtt_client_id = mqtt_client_id
self.is_mqtt_connected = False self.is_mqtt_connected = False
self.mqtt_client = mqtt.Client(mqtt_client_id) self.mqtt_client = mqtt.Client(mqtt_client_id)
self.mqtt_client.username_pw_set(username=mqtt_username, password=mqtt_passwd)
self.mqtt_connect() self.mqtt_connect()
def mqtt_connect(self): def mqtt_connect(self):