aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjwansek <eddie.atten.ea29@gmail.com>2024-06-05 09:31:20 +0100
committerjwansek <eddie.atten.ea29@gmail.com>2024-06-05 09:31:20 +0100
commita8e7d91e8cdc3c48568fee9c8ca69bdc3ae28ef9 (patch)
tree10a4b000d7cddf7be439dc3f9990ac2fd19c62cd
parentd399ef3df2ac08cfc6b58fa50abc3e4ad1cf4af6 (diff)
downloadTasmotaCLI-a8e7d91e8cdc3c48568fee9c8ca69bdc3ae28ef9.tar.gz
TasmotaCLI-a8e7d91e8cdc3c48568fee9c8ca69bdc3ae28ef9.zip
Added script to automatically fetch the mqtt IP
-rw-r--r--docker_net.py12
-rw-r--r--requirements.txt2
-rw-r--r--tasmota-mqtt-client.py3
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",