From 456fe8ed4ee2ae1a1f0be24e1c200095fd31d6d7 Mon Sep 17 00:00:00 2001 From: vvzvlad Date: Thu, 1 Jun 2023 00:34:47 +0700 Subject: [PATCH] add args --- device_status_checker.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/device_status_checker.py b/device_status_checker.py index 9254cc6..7f21beb 100644 --- a/device_status_checker.py +++ b/device_status_checker.py @@ -2,6 +2,11 @@ import paho.mqtt.client as mqtt import time import os from collections import Counter +import argparse + +parser = argparse.ArgumentParser(description="MQTT Device Error Status") +parser.add_argument("-a", "--wb", type=str, required=True, help="WB address") +args = parser.parse_args() def get_modbus_devices(): devices = {} @@ -16,7 +21,7 @@ def get_modbus_devices(): client = mqtt.Client() client.on_connect = on_connect client.on_message = on_message - client.connect("192.168.98.244", 1883, 60) + client.connect(args.wb, 1883, 60) client.loop_start() time.sleep(3) client.loop_stop() @@ -37,12 +42,10 @@ def get_all_controls(devices): client = mqtt.Client() client.on_connect = on_connect client.on_message = on_message - client.connect("192.168.98.244", 1883, 60) + client.connect(args.wb, 1883, 60) client.loop_start() - time.sleep(0.5) + time.sleep(3) client.loop_stop() - for device in devices.keys(): - client.unsubscribe(f"/devices/{device}/controls/+") client.disconnect() return devices @@ -66,7 +69,7 @@ def get_all_controls_errors(devices): client = mqtt.Client() client.on_connect = on_connect client.on_message = on_message - client.connect("192.168.98.244", 1883, 60) + client.connect(args.wb, 1883, 60) client.loop_start() def sort_devices(devices):