Skip to content

Commit

Permalink
Merge branch 'development' into jbd-bms-support
Browse files Browse the repository at this point in the history
  • Loading branch information
MoleBre committed Sep 8, 2024
2 parents aa8140c + cec4003 commit 4ae8884
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
platformio-device-monitor*.log
logs/device-monitor*.log
platformio_override.ini
webapp_dist/
.DS_Store
2 changes: 1 addition & 1 deletion include/BatteryStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class BatteryStats {
uint32_t getAgeSeconds() const { return (millis() - _lastUpdate) / 1000; }
bool updateAvailable(uint32_t since) const;

uint8_t getSoC() const { return _soc; }
float getSoC() const { return _soc; }
uint32_t getSoCAgeSeconds() const { return (millis() - _lastUpdateSoC) / 1000; }
uint8_t getSoCPrecision() const { return _socPrecision; }

Expand Down
4 changes: 2 additions & 2 deletions include/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@
#define POWERLIMITER_VOLTAGE_LOAD_CORRECTION_FACTOR 0.001
#define POWERLIMITER_RESTART_HOUR -1
#define POWERLIMITER_FULL_SOLAR_PASSTHROUGH_SOC 100
#define POWERLIMITER_FULL_SOLAR_PASSTHROUGH_START_VOLTAGE 100.0
#define POWERLIMITER_FULL_SOLAR_PASSTHROUGH_STOP_VOLTAGE 100.0
#define POWERLIMITER_FULL_SOLAR_PASSTHROUGH_START_VOLTAGE 66.0
#define POWERLIMITER_FULL_SOLAR_PASSTHROUGH_STOP_VOLTAGE 66.0

#define BATTERY_ENABLED false
#define BATTERY_PROVIDER 0 // Pylontech CAN receiver
Expand Down
65 changes: 65 additions & 0 deletions pio-scripts/compile_webapp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import os
import hashlib
import pickle
import subprocess

def check_files(directories, filepaths, hash_file):
old_file_hashes = {}
file_hashes = {}

for directory in directories:
for root, dirs, filenames in os.walk(directory):
for file in filenames:
filepaths.append(os.path.join(root, file))

for file_path in filepaths:
with open(file_path, 'rb') as f:
file_data = f.read()
file_hashes[file_path] = hashlib.md5(file_data).hexdigest()

if os.path.exists(hash_file):
with open(hash_file, 'rb') as f:
old_file_hashes = pickle.load(f)

update = False
for file_path, file_hash in file_hashes.items():
if file_path not in old_file_hashes or old_file_hashes[file_path] != file_hash:
update = True
break

if not update:
print("webapp artifacts should be up-to-date")
return

print("compiling webapp (hang on, this can take a while and there might be little output)...")

try:
# if these commands fail, an exception will prevent us from
# persisting the current hashes => commands will be executed again
subprocess.run(["yarn", "--cwd", "webapp", "install", "--frozen-lockfile"],
check=True)

subprocess.run(["yarn", "--cwd", "webapp", "build"], check=True)

except FileNotFoundError:
raise Exception("it seems 'yarn' is not installed/available on your system")

with open(hash_file, 'wb') as f:
pickle.dump(file_hashes, f)

def main():
if os.getenv('GITHUB_ACTIONS') == 'true':
print("INFO: not testing for up-to-date webapp artifacts when running as Github action")
return 0

print("INFO: testing for up-to-date webapp artifacts")

directories = ["webapp/src/", "webapp/public/"]
files = ["webapp/index.html", "webapp/tsconfig.config.json",
"webapp/tsconfig.json", "webapp/vite.config.ts",
"webapp/yarn.lock"]
hash_file = "webapp_dist/.hashes.pkl"

check_files(directories, files, hash_file)

main()
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ lib_deps =
plerup/EspSoftwareSerial @ ^8.2.0

extra_scripts =
pre:pio-scripts/compile_webapp.py
pre:pio-scripts/auto_firmware_version.py
pre:pio-scripts/patch_apply.py
post:pio-scripts/create_factory_bin.py
Expand Down
2 changes: 1 addition & 1 deletion src/PowerLimiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ void PowerLimiterClass::loop()
_batteryDischargeEnabled = getBatteryPower();

if (_verboseLogging && !config.PowerLimiter.IsInverterSolarPowered) {
MessageOutput.printf("[DPL::loop] battery interface %s, SoC: %d %%, StartTH: %d %%, StopTH: %d %%, SoC age: %d s, ignore: %s\r\n",
MessageOutput.printf("[DPL::loop] battery interface %s, SoC: %f %%, StartTH: %d %%, StopTH: %d %%, SoC age: %d s, ignore: %s\r\n",
(config.Battery.Enabled?"enabled":"disabled"),
Battery.getStats()->getSoC(),
config.PowerLimiter.BatterySocStartThreshold,
Expand Down
2 changes: 1 addition & 1 deletion src/PylontechCanReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void PylontechCanReceiver::onMessage(twai_message_t rx_message)
_stats->_stateOfHealth = this->readUnsignedInt16(rx_message.data + 2);

if (_verboseLogging) {
MessageOutput.printf("[Pylontech] soc: %d soh: %d\r\n",
MessageOutput.printf("[Pylontech] soc: %f soh: %d\r\n",
_stats->getSoC(), _stats->_stateOfHealth);
}
break;
Expand Down
2 changes: 1 addition & 1 deletion src/PytesCanReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void PytesCanReceiver::onMessage(twai_message_t rx_message)
_stats->_stateOfHealth = this->readUnsignedInt16(rx_message.data + 2);

if (_verboseLogging) {
MessageOutput.printf("[Pytes] soc: %d soh: %d\r\n",
MessageOutput.printf("[Pytes] soc: %f soh: %d\r\n",
_stats->getSoC(), _stats->_stateOfHealth);
}
break;
Expand Down
6 changes: 1 addition & 5 deletions webapp/src/views/PowerLimiterAdminView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -501,11 +501,7 @@ export default defineComponent({
canUseSolarPassthrough() {
const cfg = this.powerLimiterConfigList;
const meta = this.powerLimiterMetaData;
const canUse = this.isEnabled() && meta.charge_controller_enabled && !cfg.is_inverter_solar_powered;
if (!canUse) {
cfg.solar_passthrough_enabled = false;
}
return canUse;
return this.isEnabled() && meta.charge_controller_enabled && !cfg.is_inverter_solar_powered;
},
canUseSoCThresholds() {
const cfg = this.powerLimiterConfigList;
Expand Down
Binary file removed webapp_dist/favicon.ico
Binary file not shown.
Binary file removed webapp_dist/favicon.png
Binary file not shown.
Binary file removed webapp_dist/index.html.gz
Binary file not shown.
Binary file removed webapp_dist/js/app.js.gz
Binary file not shown.
13 changes: 0 additions & 13 deletions webapp_dist/site.webmanifest

This file was deleted.

Binary file removed webapp_dist/zones.json.gz
Binary file not shown.

0 comments on commit 4ae8884

Please sign in to comment.