Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serial starter #1

Merged
merged 4 commits into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
# dbus-serialbattery
dbus driver for serial battery in VenusOS
This is a driver for VenusOS devices (any GX device sold by Victron or a Raspberry Pi running the VenusOS image).

The driver will communicate with a Battery Management System (BMS) that support serial communication (RS232 or RS485)
and publish this data to the dbus used by VenusOS. The main purpose is to supply up to date State Of Charge (SOC) values
to the inverter, but many extra parameters is also published if available from the BMS.

Driver support:
* Smart BMS range from [LLT Power](https://www.lithiumbatterypcb.com/product-instructionev-battery-pcb-boardev-battery-pcb-board/ev-battery-pcb-board/smart-bms-of-power-battery/)
(Cell values are currently only supported for the first 16 cells: Min Cell V, Max Cell V, Cell Balance)

Planned support:
* AntBMS
* Smart Daly BMS

### How to install
1. You need to have a VenusOS device set up and running on your system and have [root access](https://www.victronenergy.com/live/ccgx:root_access).
2. You also need to connect your BMS to the VenusOS device using a serial interface. A USB->232 converter like the FT232R. The FT232R already has a driver included in the VenusOS.
3. Use a FTP client that support SFTP to copy the driver files to the rooted VenusOS device. [Filezilla](https://filezilla-project.org/) is a good option
- copy the dbus-serialbattery folder to `/data/etc/`
- copy or move rc.local to `/data/`
- copy or move serial-starter.d to `/data/conf/`
- reboot your VenusOS device and check if your battery is connected
15 changes: 12 additions & 3 deletions dbus-serialbattery.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python -u
#!/usr/bin/python
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, print_function, unicode_literals
Expand Down Expand Up @@ -136,6 +136,8 @@ def is_bit_set(self, tmp):

def to_cell_bits(self, byte_data):
tmp = bin(byte_data)[2:].rjust(self.cell_count, self.zero_char)
for c in self.cells:
self.cells.remove(c)
for bit in reversed(tmp):
self.cells.append(Cell(self.is_bit_set(bit)))

Expand Down Expand Up @@ -322,7 +324,7 @@ def setup_vedbus(self, instance):
self._dbusservice.add_path('/Alarms/LowTemperature', 0, writeable=True)


INTERVAL = 3000
INTERVAL = 2000


def main():
Expand All @@ -338,8 +340,15 @@ def poll_battery(loop):
logger.info('dbus-serialbattery')
# Have a mainloop, so we can send/receive asynchronous calls to and from dbus
DBusGMainLoop(set_as_default=True)

# Get the port we need to use from the argument
if len(sys.argv) > 1:
port = sys.argv[1]
else:
logger.info('No Port')
port = '/dev/ttyUSB2'

# create a new battery object that can read the battery
port = '/dev/ttyUSB2'
battery = Battery(port)
result = battery.read_hardware_data()
if result is False:
Expand Down
2 changes: 2 additions & 0 deletions rc.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
ln -s /data/etc/dbus-serialbattery /opt/victronenergy/dbus-serialbattery
2 changes: 2 additions & 0 deletions serial-starter.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
service sbattery dbus-serialbattery
alias default sbattery
3 changes: 3 additions & 0 deletions service/log/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
exec 2>&1
exec multilog t s25000 n4 /var/log/dbus-serialbattery.TTY
3 changes: 3 additions & 0 deletions service/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
exec 2>&1
exec softlimit -d 100000000 -s 1000000 -a 100000000 python /opt/victronenergy/dbus-serialbattery/dbus-serialbattery.py /dev/TTY