refactor(cli): add argument to override mqtt port
This commit is contained in:
parent
fe63597ba4
commit
3766531936
@ -1,7 +1,8 @@
|
|||||||
"""
|
"""
|
||||||
Publish data from oak-lite device
|
Publish data from oak-lite device
|
||||||
|
|
||||||
Usage: rc-oak-camera [-u USERNAME | --mqtt-username=USERNAME] [--mqtt-password=PASSWORD] [--mqtt-broker=HOSTNAME] \
|
Usage: rc-oak-camera [-u USERNAME | --mqtt-username=USERNAME] [--mqtt-password=PASSWORD] \
|
||||||
|
[--mqtt-broker-host=HOSTNAME] [--mqtt-broker-port=PORT] \
|
||||||
[--mqtt-topic-robocar-oak-camera="TOPIC_CAMERA"] [--mqtt-topic-robocar-objects="TOPIC_OBJECTS"] \
|
[--mqtt-topic-robocar-oak-camera="TOPIC_CAMERA"] [--mqtt-topic-robocar-objects="TOPIC_OBJECTS"] \
|
||||||
[--mqtt-client-id=CLIENT_ID] \
|
[--mqtt-client-id=CLIENT_ID] \
|
||||||
[-H IMG_HEIGHT | --image-height=IMG_HEIGHT] [-W IMG_WIDTH | --image-width=IMG_width] \
|
[-H IMG_HEIGHT | --image-height=IMG_HEIGHT] [-W IMG_WIDTH | --image-width=IMG_width] \
|
||||||
@ -11,7 +12,8 @@ Options:
|
|||||||
-h --help Show this screen.
|
-h --help Show this screen.
|
||||||
-u USERID --mqtt-username=USERNAME MQTT user
|
-u USERID --mqtt-username=USERNAME MQTT user
|
||||||
-p PASSWORD --mqtt-password=PASSWORD MQTT password
|
-p PASSWORD --mqtt-password=PASSWORD MQTT password
|
||||||
-b HOSTNAME --mqtt-broker=HOSTNAME MQTT broker host
|
-b HOSTNAME --mqtt-broker-host=HOSTNAME MQTT broker host
|
||||||
|
-P HOSTNAME --mqtt-broker-port=PORT MQTT broker port
|
||||||
-C CLIENT_ID --mqtt-client-id=CLIENT_ID MQTT client id
|
-C CLIENT_ID --mqtt-client-id=CLIENT_ID MQTT client id
|
||||||
-c TOPIC_CAMERA --mqtt-topic-robocar-oak-camera=TOPIC_CAMERA MQTT topic where to publish robocar-oak-camera frames
|
-c TOPIC_CAMERA --mqtt-topic-robocar-oak-camera=TOPIC_CAMERA MQTT topic where to publish robocar-oak-camera frames
|
||||||
-o TOPIC_OBJECTS --mqtt-topic-robocar-objects=TOPIC_OBJECTS MQTT topic where to publish objects detection results
|
-o TOPIC_OBJECTS --mqtt-topic-robocar-objects=TOPIC_OBJECTS MQTT topic where to publish objects detection results
|
||||||
@ -31,13 +33,13 @@ logging.basicConfig(level=logging.INFO)
|
|||||||
default_client_id = "robocar-depthai"
|
default_client_id = "robocar-depthai"
|
||||||
|
|
||||||
|
|
||||||
def init_mqtt_client(broker_host: str, user: str, password: str, client_id: str) -> mqtt.Client:
|
def init_mqtt_client(broker_host: str, broker_port, user: str, password: str, client_id: str) -> mqtt.Client:
|
||||||
logger.info("Start part.py-robocar-oak-camera")
|
logger.info("Start part.py-robocar-oak-camera")
|
||||||
client = mqtt.Client(client_id=client_id, clean_session=True, userdata=None, protocol=mqtt.MQTTv311)
|
client = mqtt.Client(client_id=client_id, clean_session=True, userdata=None, protocol=mqtt.MQTTv311)
|
||||||
|
|
||||||
client.username_pw_set(user, password)
|
client.username_pw_set(user, password)
|
||||||
logger.info("Connect to mqtt broker "+ broker_host)
|
logger.info("Connect to mqtt broker "+ broker_host)
|
||||||
client.connect(host=broker_host, port=1883, keepalive=60)
|
client.connect(host=broker_host, port=broker_port, keepalive=60)
|
||||||
logger.info("Connected to mqtt broker")
|
logger.info("Connected to mqtt broker")
|
||||||
return client
|
return client
|
||||||
|
|
||||||
@ -47,7 +49,8 @@ def execute_from_command_line():
|
|||||||
|
|
||||||
args = docopt(__doc__)
|
args = docopt(__doc__)
|
||||||
|
|
||||||
client = init_mqtt_client(broker_host=get_default_value(args["--mqtt-broker"], "MQTT_BROKER", "localhost"),
|
client = init_mqtt_client(broker_host=get_default_value(args["--mqtt-broker-host"], "MQTT_BROKER_HOST", "localhost"),
|
||||||
|
broker_port=int(get_default_value(args["--mqtt-broker-port"], "MQTT_BROKER_PORT", "1883")),
|
||||||
user=get_default_value(args["--mqtt-username"], "MQTT_USERNAME", ""),
|
user=get_default_value(args["--mqtt-username"], "MQTT_USERNAME", ""),
|
||||||
password=get_default_value(args["--mqtt-password"], "MQTT_PASSWORD", ""),
|
password=get_default_value(args["--mqtt-password"], "MQTT_PASSWORD", ""),
|
||||||
client_id=get_default_value(args["--mqtt-client-id"], "MQTT_CLIENT_ID",
|
client_id=get_default_value(args["--mqtt-client-id"], "MQTT_CLIENT_ID",
|
||||||
|
Loading…
Reference in New Issue
Block a user