Added alarm changing

This commit is contained in:
Kim 2023-09-08 11:56:49 +02:00
parent 47c8d438d1
commit eb54250031
3 changed files with 27 additions and 3 deletions

View File

@ -4,6 +4,7 @@ using HandlebarsDotNet;
using InnovEnergy.App.VrmGrabber.Database; using InnovEnergy.App.VrmGrabber.Database;
using InnovEnergy.App.VrmGrabber.DataTypes; using InnovEnergy.App.VrmGrabber.DataTypes;
using InnovEnergy.Lib.Utils; using InnovEnergy.Lib.Utils;
using InnovEnergy.Lib.Victron.VictronVRM;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using FILE=System.IO.File; using FILE=System.IO.File;
using VrmInstallation = InnovEnergy.Lib.Victron.VictronVRM.Installation; using VrmInstallation = InnovEnergy.Lib.Victron.VictronVRM.Installation;
@ -238,9 +239,9 @@ th { /* header cell */
private static async Task SendNewBatteryFirmware(String installationIp) private static async Task SendNewBatteryFirmware(String installationIp)
{ {
await Cli.Wrap("scp") await Cli.Wrap("rsync")
.WithArguments($@"{FirmwareVersion}.bin") .WithArguments($@"-r {FirmwareVersion}.bin")
.AppendArgument($@"root@{installationIp}:/opt/innovenergy/{FirmwareVersion}.bin") .AppendArgument($@"root@{installationIp}:/opt/innovenergy/bms-firmware/{FirmwareVersion}.bin")
.ExecuteAsync(); .ExecuteAsync();
} }
// [HttpGet(nameof(GetInstallation))] // [HttpGet(nameof(GetInstallation))]

View File

@ -1,11 +1,13 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text.Json.Nodes;
using System.Web; using System.Web;
using CliWrap; using CliWrap;
using CliWrap.Buffered; 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 Newtonsoft.Json;
using SQLite; using SQLite;
using static System.Text.Json.JsonSerializer; using static System.Text.Json.JsonSerializer;
using static InnovEnergy.App.VrmGrabber.Database.Systemd; using static InnovEnergy.App.VrmGrabber.Database.Systemd;
@ -81,6 +83,7 @@ public static partial class Db
Console.WriteLine(installation.Name); Console.WriteLine(installation.Name);
sd_notify(0, "WATCHDOG=1"); sd_notify(0, "WATCHDOG=1");
var details = await GetInstallationDetails(installation); var details = await GetInstallationDetails(installation);
await updateAlarms(installation);
var ip = Ip(details); var ip = Ip(details);
var updatedInstallation = new Installation( var updatedInstallation = new Installation(
installation.Name, installation.Name,
@ -111,6 +114,26 @@ public static partial class Db
} }
} }
[RequiresUnreferencedCode("Calls System.Text.Json.JsonSerializer.SerializeToElement<TValue>(TValue, JsonSerializerOptions)")]
private static async Task<Boolean> updateAlarms(VrmInstallation installation)
{
// installation.GetDevices().batteryMonitor.setTemperatureAlarms(245,250,315,313);
var alarmJson = Deserialize<JsonObject>("""
{
"AlarmEnabled": 1,
"NotifyAfterSeconds": 60,
"highAlarm": 315,
"highAlarmHysteresis": 313,
"lowAlarm": 245,
"lowAlarmHysteresis": 250
}
""")!;
var tags = await installation.GetTags();
if (tags.Contains("FM-AF09"))
return await installation.SetAlarms(alarmJson);
return true;
}
public static async Task<VrmAccount> GetVrmAccount() public static async Task<VrmAccount> GetVrmAccount()
{ {
var fileContent = await File.ReadAllTextAsync("./token.json"); var fileContent = await File.ReadAllTextAsync("./token.json");

Binary file not shown.