A lightweight docker container for maintaining a reliable connection to the Victron MQTT broker.
This project implements a container and a threaded Python system that connects to a Victron MQTT broker, performing regular keepalive checks, and gracefully handling disconnections by restarting the connection logic. It is optimized for use in Docker containers and uses only the minimal required dependencies.
The application is split across three main threads implemented in two classes:
-
thdKeepAlive:
A thread responsible for sending periodic keepalive pings to check the health of the connection. -
thdReceiver:
A thread that handles the MQTT connection and data reception from the Victron broker. -
Main Controller (in
main.pyor equivalent):
Manages the lifecycle of the threads:- Starts and monitors the keepalive and receiver threads.
- Automatically stops and restarts the receiver if the keepalive thread indicates a failure (with some hysteresis to avoid flapping).
- Planned: Periodically checks the MQTT broker address for changes.
- Thread-based concurrency: Simple and robust compared to multiprocessing in Docker.
- Graceful recovery: Auto-restarts receiver thread on connection failure.
- Minimal dependencies: Only core libraries and essentials:
paho-mqttrequestsjsonsslconfigparserinfluxdb
- Configurable via INI: Easily adjustable settings through a config file.
- Structured logging: Outputs logs in format
[CLASS] (YYYY-MM-DD HH:MM:SS).
[x] Stable core implementation [x] Integrated logging [x] Docker-friendly
[] Dynamic broker IP re-check (planned) [] Topic parsing from Victron's VE.PROTOCOL 3.34
This client is currently being tested with a Victron Cerbo GX test unit in the lab.
- Confirmed operational for over 12 hours continuously.
- Successfully runs in a Docker container (most-giroe-victron:sdi).
- Coexists with older container instances without issue.
- Manual disconnection testing is ongoing to confirm resilience.
Clone the repo and set up your testing environment:
git clone https://github.com/delloiaconos/MOST-Victron-Clinet.git cd most-victron-client python3 -m venv .env source .env/bin/activate pip install -r requirements.txt python main.py
This project includes two helper scripts: build.sh and run.sh to simplify Docker image creation and container management.
The makefile script can build and run the Docker image for the Victron MQTT client.
make build
This command:
- Executes docker build using the local Dockerfile.
- Tags the image (e.g.,
most-victron-client:devel— check your script for the exact tag).
To start a new container from the previously built image, use the following command:
make run
This command:
- Launches the Docker container using the last devel image available.
- Mounts required volumes or binds configuration files (e.g., development.ini).
- Install ansible
- Install collections:
ansible-galaxy collection install community.docker
- Run the playbook
ansible-playbook create_containers.yml --ask-become-pass
A custom command has been added to the Makefile
make ansible-deploy
curl -X POST "https://vrmapi.victronenergy.com/v2/auth/login" \ -H "Content-Type: application/json" \ -d '{"username":"[email protected]","password":"SecretPassword"}'
This project is version-controlled via Git for clarity and development hygiene — no CI/CD or advanced Git-based deployments are planned. If you'd like access to the repository, just ask the maintainer.
Victron VE.Direct Protocol v3.34
This study was carried out within the MOST - Sustainable Mobility National Research Center and received funding from the European Union Next-GenerationEU (PIANO NAZIONALE DI RIPRESA E RESILIENZA (PNRR) - MISSIONE 4 COMPONENTE 2, INVESTIMENTO 1.4 - D.D. 1033 17/06/2022, CN00000023), Spoke 5 "Light Vehicle and Active Mobility". This work/code/repository reflects only the authors’ views and opinions, neither the European Union nor the European Commission can be considered responsible for them.