Skip to content

Commit

Permalink
added timeout on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-manuel committed Dec 18, 2023
1 parent 049046e commit f9cdb39
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## v1.0.7
* Added: Timeout on driver startup. Prevents problems, if the MQTT broker is not reachable on driver startup

## 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
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
I wrote this script for myself. I'm not responsible, if you damage something using my script.


## Supporting/Sponsoring this project

You like the project and you want to support me?

[<img src="https://github.md0.eu/uploads/donate-button.svg" height="50">](https://www.paypal.com/donate/?hosted_button_id=3NEVZBDM5KABW)


### Purpose

The script emulates a battery in Venus OS. It gets the MQTT data from a subscribed topic and publishes the information on the dbus as the service `com.victronenergy.battery.mqtt_battery` with the VRM instance `41`.
Expand Down Expand Up @@ -255,10 +262,3 @@ It was tested on following devices:
![MQTT Battery - device list - mqtt battery](/screenshots/battery_device_list_mqtt-battery_12.png)
</details>
## Supporting/Sponsoring this project
You like the project and you want to support me?
[<img src="https://github.md0.eu/uploads/donate-button.svg" height="50">](https://www.paypal.com/donate/?hosted_button_id=3NEVZBDM5KABW)
11 changes: 10 additions & 1 deletion dbus-mqtt-battery/dbus-mqtt-battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,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.6 (20230518)')
self._dbusservice.add_path('/FirmwareVersion', '1.0.7 (20231218)')
# self._dbusservice.add_path('/HardwareVersion', '')
self._dbusservice.add_path('/Connected', 1)

Expand Down Expand Up @@ -595,6 +595,15 @@ def main():
logging.info("Waiting 5 seconds for receiving first data...")
else:
logging.warning("Waiting since %s seconds for receiving first data..." % str(i * 5))

# check if timeout was exceeded
if timeout <= (i * 5):
logging.error(
"Driver stopped. Timeout of %i seconds exceeded, since no new MQTT message was received in this time."
% timeout
)
sys.exit()

sleep(5)
i += 1

Expand Down
3 changes: 2 additions & 1 deletion dbus-mqtt-battery/installqml.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
set -x
# set -x

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

# elaborate version string for better comparing
Expand Down

0 comments on commit f9cdb39

Please sign in to comment.