Skip to content

Commit 7320437

Browse files
committed
bms data display toggles
1 parent a966479 commit 7320437

File tree

10 files changed

+89
-27
lines changed

10 files changed

+89
-27
lines changed

src/Client/Pages/BMS.razor

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<PageTitle>JK BMS Status</PageTitle>
77

8-
<Loader Enabled=@(status is null)/>
8+
<Loader Enabled=@(status is null) />
99

1010
@if (status is not null)
1111
{
@@ -24,8 +24,8 @@
2424
<div class="fs-1 my-1 mx-5 border-top">
2525
@status.CapacityPct%
2626
</div>
27-
<div class="fs-5 m-0 border-top">
28-
@Math.Round(status.AvailableCapacity, 1) Ah / @status.PackCapacity Ah
27+
<div class="fs-5 m-0 border-top" style="cursor: pointer;" @onclick="_ => ShowCapacityKwh = !ShowCapacityKwh">
28+
@(GetPackCapacity())
2929
</div>
3030
</div>
3131
<div class="col bg-light">
@@ -41,14 +41,14 @@
4141
<div class="fw-bold fs-6 text-secondary">
4242
@($"{status.CRate:0.00} C") / @($"{status.AvgPowerWatts:0} W")
4343
</div>
44-
<div class="fw-normal fs-6 m-0 p-0">
45-
@status.TimeHrs Hrs @status.TimeMins Mins
44+
<div class="fw-normal fs-6 m-0 p-0" style="cursor: pointer;" @onclick="_ => ShowEndDateAndTime = !ShowEndDateAndTime">
45+
@(GetTimeLeft())
4646
</div>
4747
}
4848
@if (status.AvgCurrentAmps == 0)
4949
{
5050
<div class="fs-5 m-0 p-0 text-muted">
51-
Holding<br/>Voltage
51+
Holding<br />Voltage
5252
</div>
5353
}
5454
@if (status.IsWarning)
@@ -127,6 +127,8 @@
127127
private static event Action<BMSStatus?>? onStatusUpdated;
128128
private static event Action? onStatusRetrievalError;
129129
private static BMSStatus? status;
130+
private static bool ShowEndDateAndTime;
131+
private static bool ShowCapacityKwh;
130132

131133
protected override void OnInitialized()
132134
{
@@ -146,6 +148,26 @@
146148
StateHasChanged();
147149
}
148150

151+
private string GetTimeLeft()
152+
{
153+
if (ShowEndDateAndTime)
154+
{
155+
return status!.GetTimeString();
156+
}
157+
return $"{status!.TimeHrs} Hrs {status.TimeMins} Mins";
158+
}
159+
160+
private string GetPackCapacity()
161+
{
162+
if (ShowCapacityKwh)
163+
{
164+
var avlCap = Math.Round((status!.AvailableCapacity * status.PackNominalVoltage) / 1000, 1);
165+
var packCap = Math.Round((status!.PackCapacity * status.PackNominalVoltage) / 1000, 1);
166+
return $"{avlCap} kWh / {packCap} kWh";
167+
}
168+
return $"{Math.Round(status!.AvailableCapacity, 1)} Ah / {status!.PackCapacity} Ah";
169+
}
170+
149171
public void Dispose()
150172
{
151173
onStatusUpdated -= UpdateState;
@@ -160,10 +182,10 @@
160182
// which leads to a memory leak/ connection exhaustion.
161183
162184
using var client = new HttpClient
163-
{
164-
BaseAddress = new(basePath),
165-
Timeout = TimeSpan.FromSeconds(5)
166-
};
185+
{
186+
BaseAddress = new(basePath),
187+
Timeout = TimeSpan.FromSeconds(5)
188+
};
167189

168190
var retryDelay = 1000;
169191

@@ -183,10 +205,10 @@
183205
JsonSerializer.DeserializeAsyncEnumerable<BMSStatus>(
184206
stream,
185207
new JsonSerializerOptions
186-
{
187-
PropertyNameCaseInsensitive = true,
188-
DefaultBufferSize = 64
189-
}))
208+
{
209+
PropertyNameCaseInsensitive = true,
210+
DefaultBufferSize = 64
211+
}))
190212
{
191213
onStatusUpdated?.Invoke(s);
192214
retryDelay = 1000;

src/Client/Pages/Settings.razor

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,19 @@
253253
</div>
254254
</div>
255255
</div>
256+
<div class="row border-primary bg-light px-3 mt-1">
257+
<div class="col-6 my-auto fw-bold">
258+
Battery Voltage:
259+
</div>
260+
<div class="col-6 p-2 bg-secondary">
261+
<div class="row">
262+
<div style="width:4.75rem;">
263+
<input type="number" class="form-control bg-light" @bind-value=settings.SystemSpec.BatteryNominalVoltage>
264+
</div>
265+
<div class="col-1 fw-bolder fs-5 m-1 text-white">V</div>
266+
</div>
267+
</div>
268+
</div>
256269
<div class="row border-primary bg-light px-3 mt-1">
257270
<div class="col-6 my-auto fw-bold">
258271
Daylight Start (24hr format):

src/Server/BatteryService/JK-BMS-RS485-Service.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using InverterMon.Shared.Models;
1+
using InverterMon.Server.Persistance.Settings;
2+
using InverterMon.Shared.Models;
23
using SerialPortLib;
34

45
namespace InverterMon.Server.BatteryService;
@@ -12,7 +13,7 @@ public class JkBms
1213
readonly AmpValQueue _recentAmpReadings = new(5); //avg value over 5 readings (~5secs)
1314
readonly SerialPortInput _bms = new();
1415

15-
public JkBms(IConfiguration config, ILogger<JkBms> logger, IWebHostEnvironment env, IHostApplicationLifetime appLife)
16+
public JkBms(UserSettings userSettings, IConfiguration config, ILogger<JkBms> logger, IWebHostEnvironment env, IHostApplicationLifetime appLife)
1617
{
1718
if (env.IsDevelopment())
1819
{
@@ -21,6 +22,7 @@ public JkBms(IConfiguration config, ILogger<JkBms> logger, IWebHostEnvironment e
2122
return;
2223
}
2324

25+
Status.PackNominalVoltage = userSettings.BatteryNominalVoltage;
2426
var bmsAddress = config["LaunchSettings:JkBmsAddress"] ?? "/dev/ttyUSB0";
2527
_bms.SetPort(bmsAddress);
2628
_bms.ConnectionStatusChanged += ConnectionStatusChanged;
@@ -126,11 +128,12 @@ void FillDummyData()
126128
Status.PackVoltage = 25.6f;
127129
Status.IsCharging = true;
128130
Status.AvgCurrentAmps = 21.444f;
129-
Status.CapacityPct = 50;
131+
Status.CapacityPct = 48;
130132
Status.PackCapacity = 120;
133+
Status.PackNominalVoltage = 50;
131134
Status.IsWarning = false;
132-
Status.TimeHrs = 3;
133-
Status.TimeMins = 11;
135+
Status.TimeHrs = 24;
136+
Status.TimeMins = 10;
134137
for (byte i = 1; i <= 8; i++)
135138
Status.Cells.Add(i, 1.110f);
136139
}

src/Server/Endpoints/Settings/SetSystemSpec/Validator.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ public Validator()
1818
RuleFor(x => x.SunlightEndHour)
1919
.GreaterThanOrEqualTo(0)
2020
.LessThanOrEqualTo(24)
21-
.Must((s, h) => h > s.SunlightStartHour).WithMessage("Sunlight end hour must be later than start hour!"); ;
21+
.Must((s, h) => h > s.SunlightStartHour).WithMessage("Sunlight end hour must be later than start hour!");
22+
23+
RuleFor(x => x.BatteryNominalVoltage)
24+
.GreaterThan(5)
25+
.WithMessage("Battery nominal voltage required!");
2226

2327
//todo: display validation errors on ui
2428
}

src/Server/Persistance/Database.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public void RestoreUserSettings()
8888
{
8989
_settings.PV_MaxCapacity = settings.PV_MaxCapacity;
9090
_settings.BatteryCapacity = settings.BatteryCapacity;
91+
_settings.BatteryNominalVoltage = settings.BatteryNominalVoltage;
9192
_settings.SunlightStartHour = settings.SunlightStartHour;
9293
_settings.SunlightEndHour = settings.SunlightEndHour;
9394
}

src/Server/Persistance/Settings/UserSettings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public class UserSettings
88
public int Id { get; set; } = 1;
99
public int PV_MaxCapacity { get; set; } = 1000;
1010
public int BatteryCapacity { get; set; } = 100;
11+
public float BatteryNominalVoltage { get; set; } = 25.6f;
1112
public int SunlightStartHour { get; set; } = 6;
1213
public int SunlightEndHour { get; set; } = 18;
1314
public int[] PVGraphRange => new[] { 0, (SunlightEndHour - SunlightStartHour) * 60 };
@@ -18,6 +19,7 @@ public SystemSpec ToSystemSpec()
1819
{
1920
PV_MaxCapacity = PV_MaxCapacity,
2021
BatteryCapacity = BatteryCapacity,
22+
BatteryNominalVoltage = BatteryNominalVoltage,
2123
SunlightStartHour = SunlightStartHour,
2224
SunlightEndHour = SunlightEndHour
2325
};
@@ -27,6 +29,7 @@ public void FromSystemSpec(SystemSpec spec)
2729
Id = 1;
2830
PV_MaxCapacity = spec.PV_MaxCapacity;
2931
BatteryCapacity = spec.BatteryCapacity;
32+
BatteryNominalVoltage = spec.BatteryNominalVoltage;
3033
SunlightStartHour = spec.SunlightStartHour;
3134
SunlightEndHour = spec.SunlightEndHour;
3235
}

src/Server/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
bld.Services
2020
.AddSingleton<UserSettings>()
2121
.AddSingleton<CommandQueue>()
22-
.AddSingleton<JkBms>()
23-
.AddSingleton<Database>();
22+
.AddSingleton<Database>()
23+
.AddSingleton<JkBms>();
2424

2525
if (!bld.Environment.IsDevelopment())
2626
{

src/Shared/Models/BMSStatus.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Text.Json.Serialization;
1+
using System.Globalization;
2+
using System.Text.Json.Serialization;
23

34
namespace InverterMon.Shared.Models;
45

@@ -63,4 +64,20 @@ public class BMSStatus
6364

6465
[JsonPropertyName("t")]
6566
public double AvgPowerWatts => Math.Round(AvgCurrentAmps * PackVoltage, 0, MidpointRounding.AwayFromZero);
67+
68+
[JsonPropertyName("u")]
69+
public float PackNominalVoltage { get; set; }
70+
71+
public string GetTimeString()
72+
{
73+
var currentTime = DateTime.UtcNow
74+
.AddHours(5).AddMinutes(30); //only supports IST time zone :-(
75+
76+
var futureTime = currentTime.AddHours(TimeHrs).AddMinutes(TimeMins);
77+
78+
if (futureTime.Date == currentTime.Date)
79+
return futureTime.ToString("h:mm tt");
80+
else
81+
return futureTime.ToString("dddd h:mm tt");
82+
}
6683
}

src/Shared/Models/SystemSpec.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ public class SystemSpec
44
{
55
public int PV_MaxCapacity { get; set; } = 1000;
66
public int BatteryCapacity { get; set; } = 100;
7+
public float BatteryNominalVoltage { get; set; } = 25.6f;
78
public int SunlightStartHour { get; set; } = 6;
89
public int SunlightEndHour { get; set; } = 18;
910
}

src/changelog.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
## changelog
22

3-
- show decimal point of jk bms temperature sensor values
4-
- show battery power in watts in jk bms section
5-
- improve bms cell voltage display
6-
- improve pv watts display
3+
- toggle for displaying bms battery capacities in kWh
4+
- toggle for displaying bms remaining time as date and time string

0 commit comments

Comments
 (0)