Skip to content

Commit

Permalink
Added logging info, fixed colors for dark mode
Browse files Browse the repository at this point in the history
* Added: Show to which broker and port the connection was made when logging is set to INFO
* Added: Try to reconnect every 15 seconds to MQTT broker, if connection is closed abnormally
* Changed: Colors of cell voltage background on the cell voltages page to apply correctly the dark mode
  • Loading branch information
mr-manuel committed May 18, 2023
1 parent f11c777 commit 049046e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[flake8]
max-line-length = 180
max-line-length = 216
exclude =
./dbus-mqtt-battery/ext
./dbus-mqtt-battery/ext
extend-ignore:
# E203 whitespace before ':' conflicts with black code formatting. Will be ignored in flake8
E203
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v1.0.6
* Added: Show to which broker and port the connection was made when logging is set to INFO
* Added: Try to reconnect every 15 seconds to MQTT broker, if connection is closed abnormally
* Changed: Colors of cell voltage background on the cell voltages page to apply correctly the dark mode

## v1.0.5
* Added: Calculation of `ConsumedAmphours` when `InstalledCapacity` and `Capacity` is provided, if empty
* Added: Calculation of `ConsumedAmphours` and `Capacity` when `InstalledCapacity` is provided, if empty
Expand Down
20 changes: 12 additions & 8 deletions dbus-mqtt-battery/dbus-mqtt-battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,16 @@ def on_disconnect(client, userdata, rc):
else:
logging.warning('MQTT client: rc value:' + str(rc))

try:
logging.warning("MQTT client: Trying to reconnect")
client.connect(config['MQTT']['broker_address'])
connected = 1
except Exception as e:
logging.error("MQTT client: Error in retrying to connect with broker: %s" % e)
connected = 0
while connected == 0:
try:
logging.warning("MQTT client: Trying to reconnect")
client.connect(config['MQTT']['broker_address'])
connected = 1
except Exception as err:
logging.error(f"MQTT client: Error in retrying to connect with broker ({config['MQTT']['broker_address']}:{config['MQTT']['broker_port']}): {err}")
logging.error("MQTT client: Retrying in 15 seconds")
connected = 0
sleep(15)


def on_connect(client, userdata, flags, rc):
Expand Down Expand Up @@ -487,7 +490,7 @@ def __init__(
self._dbusservice.add_path('/ProductId', 0xFFFF)
self._dbusservice.add_path('/ProductName', productname)
self._dbusservice.add_path('/CustomName', customname)
self._dbusservice.add_path('/FirmwareVersion', '1.0.5')
self._dbusservice.add_path('/FirmwareVersion', '1.0.6 (20230518)')
# self._dbusservice.add_path('/HardwareVersion', '')
self._dbusservice.add_path('/Connected', 1)

Expand Down Expand Up @@ -578,6 +581,7 @@ def main():
client.username_pw_set(username=config['MQTT']['username'], password=config['MQTT']['password'])

# connect to broker
logging.info(f"MQTT client: Connecting to broker {config['MQTT']['broker_address']} on port {config['MQTT']['broker_port']}")
client.connect(
host=config['MQTT']['broker_address'],
port=int(config['MQTT']['broker_port'])
Expand Down
50 changes: 26 additions & 24 deletions dbus-mqtt-battery/qml/PageBatteryCellVoltages.qml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import com.victron.velib 1.0
MbPage {
id: root
property string bindPrefix
property MbStyle style: MbStyle{}

property VBusItem _b1: VBusItem { bind: service.path("/Balances/Cell1") }
property VBusItem _b2: VBusItem { bind: service.path("/Balances/Cell2") }
property VBusItem _b3: VBusItem { bind: service.path("/Balances/Cell3") }
Expand Down Expand Up @@ -52,30 +54,30 @@ MbPage {
property VBusItem volt22: VBusItem { bind: service.path("/Voltages/Cell22") }
property VBusItem volt23: VBusItem { bind: service.path("/Voltages/Cell23") }
property VBusItem volt24: VBusItem { bind: service.path("/Voltages/Cell24") }
property string c1: _b1.valid && _b1.text == "1" ? "#ff0000" : "#ddd"
property string c2: _b2.valid && _b2.text == "1" ? "#ff0000" : "#ddd"
property string c3: _b3.valid && _b3.text == "1" ? "#ff0000" : "#ddd"
property string c4: _b4.valid && _b4.text == "1" ? "#ff0000" : "#ddd"
property string c5: _b5.valid && _b5.text == "1" ? "#ff0000" : "#ddd"
property string c6: _b6.valid && _b6.text == "1" ? "#ff0000" : "#ddd"
property string c7: _b7.valid && _b7.text == "1" ? "#ff0000" : "#ddd"
property string c8: _b8.valid && _b8.text == "1" ? "#ff0000" : "#ddd"
property string c9: _b9.valid && _b9.text == "1" ? "#ff0000" : "#ddd"
property string c10: _b10.valid && _b10.text == "1" ? "#ff0000" : "#ddd"
property string c11: _b11.valid && _b11.text == "1" ? "#ff0000" : "#ddd"
property string c12: _b12.valid && _b12.text == "1" ? "#ff0000" : "#ddd"
property string c13: _b13.valid && _b13.text == "1" ? "#ff0000" : "#ddd"
property string c14: _b14.valid && _b14.text == "1" ? "#ff0000" : "#ddd"
property string c15: _b15.valid && _b15.text == "1" ? "#ff0000" : "#ddd"
property string c16: _b16.valid && _b16.text == "1" ? "#ff0000" : "#ddd"
property string c17: _b17.valid && _b17.text == "1" ? "#ff0000" : "#ddd"
property string c18: _b18.valid && _b18.text == "1" ? "#ff0000" : "#ddd"
property string c19: _b19.valid && _b19.text == "1" ? "#ff0000" : "#ddd"
property string c20: _b20.valid && _b20.text == "1" ? "#ff0000" : "#ddd"
property string c21: _b21.valid && _b21.text == "1" ? "#ff0000" : "#ddd"
property string c22: _b22.valid && _b22.text == "1" ? "#ff0000" : "#ddd"
property string c23: _b23.valid && _b23.text == "1" ? "#ff0000" : "#ddd"
property string c24: _b24.valid && _b24.text == "1" ? "#ff0000" : "#ddd"
property string c1: _b1.valid && _b1.text == "1" ? "#ff0000" : style.borderColor
property string c2: _b2.valid && _b2.text == "1" ? "#ff0000" : style.borderColor
property string c3: _b3.valid && _b3.text == "1" ? "#ff0000" : style.borderColor
property string c4: _b4.valid && _b4.text == "1" ? "#ff0000" : style.borderColor
property string c5: _b5.valid && _b5.text == "1" ? "#ff0000" : style.borderColor
property string c6: _b6.valid && _b6.text == "1" ? "#ff0000" : style.borderColor
property string c7: _b7.valid && _b7.text == "1" ? "#ff0000" : style.borderColor
property string c8: _b8.valid && _b8.text == "1" ? "#ff0000" : style.borderColor
property string c9: _b9.valid && _b9.text == "1" ? "#ff0000" : style.borderColor
property string c10: _b10.valid && _b10.text == "1" ? "#ff0000" : style.borderColor
property string c11: _b11.valid && _b11.text == "1" ? "#ff0000" : style.borderColor
property string c12: _b12.valid && _b12.text == "1" ? "#ff0000" : style.borderColor
property string c13: _b13.valid && _b13.text == "1" ? "#ff0000" : style.borderColor
property string c14: _b14.valid && _b14.text == "1" ? "#ff0000" : style.borderColor
property string c15: _b15.valid && _b15.text == "1" ? "#ff0000" : style.borderColor
property string c16: _b16.valid && _b16.text == "1" ? "#ff0000" : style.borderColor
property string c17: _b17.valid && _b17.text == "1" ? "#ff0000" : style.borderColor
property string c18: _b18.valid && _b18.text == "1" ? "#ff0000" : style.borderColor
property string c19: _b19.valid && _b19.text == "1" ? "#ff0000" : style.borderColor
property string c20: _b20.valid && _b20.text == "1" ? "#ff0000" : style.borderColor
property string c21: _b21.valid && _b21.text == "1" ? "#ff0000" : style.borderColor
property string c22: _b22.valid && _b22.text == "1" ? "#ff0000" : style.borderColor
property string c23: _b23.valid && _b23.text == "1" ? "#ff0000" : style.borderColor
property string c24: _b24.valid && _b24.text == "1" ? "#ff0000" : style.borderColor
title: service.description + " | Cell Voltages"

model: VisibleItemModel {
Expand Down

0 comments on commit 049046e

Please sign in to comment.