Added updating battery firmware
This commit is contained in:
parent
ec4d76f8fd
commit
92721376a6
|
@ -19,7 +19,9 @@ public record InstallationToHtmlInterface(
|
||||||
String Online,
|
String Online,
|
||||||
String LastSeen,
|
String LastSeen,
|
||||||
Int64 NumBatteries,
|
Int64 NumBatteries,
|
||||||
String BatteryVersion
|
String BatteryVersion,
|
||||||
|
String ServerIp = "10.2.0.1", //TODO MAKE ME DYNAMIC
|
||||||
|
String FirmwareVersion = "AF09" //Todo automatically grab newest version?
|
||||||
);
|
);
|
||||||
|
|
||||||
[Controller]
|
[Controller]
|
||||||
|
@ -27,7 +29,7 @@ public class Controller : ControllerBase
|
||||||
{
|
{
|
||||||
|
|
||||||
//Todo automatically grab newest version?
|
//Todo automatically grab newest version?
|
||||||
private const String FirmwareVersion = "VERSION";
|
private const String FirmwareVersion = "AF09";
|
||||||
|
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
|
@ -99,7 +101,7 @@ public class Controller : ControllerBase
|
||||||
<td>{{Serial}}</td>
|
<td>{{Serial}}</td>
|
||||||
<td>{{NumBatteries}}</td>
|
<td>{{NumBatteries}}</td>
|
||||||
<td>{{BatteryVersion}}</td>
|
<td>{{BatteryVersion}}</td>
|
||||||
<td><a target='_blank' href=http://{{serverIp}}/UpdateBatteryFirmware/{{Ip}}>⬆️{{firmwareVersion}}</a></td>
|
<td><a target='_blank' href=http://{{ServerIp}}/UpdateBatteryFirmware/{{Ip}}/{{NumBatteries}}>⬆️{{FirmwareVersion}}</a></td>
|
||||||
</tr>";
|
</tr>";
|
||||||
|
|
||||||
var installationsInDb = Db.Installations.ToList();
|
var installationsInDb = Db.Installations.ToList();
|
||||||
|
@ -126,8 +128,6 @@ public class Controller : ControllerBase
|
||||||
var data = new
|
var data = new
|
||||||
{
|
{
|
||||||
inst = installsForHtml,
|
inst = installsForHtml,
|
||||||
serverIp = "10.2.0.1", //TODO MAKE ME DYNAMIC
|
|
||||||
firmwareVersion = FirmwareVersion
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var result = template(data);
|
var result = template(data);
|
||||||
|
@ -140,22 +140,25 @@ public class Controller : ControllerBase
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[HttpGet(nameof(UpdateBatteryFirmware))]
|
[HttpGet("updatebatteryfirmware/{installationIp}/{numberOfBatteries}")]
|
||||||
public async Task<ActionResult> UpdateBatteryFirmware(String installationIp, Int64 numOfBatteries)
|
public async Task<String> UpdateBatteryFirmware(String installationIp, String numberOfBatteries)
|
||||||
{
|
{
|
||||||
//We need the DeviceName of the battery (ttyUSB?)
|
//We need the DeviceName of the battery (ttyUSB?)
|
||||||
var pathToBattery = await Db.ExecuteBufferedAsyncCommandOnIp(installationIp, "dbus-send --system --dest=com.victronenergy.system --type=method_call --print-reply /ServiceMapping/com_victronenergy_battery_1 com.victronenergy.BusItem.GetText");
|
var pathToBattery = await Db.ExecuteBufferedAsyncCommandOnIp(installationIp, "dbus-send --system --dest=com.victronenergy.system --type=method_call --print-reply /ServiceMapping/com_victronenergy_battery_1 com.victronenergy.BusItem.GetText");
|
||||||
|
|
||||||
if (pathToBattery == "Failed") return new BadRequestResult();
|
if (pathToBattery.Split('"')[1] == "Failed") return "Update failed";
|
||||||
|
|
||||||
SendNewBatteryFirmware(installationIp);
|
SendNewBatteryFirmware(installationIp);
|
||||||
|
|
||||||
for (var batteryId = 0; batteryId < numOfBatteries; batteryId++)
|
for (var batteryId = 2; batteryId <= Int64.Parse(numberOfBatteries) + 1; batteryId++)
|
||||||
{
|
{
|
||||||
var updateCommand = await Db.ExecuteBufferedAsyncCommandOnIp(installationIp, $"/opt/innovenergy/scripts/upload-bms-firmware {pathToBattery} {batteryId} /opt/innovenergy/bms-firmware/{FirmwareVersion}.bin");
|
var batteryTtyName = pathToBattery.Split('"')[1].Split(".").Last();
|
||||||
if (updateCommand == "Failed") return new BadRequestResult();
|
var localCommand = $"/opt/innovenergy/scripts/upload-bms-firmware {batteryTtyName} {batteryId} /opt/innovenergy/bms-firmware/{FirmwareVersion}.bin";
|
||||||
|
|
||||||
|
var remoteUpdateCommandResult = Db.ExecuteBufferedAsyncCommandOnIp(installationIp, localCommand);
|
||||||
|
// Console.WriteLine(remoteUpdateCommandResult); //Todo replace me with checking if it worked...
|
||||||
}
|
}
|
||||||
return new AcceptedResult();
|
return "Battery update is successfully initiated! You can close this page now.";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SendNewBatteryFirmware(String installationIp)
|
private static void SendNewBatteryFirmware(String installationIp)
|
||||||
|
|
|
@ -8,6 +8,7 @@ using CliWrap.Buffered;
|
||||||
using InnovEnergy.App.RemoteSupportConsole;
|
using InnovEnergy.App.RemoteSupportConsole;
|
||||||
using InnovEnergy.Lib.Utils;
|
using InnovEnergy.Lib.Utils;
|
||||||
using InnovEnergy.Lib.Victron.VictronVRM;
|
using InnovEnergy.Lib.Victron.VictronVRM;
|
||||||
|
using Microsoft.AspNetCore.Mvc.TagHelpers.Cache;
|
||||||
using SQLite;
|
using SQLite;
|
||||||
using static System.Text.Json.JsonSerializer;
|
using static System.Text.Json.JsonSerializer;
|
||||||
using Installation = InnovEnergy.App.VrmGrabber.DataTypes.Installation;
|
using Installation = InnovEnergy.App.VrmGrabber.DataTypes.Installation;
|
||||||
|
@ -59,7 +60,7 @@ public static partial class Db
|
||||||
do {
|
do {
|
||||||
await UpdateInstallationsAndDetailsFromVrm(0);
|
await UpdateInstallationsAndDetailsFromVrm(0);
|
||||||
}
|
}
|
||||||
while (true) ;
|
while (false) ; //Todo change to true before
|
||||||
}
|
}
|
||||||
|
|
||||||
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "<Pending>")]
|
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "<Pending>")]
|
||||||
|
@ -72,7 +73,7 @@ public static partial class Db
|
||||||
var installations = await user.GetInstallations();
|
var installations = await user.GetInstallations();
|
||||||
|
|
||||||
// var returnDictionary = new Dictionary<VrmInstallation, InstallationDetails>();
|
// var returnDictionary = new Dictionary<VrmInstallation, InstallationDetails>();
|
||||||
foreach (var installation in installations) //TODO REMOVE TAKE
|
foreach (var installation in installations.Skip(404).Take(3)) //TODO REMOVE TAKE
|
||||||
{
|
{
|
||||||
Console.WriteLine(installation.Name);
|
Console.WriteLine(installation.Name);
|
||||||
var details = await GetInstallationDetails(installation);
|
var details = await GetInstallationDetails(installation);
|
||||||
|
@ -109,11 +110,12 @@ public static partial class Db
|
||||||
if (ip is null or "Unknown" || online == "❌") return "Unknown";
|
if (ip is null or "Unknown" || online == "❌") return "Unknown";
|
||||||
var pathToBattery = await ExecuteBufferedAsyncCommandOnIp(ip, "dbus-send --system --dest=com.victronenergy.system --type=method_call --print-reply /ServiceMapping/com_victronenergy_battery_1 com.victronenergy.BusItem.GetText");
|
var pathToBattery = await ExecuteBufferedAsyncCommandOnIp(ip, "dbus-send --system --dest=com.victronenergy.system --type=method_call --print-reply /ServiceMapping/com_victronenergy_battery_1 com.victronenergy.BusItem.GetText");
|
||||||
|
|
||||||
if (pathToBattery.StartsWith("Error")) return "Unknown";
|
if (pathToBattery.Split('"')[1].StartsWith("Error")) return "Unknown";
|
||||||
|
|
||||||
|
|
||||||
var command = $"dbus-send --system --dest={pathToBattery} --type=method_call --print-reply /FirmwareVersion com.victronenergy.BusItem.GetText";
|
var command = $"dbus-send --system --dest={pathToBattery.Split('"')[1]} --type=method_call --print-reply /FirmwareVersion com.victronenergy.BusItem.GetText";
|
||||||
return await ExecuteBufferedAsyncCommandOnIp(ip, command);
|
var returnString = await ExecuteBufferedAsyncCommandOnIp(ip, command);
|
||||||
|
return returnString.Split('"')[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task<Int64> NumberOfBatteries(String? ip, String? online)
|
private static async Task<Int64> NumberOfBatteries(String? ip, String? online)
|
||||||
|
@ -121,11 +123,11 @@ public static partial class Db
|
||||||
if (ip is null or "Unknown" || online == "❌") return 0;
|
if (ip is null or "Unknown" || online == "❌") return 0;
|
||||||
var pathToBattery = await ExecuteBufferedAsyncCommandOnIp(ip, "dbus-send --system --dest=com.victronenergy.system --type=method_call --print-reply /ServiceMapping/com_victronenergy_battery_1 com.victronenergy.BusItem.GetText");
|
var pathToBattery = await ExecuteBufferedAsyncCommandOnIp(ip, "dbus-send --system --dest=com.victronenergy.system --type=method_call --print-reply /ServiceMapping/com_victronenergy_battery_1 com.victronenergy.BusItem.GetText");
|
||||||
|
|
||||||
if (pathToBattery.StartsWith("Error")) return 0;
|
if (pathToBattery.Split('"')[1].StartsWith("Error")) return 0;
|
||||||
|
|
||||||
var cmd = await ExecuteBufferedAsyncCommandOnIp(ip,$"dbus-send --system --dest={pathToBattery} --type=method_call --print-reply /NbOfBatteries com.victronenergy.BusItem.GetText" );
|
var cmd = await ExecuteBufferedAsyncCommandOnIp(ip,$"dbus-send --system --dest={pathToBattery.Split('"')[1]} --type=method_call --print-reply /NbOfBatteries com.victronenergy.BusItem.GetText" );
|
||||||
|
|
||||||
return cmd == "Failed" ? 0 : Int64.Parse(cmd); //No Batteries can be found
|
return cmd.Split('"')[1] == "Failed" ? 0 : Int64.Parse(cmd.Split('"')[1]); //No Batteries can be found
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -138,7 +140,7 @@ public static partial class Db
|
||||||
.AppendArgument("-o StrictHostKeyChecking=accept-new")
|
.AppendArgument("-o StrictHostKeyChecking=accept-new")
|
||||||
.AppendArgument(command)
|
.AppendArgument(command)
|
||||||
.WithValidation(CommandResultValidation.None).ExecuteBufferedAsync();
|
.WithValidation(CommandResultValidation.None).ExecuteBufferedAsync();
|
||||||
return cmd.ExitCode == 0 ? cmd.StandardOutput.Split('"')[1] : cmd.StandardError;
|
return cmd.ExitCode == 0 ? cmd.StandardOutput : cmd.StandardError;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String?[] Ip(InstallationDetails details)
|
private static String?[] Ip(InstallationDetails details)
|
||||||
|
|
|
@ -13,7 +13,6 @@ public static class Program
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
builder.Services.AddSwaggerGen(c =>
|
builder.Services.AddSwaggerGen(c =>
|
||||||
{
|
{
|
||||||
c.SwaggerDoc("v1", OpenApiInfo);
|
|
||||||
c.UseAllOfToExtendReferenceSchemas();
|
c.UseAllOfToExtendReferenceSchemas();
|
||||||
c.SupportNonNullableReferenceTypes();
|
c.SupportNonNullableReferenceTypes();
|
||||||
});
|
});
|
||||||
|
|
Binary file not shown.
|
@ -84,6 +84,7 @@ def init_modbus(tty):
|
||||||
def failed(response):
|
def failed(response):
|
||||||
# type: (ModbusResponse) -> bool
|
# type: (ModbusResponse) -> bool
|
||||||
|
|
||||||
|
# Todo 'ModbusIOException' object has no attribute 'function_code'
|
||||||
return response.function_code > 0x80
|
return response.function_code > 0x80
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue