diff options
-rw-r--r-- | docker_net.py | 12 | ||||
-rw-r--r-- | requirements.txt | 2 | ||||
-rw-r--r-- | tasmota-mqtt-client.py | 3 |
3 files changed, 15 insertions, 2 deletions
diff --git a/docker_net.py b/docker_net.py new file mode 100644 index 0000000..dd6f705 --- /dev/null +++ b/docker_net.py @@ -0,0 +1,12 @@ +import docker +import os + +def get_mqtt_addr(): + if os.getuid() != 0: + raise Exception("You must be root to access the docker API and fetch the container's network") + + client = docker.from_env() + containers = client.networks.get("poweredagay_default").attrs["Containers"] + for k, v in containers.items(): + if "mqtt_1" in v["Name"]: + return v["IPv4Address"].split("/") diff --git a/requirements.txt b/requirements.txt index f6950d8..f8fd590 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ tasmotadevicecontroller aiohttp -paho-mqtt +paho-mqtt==1.6.1 diff --git a/tasmota-mqtt-client.py b/tasmota-mqtt-client.py index c4be92a..9c9ccb5 100644 --- a/tasmota-mqtt-client.py +++ b/tasmota-mqtt-client.py @@ -2,6 +2,7 @@ import paho.mqtt.client as paho import threading import argparse import getpass +import docker_net import time import json @@ -61,7 +62,7 @@ parser.add_argument( "-m", "--mqtt-host", type = str, help = "MQTT Server", - default = "172.18.0.2", + default = docker_net.get_mqtt_addr()[0] ) parser.add_argument( "-u", "--user", |