From 2bb36bfc19cb6d59e48bb2dd50aaff8cbfbcba89 Mon Sep 17 00:00:00 2001 From: Markus Dillmann Date: Wed, 5 Jun 2024 07:58:55 +0200 Subject: [PATCH] Make statuspage work with HUB 2000 in online mode (#46) * Make statuspage work with HUB 2000 in online mode * Properly dispose background MQTT tasks --- README.md | 5 +++++ src/requirements.txt | 2 +- src/solarflow-status.py | 17 ++++++++++++----- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 321461a..149661e 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,11 @@ MQTT_USER = MQTT_PWD = ``` +For HUB 2000 an additional environment variable is needed as follows +```` +PROD_NAME=SolarFlow Hub 2000 +``` + Then run the container and expose it's port to a local port. Make sure to also specify the --online option, as per default the statuspage will try to work ```offline``` (meaning it will expect the telemetry data already in MQTT, provided by an offline hub) ``` docker run --rm --env-file .env -p 127.0.0.1:5000:5000 --name solarflow-statuspage rbrandstaedter/solarflow-statuspage:master --online diff --git a/src/requirements.txt b/src/requirements.txt index 3978c61..45cec01 100644 --- a/src/requirements.txt +++ b/src/requirements.txt @@ -16,5 +16,5 @@ Werkzeug==2.2.1 zipp==3.8.1 requests simple-websocket -paho-mqtt +paho-mqtt<2.0.0 click \ No newline at end of file diff --git a/src/solarflow-status.py b/src/solarflow-status.py index 08a3be8..7dab187 100644 --- a/src/solarflow-status.py +++ b/src/solarflow-status.py @@ -226,12 +226,16 @@ def on_connect(client, userdata, flags, rc): def on_zendure_disconnect(client, userdata, rc): if rc != 0: - log.warning("Unexpected disconnection.") + log.warning("Unexpected Zendure disconnection.Disconnecting reason " +str(rc)) + client.loop_stop() + client.disconnect() zendure_mqtt_background_task() def on_local_disconnect(client, userdata, rc): if rc != 0: - log.warning("Unexpected disconnection.") + log.warning("Unexpected local MQTT disconnection. Disconnecting reason " +str(rc)) + client.loop_stop() + client.disconnect() local_mqtt_background_task() def connect_zendure_mqtt(client_id) -> mqtt_client: @@ -267,14 +271,17 @@ def zendure_subscribe(client: mqtt_client, auth: ZenAuth): def local_subscribe(client: mqtt_client): log.info(f'Subscribing to topics...') + report_topic = f'/{device_details["productKey"]}/+/properties/report' + log_topic = f'/{device_details["productKey"]}/+/log' + iot_topic = f'iot/{device_details["productKey"]}/+/properties/write' client.subscribe("solarflow-hub/telemetry/#") client.subscribe("solarflow-hub/control/#") client.subscribe("solarflow-hub/+/telemetry/#") client.subscribe("solarflow-hub/+/control/#") client.subscribe("solarflow-hub/smartmeter/homeUsage") - client.subscribe("/73bkTV/+/properties/report") - client.subscribe("/73bkTV/+/log") - client.subscribe("iot/73bkTV/+/properties/write") + client.subscribe(report_topic) + client.subscribe(log_topic) + client.subscribe(iot_topic) client.on_message = on_local_message def get_auth() -> ZenAuth: