Last active
November 19, 2017 15:14
-
-
Save mpvader/94672c05d68bb6762859ba70240ea887 to your computer and use it in GitHub Desktop.
python script that creates dummy data from a battery monitor on D-Bus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Simple script that generates dummy data on the D-Bus. Its (only) | |
# the main readouts on com.victronenergy.battery. All alarms and | |
# history data are currently missing, but they are simply enough | |
# to add. For a complete list of data normally available see: | |
# https://github.com/victronenergy/venus/wiki/dbus#battery-monitor | |
# | |
# Note on update rate: | |
# All paths that change have an update rate of 1 Hz, in this script. | |
# 1 Hz is also the highest update rate within Venus. | |
# The difference between a real installation and this script is that | |
# normally not all paths update every second. Voltage is typically | |
# quite volatile, but soc can stay at the same level for hours. And | |
# then there are also no PropertiesChanged signals for SOC during those | |
# hours: the signal is only sent when something changes. Unlike for | |
# example nmea 0183 and nmea2000. | |
# | |
# Usage | |
# | |
# git clone https://github.com/victronenergy/velib_python.git | |
# | |
# the script requires the python-gobject package to be | |
# installed. ie run sudo apt-get install python-gobject | |
# | |
# then in that same directory add this file. | |
# run it from the commandline (./dummybattery.py) | |
# leave it running, and in another terminal you can now use | |
# a dbus client to see it. Info on how to look around on the | |
# D-Bus from the commandline is documented here: | |
# https://github.com/victronenergy/venus/wiki/commandline-introduction#working-with-d-bus | |
from dbus.mainloop.glib import DBusGMainLoop | |
import gobject | |
import argparse | |
import logging | |
import sys | |
import os | |
# our own packages | |
from dbusdummyservice import DbusDummyService | |
from logger import setup_logging | |
# Argument parsing | |
parser = argparse.ArgumentParser( | |
description='dummy dbus service' | |
) | |
parser.add_argument("-n", "--name", help="the D-Bus service you want me to claim", | |
type=str, default="com.victronenergy.battery.ttyO1") | |
args = parser.parse_args() | |
print(__file__ + " is starting up, use -h argument to see optional arguments") | |
logger = setup_logging(debug=True) | |
# Have a mainloop, so we can send/receive asynchronous calls to and from dbus | |
DBusGMainLoop(set_as_default=True) | |
s = DbusDummyService( | |
servicename=args.name, | |
deviceinstance=0, | |
paths={ | |
'/Soc': {'initial': 100, 'update': -1}, | |
'/Dc/0/Voltage': {'initial': 24.3, 'update': 0.1}, | |
'/Dc/0/Current': {'initial': 2, 'update': 0.1}, | |
'/Dc/0/Power': {'initial': 48.6, 'update': 0.1}}, | |
productname='BMV-700', | |
connection='VE.Direct port 1') | |
logger.info('Connected to dbus, and switching over to gobject.MainLoop() (= event based)') | |
mainloop = gobject.MainLoop() | |
mainloop.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment