diff --git a/Dockerfile b/Dockerfile index 8c37f4d..447e9d9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,11 @@ FROM python:3.10 RUN adduser --disabled-password --gecos "" python +ENV PATH="/home/python/.local/bin:$PATH" USER python COPY *.py requirements.txt / RUN pip --disable-pip-version-check install -r requirements.txt -ENTRYPOINT ["python", "run.py"] \ No newline at end of file +ENTRYPOINT ["python", "run.py"] diff --git a/config.toml-default b/config.toml-default index 5403e1f..9c9ed5e 100644 --- a/config.toml-default +++ b/config.toml-default @@ -1,2 +1,10 @@ +[apsystems] username = "" -password = "" \ No newline at end of file +password = "" + +[mqtt] +username = "" +password = "" +broker = "" +port = 1883 +topic = "ez1cloud2mqtt" diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..256a8c5 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,7 @@ +version: "3.9" +services: + ez1cloud2mqtt: + image: ez1cloud2mqtt + build: . + volumes: + - ./config.toml:/config.toml diff --git a/requirements.txt b/requirements.txt index 0895f5e..8fb8219 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ toml==0.10.2 -requests~=2.31.0 \ No newline at end of file +requests~=2.31.0 +paho-mqtt~=1.6.1 \ No newline at end of file diff --git a/run.py b/run.py index 18a3c30..9c43cce 100644 --- a/run.py +++ b/run.py @@ -1,6 +1,7 @@ import asyncio import os import toml +import paho.mqtt.client as mqtt from CloudConnection import CloudConnection from Inverter import Inverter @@ -11,7 +12,7 @@ async def main(): with open("config.toml", "r") as f: config = toml.load(f) - connection = CloudConnection(config["username"], config["password"]) + connection = CloudConnection(config["apsystems"]["username"], config["apsystems"]["password"]) connection.generate_user_token() inverter = connection.get_inverter() devices = [] @@ -22,9 +23,17 @@ async def main(): for device in devices: asyncio.create_task(device.start()) + mqtt_client = mqtt.Client() + mqtt_client.username_pw_set(config["mqtt"]["username"], config["mqtt"]["password"]) + mqtt_client.connect(config["mqtt"]["broker"], config["mqtt"]["port"]) + while True: item = await queue.get() - print(item) + for i in item.data: + return_code, _ = mqtt_client.publish(f"{config['mqtt']['topic']}/{item.name}/{i}", item.data[i]) + if return_code == 4: + print("Invalid credentials, check your configuration.") + exit(1) if __name__ == '__main__':