Skip to content

Commit

Permalink
Make statuspage work with HUB 2000 in online mode (#46)
Browse files Browse the repository at this point in the history
* Make statuspage work with HUB 2000 in online mode

* Properly dispose background MQTT tasks
  • Loading branch information
mdillmann authored Jun 5, 2024
1 parent 5272eed commit 2bb36bf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ MQTT_USER = <mqtt user>
MQTT_PWD = <mqtt user password>
```

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
Expand Down
2 changes: 1 addition & 1 deletion src/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ Werkzeug==2.2.1
zipp==3.8.1
requests
simple-websocket
paho-mqtt
paho-mqtt<2.0.0
click
17 changes: 12 additions & 5 deletions src/solarflow-status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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'

This comment has been minimized.

Copy link
@reinhard-brandstaedter

reinhard-brandstaedter Jun 25, 2024

Owner

device_details["productKey"] doesn't exist at this point

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:
Expand Down

0 comments on commit 2bb36bf

Please sign in to comment.