aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md6
-rw-r--r--config.env10
-rw-r--r--config.env.example10
-rw-r--r--docker-compose.yml26
-rw-r--r--mqtt-client/Dockerfile10
-rw-r--r--mqtt-client/mqtt-client.py63
-rw-r--r--mqtt-client/requirements.txt3
7 files changed, 2 insertions, 126 deletions
diff --git a/README.md b/README.md
index d679508..c0323a0 100644
--- a/README.md
+++ b/README.md
@@ -2,14 +2,10 @@
Logs Tasmota-flashed power usage monitors to InfluxDB and Grafana using MQTT.
-Looking for the Mikrotik POE usage monitor/exporter? That's been moved to [MikrotikPOEPowerExporter](https://github.com/jwansek/MikrotikPOEPowerExporter)
-
## Setup
-- `cp power.env.example power.env`
-- Edit `power.env` as appropriate
- `touch .passwords`
-- `sudo docker-compose up -d --build`
+- `sudo docker-compose up -d`
- `sudo docker exec -it poweredagay_mqtt_1 sh` Then in the container:
- `chmod 0700 /mosquitto/passwd_file`
- `chmod root:root /mosquitto/passwd_file`
diff --git a/config.env b/config.env
deleted file mode 100644
index 061d3a6..0000000
--- a/config.env
+++ /dev/null
@@ -1,10 +0,0 @@
-MQTT_USER=eden
-MQTT_PASSWD=securebackdoor
-
-DOCKER_INFLUXDB_INIT_MODE=setup
-DOCKER_INFLUXDB_INIT_USERNAME=eden
-DOCKER_INFLUXDB_INIT_PASSWORD=securebackdoor
-DOCKER_INFLUXDB_INIT_ORG=poweredagay
-DOCKER_INFLUXDB_INIT_BUCKET=edenbucket
-DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=027b29324702baad0fd9a3fcf2dbe644
-DOCKER_INFLUXDB_DB=power
diff --git a/config.env.example b/config.env.example
deleted file mode 100644
index 9010652..0000000
--- a/config.env.example
+++ /dev/null
@@ -1,10 +0,0 @@
-MQTT_USER=eden
-MQTT_PASSWD=****************
-
-DOCKER_INFLUXDB_INIT_MODE=setup
-DOCKER_INFLUXDB_INIT_USERNAME=eden
-DOCKER_INFLUXDB_INIT_PASSWORD=****************
-DOCKER_INFLUXDB_INIT_ORG=poweredagay
-DOCKER_INFLUXDB_INIT_BUCKET=edenbucket
-DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=************************
-DOCKER_INFLUXDB_DB=power
diff --git a/docker-compose.yml b/docker-compose.yml
index 0ca01a6..daaeb5c 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -8,34 +8,10 @@ services:
- 9001:9001
volumes:
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf
- - ./.passwords:/mosquitto/passwd_file
+ - ./.passwords://mosquitto/passwd_file
- mosquitto-data:/mosquitto/data
- mosquitto-logs:/mosquitto/log
-
- influxdb:
- image: influxdb:2.0
- ports:
- - 8086:8086
- volumes:
- - influxdb-config:/etc/influxdb2
- - influxdb-data:/var/lib/influxdb2
- env_file:
- - ./config.env
- depends_on:
- - mqtt
-
- mqtt_client:
- image: jwansek/mqtt-client
- build:
- context: ./mqtt-client
- dockerfile: Dockerfile
- env_file:
- - ./config.env
- depends_on:
- - influxdb
volumes:
mosquitto-data:
mosquitto-logs:
- influxdb-config:
- influxdb-data:
diff --git a/mqtt-client/Dockerfile b/mqtt-client/Dockerfile
deleted file mode 100644
index ad59f9b..0000000
--- a/mqtt-client/Dockerfile
+++ /dev/null
@@ -1,10 +0,0 @@
-FROM debian:11-slim
-ENV TZ=Europe/London
-RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
-RUN apt-get update -y
-RUN apt-get install -y python3-pip iputils-ping
-COPY . /app
-WORKDIR /app
-RUN pip3 install -r requirements.txt
-ENTRYPOINT ["python3"]
-CMD ["mqtt-client.py"]
diff --git a/mqtt-client/mqtt-client.py b/mqtt-client/mqtt-client.py
deleted file mode 100644
index 248e5af..0000000
--- a/mqtt-client/mqtt-client.py
+++ /dev/null
@@ -1,63 +0,0 @@
-import paho.mqtt.client as paho
-from influxdb_client import InfluxDBClient, Point, WritePrecision
-from influxdb_client.client.write_api import SYNCHRONOUS
-import json
-import os
-
-class MQTTClient:
- def __init__(self):
- self.influxc = InfluxDBClient(
- url = "http://%s:8086" % INFLUXDB_HOST,
- token = os.environ["DOCKER_INFLUXDB_INIT_ADMIN_TOKEN"],
- org = os.environ["DOCKER_INFLUXDB_INIT_ORG"]
- )
- self.influxc.ping()
-
- self.mqttc = paho.Client('power-listener', clean_session = True)
- self.mqttc.on_connect = self._on_connect_cb
- self.mqttc.on_message = self._on_message_cb
-
- self.mqttc.username_pw_set(os.environ["MQTT_USER"], password = os.environ["MQTT_PASSWD"])
- self.mqttc.connect(MQTT_HOST, 1883, 60)
- self.mqttc.loop_forever()
-
- def _on_connect_cb(self, mqtt, userdata, flags, rc):
- print("Connected to broker")
- self.mqttc.subscribe("tele/+/SENSOR")
-
- def _on_message_cb(self, mqtt, userdata, msg):
- print('Topic: {0} | Message: {1}'.format(msg.topic, msg.payload))
-
- if "Tasmota" in msg.topic:
- self.handle_tasmota(msg)
-
- def handle_tasmota(self, msg):
- from_ = msg.topic.split("/")[1]
- msg_j = json.loads(msg.payload.decode())
- #print(from_)
- fields = {k: v for k, v in msg_j["ENERGY"].items() if k not in {"TotalStartTime"}}
- points = [{"measurement": "tasmota_power", "tags": {"plug": from_}, "fields": fields}]
- write_api = self.influxc.write_api(write_options = SYNCHRONOUS)
- write_api.write(
- os.environ["DOCKER_INFLUXDB_INIT_BUCKET"],
- os.environ["DOCKER_INFLUXDB_INIT_ORG"],
- points,
- write_precision = WritePrecision.S
- )
-
-if __name__ == "__main__":
- env_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "config.env")
- if os.path.exists(env_path):
- import dotenv
- dotenv.load_dotenv(dotenv_path = env_path)
- INFLUXDB_HOST = "localhost"
- MQTT_HOST = "localhost"
- else:
- INFLUXDB_HOST = "influxdb"
- MQTT_HOST = "mqtt"
-
- mqtt_client = MQTTClient()
-
-
-
-
diff --git a/mqtt-client/requirements.txt b/mqtt-client/requirements.txt
deleted file mode 100644
index 2532957..0000000
--- a/mqtt-client/requirements.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-paho-mqtt
-python-dotenv
-influxdb-client