updated VrmGrabber to automatically grab battery ids

This commit is contained in:
Kim 2023-10-02 15:40:03 +02:00
parent d04b431c9f
commit 5146491dcd
2 changed files with 13 additions and 15 deletions

View File

@ -127,7 +127,7 @@ th { /* header cell */
<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}}/{{NumBatteries}}>⬆️{{FirmwareVersion}}</a></td> <td><a target='_blank' href=http://{{ServerIp}}/UpdateBatteryFirmware/{{Ip}}>⬆️{{FirmwareVersion}}</a></td>
<td>{{BatteryUpdateStatus}}</td> <td>{{BatteryUpdateStatus}}</td>
</tr>"; </tr>";
@ -168,8 +168,8 @@ th { /* header cell */
} }
[HttpGet("UpdateBatteryFirmware/{installationIp}/{numberOfBatteries}")] [HttpGet("UpdateBatteryFirmware/{installationIp}")]
public async Task<String> UpdateBatteryFirmware(String installationIp, String numberOfBatteries) public async Task<String> UpdateBatteryFirmware(String installationIp)
{ {
//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");
@ -188,30 +188,28 @@ th { /* header cell */
await SendNewBatteryFirmware(installationIp); await SendNewBatteryFirmware(installationIp);
var batteryTtyName = split[1].Split(".").Last(); var batteryTtyName = split[1].Split(".").Last();
var localCommand = $"/opt/innovenergy/scripts/upload-bms-firmware {batteryTtyName} 2 /opt/innovenergy/bms-firmware/{FirmwareVersion}.bin"; var localCommand = "echo start";
var installation = Db.Installations.First(installation => installation.Ip == installationIp); var installation = Db.Installations.First(installation => installation.Ip == installationIp);
installation.BatteryUpdateStatus = "Running"; installation.BatteryUpdateStatus = "Running";
Db.Update(installation: installation); Db.Update(installation: installation);
for (var batteryId = 3; batteryId < Int64.Parse(numberOfBatteries) + 2; batteryId++) var batteryIdsResult = await Db.ExecuteBufferedAsyncCommandOnIp(installationIp, $"dbus-send --system --dest=com.victronenergy.battery.{batteryTtyName} --type=method_call --print-reply / com.victronenergy.BusItem.GetText | grep -E -o '_Battery/[0-9]+/' | grep -E -o '[0-9]+'| sort -u");
var batteryIds = batteryIdsResult.Split("\n").ToList();
batteryIds.Pop();
foreach (var batteryId in batteryIds)
{ {
localCommand = localCommand.Append( localCommand = localCommand.Append(
$" && sleep 3m && /opt/innovenergy/scripts/upload-bms-firmware {batteryTtyName} {batteryId} /opt/innovenergy/{FirmwareVersion}.bin"); $" && /opt/innovenergy/scripts/upload-bms-firmware {batteryTtyName} {batteryId} /opt/innovenergy/bms-firmware/{FirmwareVersion}.bin");
} }
#pragma warning disable CS4014 #pragma warning disable CS4014
Console.WriteLine(localCommand);
Db.ExecuteBufferedAsyncCommandOnIp(installationIp, localCommand) Db.ExecuteBufferedAsyncCommandOnIp(installationIp, localCommand)
.ContinueWith(t => .ContinueWith(t =>
{ {
if (t.Status == TaskStatus.RanToCompletion) Console.WriteLine(t.Result);
{
installation.BatteryUpdateStatus = "Complete"; installation.BatteryUpdateStatus = "Complete";
Db.Update(installation: installation); Db.Update(installation: installation);
UpdateVrmTagsToNewFirmware(installationIp); UpdateVrmTagsToNewFirmware(installationIp);
}
else
{
installation.BatteryUpdateStatus = "Failed";
Db.Update(installation: installation);
}
}); });
#pragma warning restore CS4014 #pragma warning restore CS4014
return "Battery update is successfully initiated, it will take around 15 minutes to complete! You can close this page now."; return "Battery update is successfully initiated, it will take around 15 minutes to complete! You can close this page now.";

View File

@ -1,4 +1,4 @@
#!/usr/bin/python -u #!/usr/bin/python3 -u
# coding=utf-8 # coding=utf-8
from argparse import ArgumentParser from argparse import ArgumentParser
from time import sleep from time import sleep