Skip to content

Commit

Permalink
Changes 2023.05.24 (#667)
Browse files Browse the repository at this point in the history
* Check Venus OS version before installing
  • Loading branch information
mr-manuel committed May 24, 2023
1 parent f19e004 commit fc95f6b
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 33 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,22 @@
* Added: Balancing switch status to the GUI -> SerialBattery -> IO by @mr-manuel
* Added: Block charge/discharge when BMS communication is lost. Can be enabled trough the config file by @mr-manuel
* Added: Charge Mode display by @mr-manuel
* Added: Check minimum required Venus OS version before installing by @mr-manuel
* Added: Choose how battery temperature is assembled (mean temp 1 & 2, only temp 1 or only temp 2) by @mr-manuel
* Added: Config file by @ppuetsch
* Added: Create empty `config.ini` for easier user usage by @mr-manuel
* Added: Cronjob to restart Bluetooth service every 12 hours by @mr-manuel
* Added: Daly BMS - Discharge / Charge Mosfet switching over remote console/GUI https://github.com/Louisvdw/dbus-serialbattery/issues/26 by @transistorgit
* Added: Daly BMS - Read capacity https://github.com/Louisvdw/dbus-serialbattery/pull/594 by @transistorgit
* Added: Daly BMS - Read production date and build unique identifier by @transistorgit
* Added: Daly BMS - Set SoC by @transistorgit
* Added: Daly BMS - Show "battery code" field that can be set in the Daly app by @transistorgit
* Added: Daly BMS - Discharge / Charge Mosfet switching over remote console/GUI https://github.com/Louisvdw/dbus-serialbattery/issues/26 by @transistorgit
* Added: Device name field (found in the GUI -> SerialBattery -> Device), that show a custom string that can be set in some BMS, if available by @mr-manuel
* Added: Driver uninstall script by @mr-manuel
* Added: Rename TAR file after USB/SD card install to not overwrite the data on every reboot https://github.com/Louisvdw/dbus-serialbattery/issues/638 by @mr-manuel
* Added: Fix for Venus OS >= v3.00~14 showing unused items https://github.com/Louisvdw/dbus-serialbattery/issues/469 by @mr-manuel
* Added: HeltecSmartBMS driver by @ramack
* Added: HighInternalTemperature alarm (MOSFET) for JKBMS by @mr-manuel
* Added: HLPdata BMS driver by @ peterohman
* Added: Improved maintainability (flake8, black lint), introduced code checks and automate release build https://github.com/Louisvdw/dbus-serialbattery/pull/386 by @ppuetsch
* Added: Install needed Bluetooth components automatically after a Venus OS upgrade by @mr-manuel
* Added: JKBMS - MOS temperature https://github.com/Louisvdw/dbus-serialbattery/pull/440 by @baphomett
Expand All @@ -45,8 +47,10 @@
* Added: Post install notes by @mr-manuel
* Added: Read charge/discharge limits from JKBMS by @mr-manuel
* Added: Recalculation interval in linear mode for CVL, CCL and DCL by @mr-manuel
* Added: Rename TAR file after USB/SD card install to not overwrite the data on every reboot https://github.com/Louisvdw/dbus-serialbattery/issues/638 by @mr-manuel
* Added: Reset values to None, if battery goes offline (not reachable for 10s). Fixes https://github.com/Louisvdw/dbus-serialbattery/issues/193 https://github.com/Louisvdw/dbus-serialbattery/issues/64 by @transistorgit
* Added: Script to install directly from repository by @mr-manuel
* Added: Seplos BMS driver by @wollew
* Added: Serial number field (found in the GUI -> SerialBattery -> Device), that show the serial number or a unique identifier for the BMS, if available by @mr-manuel
* Added: Show charge mode (absorption, bulk, ...) in Parameters page by @mr-manuel
* Added: Show charge/discharge limitation reason by @mr-manuel
Expand Down
132 changes: 101 additions & 31 deletions etc/dbus-serialbattery/reinstall-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,63 @@

DRIVERNAME=dbus-serialbattery


# check if minimum required Venus OS is installed | start
versionRequired="v2.90"

# elaborate version string for better comparing
# https://github.com/kwindrem/SetupHelper/blob/ebaa65fcf23e2bea6797f99c1c41174143c1153c/updateFileSets#L56-L81
function versionStringToNumber ()
{
local local p4="" ; local p5="" ; local p5=""
local major=""; local minor=""

# first character should be 'v' so first awk parameter will be empty and is not prited into the read command
#
# version number formats: v2.40, v2.40~6, v2.40-large-7, v2.40~6-large-7
# so we must adjust how we use paramters read from the version string
# and parsed by awk
# if no beta make sure release is greater than any beta (i.e., a beta portion of 999)

read major minor p4 p5 p6 <<< $(echo $1 | awk -v FS='[v.~-]' '{print $2, $3, $4, $5, $6}')
((versionNumber = major * 1000000000 + minor * 1000000))
if [ -z $p4 ] || [ $p4 = "large" ]; then
((versionNumber += 999))
else
((versionNumber += p4))
fi
if [ ! -z $p4 ] && [ $p4 = "large" ]; then
((versionNumber += p5 * 1000))
large=$p5
elif [ ! -z $p6 ]; then
((versionNumber += p6 * 1000))
fi
}

# get current Venus OS version
versionStringToNumber "$(head -n 1 /opt/victronenergy/version)"
venusVersionNumber="$versionNumber"

# minimum required version to install the driver
versionStringToNumber "$versionRequired"

if (( $venusVersionNumber < $versionNumber )); then
echo
echo
echo "Minimum required Venus OS version \"$versionRequired\" not met. Currently version \"$(head -n 1 /opt/victronenergy/version)\" is installed."
echo
echo "Please update via \"Remote Console/GUI -> Settings -> Firmware -> Online Update\""
echo "OR"
echo "by executing \"/opt/victronenergy/swupdate-scripts/check-updates.sh -update -force\""
echo
echo "Install the driver again after Venus OS was updated."
echo
echo
exit 1
fi
# check if minimum required Venus OS is installed | end


# handle read only mounts
bash /opt/victronenergy/swupdate-scripts/remount-rw.sh

Expand All @@ -24,38 +81,47 @@ serialstarter_path="/data/conf/serial-starter.d"
serialstarter_file="$serialstarter_path/dbus-serialbattery.conf"

# check if folder is a file (older versions of this driver < v1.0.0)
if [ -f $serialstarter_path ]; then
rm -f $serialstarter_path
if [ -f "$serialstarter_path" ]; then
rm -f "$serialstarter_path"
fi

# check if folder exists
if [ ! -d $serialstarter_path ]; then
mkdir $serialstarter_path
if [ ! -d "$serialstarter_path" ]; then
mkdir "$serialstarter_path"
fi

# check if file exists
if [ ! -f $serialstarter_file ]; then
echo "service sbattery dbus-serialbattery" >> $serialstarter_file
echo "alias default gps:vedirect:sbattery" >> $serialstarter_file
echo "alias rs485 cgwacs:fzsonick:imt:modbus:sbattery" >> $serialstarter_file
if [ ! -f "$serialstarter_file" ]; then
{
echo "service sbattery dbus-serialbattery"
echo "alias default gps:vedirect:sbattery"
echo "alias rs485 cgwacs:fzsonick:imt:modbus:sbattery"
} > "$serialstarter_file"
fi

# add install-script to rc.local to be ready for firmware update
filename=/data/rc.local
if [ ! -f $filename ]; then
echo "#!/bin/bash" >> $filename
chmod 755 $filename
if [ ! -f "$filename" ]; then
echo "#!/bin/bash" > "$filename"
chmod 755 "$filename"
fi
grep -qxF "bash /data/etc/$DRIVERNAME/reinstall-local.sh" $filename || echo "bash /data/etc/$DRIVERNAME/reinstall-local.sh" >> $filename

# add empty config.ini, if it does not exist to make it easier for users to add custom settings
filename=/data/etc/$DRIVERNAME/config.ini
if [ ! -f $filename ]; then
echo "[DEFAULT]" > $filename
echo "" >> $filename
echo "; If you want to add custom settings, then check the settings you want to change in \"config.default.ini\"" >> $filename
echo "; and add them below to persist future driver updates." >> $filename
echo "" >> $filename
filename="/data/etc/$DRIVERNAME/config.ini"
if [ ! -f "$filename" ]; then
{
echo "[DEFAULT]"
echo
echo "; If you want to add custom values/settings, then check the values/settings you want to change in \"config.default.ini\""
echo "; and insert them below to persist future driver updates."
echo
echo "; Example (remove the semicolon \";\" to uncomment and activate the value/setting):"
echo "; MAX_BATTERY_CURRENT = 50.0"
echo "; MAX_BATTERY_DISCHARGE_CURRENT = 60.0"
echo
echo
} > $filename
fi


Expand Down Expand Up @@ -84,7 +150,7 @@ rm -rf /service/dbus-blebattery.*
# kill all blebattery processes
pkill -f "blebattery"

if [ $length -gt 0 ]; then
if [ "$length" -gt 0 ]; then

echo "Found $length Bluetooth BMS in the config file!"
echo ""
Expand All @@ -101,16 +167,20 @@ if [ $length -gt 0 ]; then

# function to install ble battery
install_blebattery_service() {
mkdir -p /service/dbus-blebattery.$1/log
echo "#!/bin/sh" > /service/dbus-blebattery.$1/log/run
echo "exec multilog t s25000 n4 /var/log/dbus-blebattery.$1" >> /service/dbus-blebattery.$1/log/run
chmod 755 /service/dbus-blebattery.$1/log/run

echo "#!/bin/sh" > /service/dbus-blebattery.$1/run
echo "exec 2>&1" >> /service/dbus-blebattery.$1/run
echo "bluetoothctl disconnect $3" >> /service/dbus-blebattery.$1/run
echo "python /opt/victronenergy/dbus-serialbattery/dbus-serialbattery.py $2 $3" >> /service/dbus-blebattery.$1/run
chmod 755 /service/dbus-blebattery.$1/run
mkdir -p "/service/dbus-blebattery.$1/log"
{
echo "#!/bin/sh"
echo "exec multilog t s25000 n4 /var/log/dbus-blebattery.$1"
} > "/service/dbus-blebattery.$1/log/run"
chmod 755 "/service/dbus-blebattery.$1/log/run"

{
echo "#!/bin/sh"
echo "exec 2>&1"
echo "bluetoothctl disconnect $3"
echo "python /opt/victronenergy/dbus-serialbattery/dbus-serialbattery.py $2 $3"
} > "/service/dbus-blebattery.$1/run"
chmod 755 "/service/dbus-blebattery.$1/run"
}

echo "Packages installed."
Expand All @@ -119,7 +189,7 @@ if [ $length -gt 0 ]; then
# install_blebattery_service 0 Jkbms_Ble C8:47:8C:00:00:00
# install_blebattery_service 1 Jkbms_Ble C8:47:8C:00:00:11

for (( i=0; i<${length}; i++ ));
for (( i=0; i<length; i++ ));
do
echo "Installing ${bms_array[$i]} as dbus-blebattery.$i"
install_blebattery_service $i "${bms_array[$i]}"
Expand Down Expand Up @@ -152,7 +222,7 @@ sed -i "/^sh \/data\/etc\/dbus-serialbattery\/installble.sh/d" /data/rc.local
pkill -f "python .*/$DRIVERNAME.py"

# restart bluetooth service, if Bluetooth BMS configured
if [ $length -gt 0 ]; then
if [ "$length" -gt 0 ]; then
/etc/init.d/bluetooth restart
fi

Expand Down

0 comments on commit fc95f6b

Please sign in to comment.