improve inverter status serialization
This commit is contained in:
parent
4dd5c7a870
commit
eb62dc454d
@ -45,7 +45,7 @@
|
|||||||
<div class="container text-center fw-bold p-0">
|
<div class="container text-center fw-bold p-0">
|
||||||
<div class="row bg-light rounded">
|
<div class="row bg-light rounded">
|
||||||
<div class="progress p-0" style="height:2px;">
|
<div class="progress p-0" style="height:2px;">
|
||||||
<span class="progress-bar" role="progressbar" style="width: @RoundToWholeNumber(status?.LoadPercentage)%" aria-valuenow="25"
|
<span class="progress-bar" role="progressbar" style="width: @status?.LoadPercentage%" aria-valuenow="25"
|
||||||
aria-valuemin="0" aria-valuemax="100"></span>
|
aria-valuemin="0" aria-valuemax="100"></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
@ -55,7 +55,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<div class="fs-5 text-muted">@RoundToWholeNumber(status?.OutputVoltage)</div>
|
<div class="fs-5 text-muted">@status?.OutputVoltage</div>
|
||||||
<span class="text-body">
|
<span class="text-body">
|
||||||
V
|
V
|
||||||
</span>
|
</span>
|
||||||
@ -68,7 +68,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<div class="fs-5 text-muted">@RoundToOneDecimal(status?.LoadCurrent)</div>
|
<div class="fs-5 text-muted">@status?.LoadCurrent</div>
|
||||||
A
|
A
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -97,13 +97,13 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<div class="fs-5 text-muted">@RoundToWholeNumber(status?.PVInputVoltage)</div>
|
<div class="fs-5 text-muted">@status?.PVInputVoltage</div>
|
||||||
<span class="text-body">
|
<span class="text-body">
|
||||||
V
|
V
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<div class="fs-5 text-muted">@RoundToOneDecimal(status?.PVInputCurrent)</div>
|
<div class="fs-5 text-muted">@status?.PVInputCurrent</div>
|
||||||
A
|
A
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -119,8 +119,9 @@
|
|||||||
<div class="col-sm-12">
|
<div class="col-sm-12">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h5 class="card-header align-self-center w-100">
|
<h5 class="card-header align-self-center w-100">
|
||||||
<span class="oi oi-battery-empty" aria-hidden="true"/>
|
<span class="oi oi-battery-empty" aria-hidden="true">
|
||||||
Battery
|
Battery
|
||||||
|
</span>
|
||||||
</h5>
|
</h5>
|
||||||
<div class="card-body p-0 m-0">
|
<div class="card-body p-0 m-0">
|
||||||
<div class="container text-center m-0 p-0">
|
<div class="container text-center m-0 p-0">
|
||||||
@ -137,7 +138,7 @@
|
|||||||
<div class="fs-1 text-danger">@status?.BatteryChargeWatts</div>
|
<div class="fs-1 text-danger">@status?.BatteryChargeWatts</div>
|
||||||
W
|
W
|
||||||
<div class="fw-bold">
|
<div class="fw-bold">
|
||||||
<div class="fs-5 text-muted">@RoundToOneDecimal(status?.BatteryChargeCurrent)</div>
|
<div class="fs-5 text-muted">@status?.BatteryChargeCurrent</div>
|
||||||
A
|
A
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -145,7 +146,7 @@
|
|||||||
<div class="col-4">
|
<div class="col-4">
|
||||||
<div class="container bg-light rounded-1 p-1 m-0 fw-bold text-muted fs-1">
|
<div class="container bg-light rounded-1 p-1 m-0 fw-bold text-muted fs-1">
|
||||||
<div class="fs-4 voltage">Voltage</div>
|
<div class="fs-4 voltage">Voltage</div>
|
||||||
<div class="text-black charge-discharge">@RoundToOneDecimal(status?.BatteryVoltage)</div>
|
<div class="text-black charge-discharge">@status?.BatteryVoltage</div>
|
||||||
<div class="fs-4 text-black-50">V</div>
|
<div class="fs-4 text-black-50">V</div>
|
||||||
<div class="fs-6 bg-white text-dark">@GetCRate() C</div>
|
<div class="fs-6 bg-white text-dark">@GetCRate() C</div>
|
||||||
</div>
|
</div>
|
||||||
@ -199,12 +200,6 @@
|
|||||||
onStatusRetrievalError -= NullifyStatus;
|
onStatusRetrievalError -= NullifyStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static double RoundToWholeNumber(double? val)
|
|
||||||
=> Math.Round(val ?? 0, 0);
|
|
||||||
|
|
||||||
private static double RoundToOneDecimal(double? val)
|
|
||||||
=> Math.Round(val ?? 0, 1);
|
|
||||||
|
|
||||||
public static async Task StartStatusStreaming(string basePath)
|
public static async Task StartStatusStreaming(string basePath)
|
||||||
{
|
{
|
||||||
//note: only reason we have a full-time stream download is because there's a bug in
|
//note: only reason we have a full-time stream download is because there's a bug in
|
||||||
@ -255,10 +250,10 @@
|
|||||||
private static double GetCRate()
|
private static double GetCRate()
|
||||||
{
|
{
|
||||||
if (status?.BatteryChargeCRate > 0)
|
if (status?.BatteryChargeCRate > 0)
|
||||||
return Math.Round(status.BatteryChargeCRate, 2);
|
return status.BatteryChargeCRate;
|
||||||
|
|
||||||
if (status?.BatteryDischargeCRate > 0)
|
if (status?.BatteryDischargeCRate > 0)
|
||||||
return Math.Round(status.BatteryDischargeCRate, 2);
|
return status.BatteryDischargeCRate;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
<NoWarn>CS8618;CA2016</NoWarn>
|
<NoWarn>CS8618;CA2016</NoWarn>
|
||||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||||
<NuGetAuditMode>direct</NuGetAuditMode>
|
<NuGetAuditMode>direct</NuGetAuditMode>
|
||||||
<LangVersion>13</LangVersion>
|
<LangVersion>latest</LangVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||||
|
|||||||
@ -65,8 +65,8 @@ public sealed class FelicitySolarInverter
|
|||||||
|
|
||||||
// BatteryChargingStage = regs[1], // 0x1102: Battery charging stage (offset 1)
|
// BatteryChargingStage = regs[1], // 0x1102: Battery charging stage (offset 1)
|
||||||
|
|
||||||
Status.WorkingMode = (WorkingMode)regs[0]; // 0x1101: Working mode (offset 0)
|
Status.WorkingMode = (WorkingMode)regs[0]; // 0x1101: Working mode (offset 0)
|
||||||
Status.BatteryVoltage = regs[7] / 100.0; // 0x1108: Battery voltage (offset 0x1108 - 0x1101 = 7)
|
Status.BatteryVoltage = Math.Round(regs[7] / 100.0, 1); // 0x1108: Battery voltage (offset 0x1108 - 0x1101 = 7)
|
||||||
|
|
||||||
var disCur = ChargeStatus(regs[8]); // 0x1109: Battery current (offset 8) -- signed value
|
var disCur = ChargeStatus(regs[8]); // 0x1109: Battery current (offset 8) -- signed value
|
||||||
Status.BatteryDischargeCurrent = disCur.IsDischarge ? disCur.PositiveValue : 0;
|
Status.BatteryDischargeCurrent = disCur.IsDischarge ? disCur.PositiveValue : 0;
|
||||||
@ -76,12 +76,12 @@ public sealed class FelicitySolarInverter
|
|||||||
Status.BatteryDischargeWatts = disPow.IsDischarge ? disPow.PositiveValue : 0;
|
Status.BatteryDischargeWatts = disPow.IsDischarge ? disPow.PositiveValue : 0;
|
||||||
Status.BatteryChargeWatts = disPow.IsDischarge is false ? disPow.PositiveValue : 0;
|
Status.BatteryChargeWatts = disPow.IsDischarge is false ? disPow.PositiveValue : 0;
|
||||||
|
|
||||||
Status.OutputVoltage = regs[16] / 10.0; // 0x1111: AC output voltage (offset 0x1111 - 0x1101 = 16)
|
Status.OutputVoltage = Math.Round(regs[16] / 10.0, 0); // 0x1111: AC output voltage (offset 0x1111 - 0x1101 = 16)
|
||||||
Status.GridVoltage = regs[22] / 10.0; // 0x1111: AC output voltage (offset 0x1117 - 0x1101 = 22)
|
Status.GridVoltage = Convert.ToInt16(regs[22] / 10.0); // 0x1111: AC output voltage (offset 0x1117 - 0x1101 = 22)
|
||||||
Status.LoadWatts = regs[29]; // 0x111E: AC output active power (offset 0x111E - 0x1101 = 29)
|
Status.LoadWatts = regs[29]; // 0x111E: AC output active power (offset 0x111E - 0x1101 = 29)
|
||||||
Status.LoadPercentage = regs[31]; // 0x1120: Load percentage (offset 0x1120 - 0x1101 = 31)
|
Status.LoadPercentage = regs[31]; // 0x1120: Load percentage (offset 0x1120 - 0x1101 = 31)
|
||||||
Status.PVInputVoltage = regs[37] / 10.0; // 0x1126: PV input voltage (offset 0x1126 - 0x1101 = 37)
|
Status.PVInputVoltage = Math.Round(regs[37] / 10.0, 0); // 0x1126: PV input voltage (offset 0x1126 - 0x1101 = 37)
|
||||||
Status.PVInputWatt = regs[41]; // 0x112A: PV input power (offset 0x112A - 0x1101 = 41) -- signed value
|
Status.PVInputWatt = regs[41]; // 0x112A: PV input power (offset 0x112A - 0x1101 = 41) -- signed value
|
||||||
|
|
||||||
static (bool IsDischarge, short PositiveValue) ChargeStatus(short value)
|
static (bool IsDischarge, short PositiveValue) ChargeStatus(short value)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -8,7 +8,7 @@ public class InverterStatus
|
|||||||
public int BatteryCapacity { get; set; } = 100;
|
public int BatteryCapacity { get; set; } = 100;
|
||||||
|
|
||||||
[JsonPropertyName("b")]
|
[JsonPropertyName("b")]
|
||||||
public double BatteryChargeCRate => BatteryChargeCurrent == 0 ? 0 : Convert.ToDouble(BatteryChargeCurrent) / BatteryCapacity;
|
public double BatteryChargeCRate => BatteryChargeCurrent == 0 ? 0 : Math.Round(Convert.ToDouble(BatteryChargeCurrent) / BatteryCapacity, 2);
|
||||||
|
|
||||||
[JsonPropertyName("c")]
|
[JsonPropertyName("c")]
|
||||||
public int BatteryChargeCurrent { get; set; }
|
public int BatteryChargeCurrent { get; set; }
|
||||||
@ -17,7 +17,7 @@ public class InverterStatus
|
|||||||
public int BatteryChargeWatts { get; set; }
|
public int BatteryChargeWatts { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("e")]
|
[JsonPropertyName("e")]
|
||||||
public double BatteryDischargeCRate => BatteryDischargeCurrent == 0 ? 0 : Convert.ToDouble(BatteryDischargeCurrent) / BatteryCapacity;
|
public double BatteryDischargeCRate => BatteryDischargeCurrent == 0 ? 0 : Math.Round(Convert.ToDouble(BatteryDischargeCurrent) / BatteryCapacity, 2);
|
||||||
|
|
||||||
[JsonPropertyName("f")]
|
[JsonPropertyName("f")]
|
||||||
public int BatteryDischargeCurrent { get; set; }
|
public int BatteryDischargeCurrent { get; set; }
|
||||||
@ -35,13 +35,13 @@ public class InverterStatus
|
|||||||
public int GridUsageWatts => GridVoltage < 10 ? 0 : LoadWatts + BatteryChargeWatts - (PVInputWatt + BatteryDischargeWatts);
|
public int GridUsageWatts => GridVoltage < 10 ? 0 : LoadWatts + BatteryChargeWatts - (PVInputWatt + BatteryDischargeWatts);
|
||||||
|
|
||||||
[JsonPropertyName("k")]
|
[JsonPropertyName("k")]
|
||||||
public double GridVoltage { get; set; }
|
public int GridVoltage { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("l")]
|
[JsonPropertyName("l")]
|
||||||
public WorkingMode WorkingMode { get; set; }
|
public WorkingMode WorkingMode { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("m")]
|
[JsonPropertyName("m")]
|
||||||
public double LoadCurrent => LoadWatts == 0 ? 0 : LoadWatts / OutputVoltage;
|
public double LoadCurrent => LoadWatts == 0 ? 0 : Math.Round(LoadWatts / OutputVoltage, 1);
|
||||||
|
|
||||||
[JsonPropertyName("n")]
|
[JsonPropertyName("n")]
|
||||||
public int LoadPercentage { get; set; }
|
public int LoadPercentage { get; set; }
|
||||||
@ -53,7 +53,7 @@ public class InverterStatus
|
|||||||
public double OutputVoltage { get; set; }
|
public double OutputVoltage { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("q")]
|
[JsonPropertyName("q")]
|
||||||
public double PVInputCurrent => PVInputWatt == 0 ? 0 : PVInputWatt / PVInputVoltage;
|
public double PVInputCurrent => PVInputWatt == 0 ? 0 : Math.Round(PVInputWatt / PVInputVoltage, 1);
|
||||||
|
|
||||||
[JsonPropertyName("r")]
|
[JsonPropertyName("r")]
|
||||||
public double PVInputVoltage { get; set; }
|
public double PVInputVoltage { get; set; }
|
||||||
@ -69,7 +69,7 @@ public class InverterStatus
|
|||||||
|
|
||||||
pvInputWatt = value;
|
pvInputWatt = value;
|
||||||
var interval = (DateTime.Now - pvInputWattHourLastComputed).TotalSeconds;
|
var interval = (DateTime.Now - pvInputWattHourLastComputed).TotalSeconds;
|
||||||
PVInputWattHour += value / (3600 / interval);
|
PVInputWattHour += Math.Round(value / (3600 / interval), 2);
|
||||||
pvInputWattHourLastComputed = DateTime.Now;
|
pvInputWattHourLastComputed = DateTime.Now;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
## changelog
|
## changelog
|
||||||
|
|
||||||
- fix pv potential progress bar not showing
|
- prevent serialization errors for inverter status
|
||||||
|
- round floating point numbers on serverside before sending data to client
|
||||||
5
src/global.json
Normal file
5
src/global.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"sdk": {
|
||||||
|
"version": "9.0.200"
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user