Update backend to receive calls for updating the firmware of a battery
This commit is contained in:
parent
a4e3683082
commit
3a3f2fe1b8
|
@ -1,7 +1,4 @@
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.WebSockets;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.Json;
|
|
||||||
using InnovEnergy.App.Backend.Database;
|
using InnovEnergy.App.Backend.Database;
|
||||||
using InnovEnergy.App.Backend.DataTypes;
|
using InnovEnergy.App.Backend.DataTypes;
|
||||||
using InnovEnergy.App.Backend.DataTypes.Methods;
|
using InnovEnergy.App.Backend.DataTypes.Methods;
|
||||||
|
@ -516,6 +513,23 @@ public class Controller : ControllerBase
|
||||||
: Unauthorized();
|
: Unauthorized();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost(nameof(UpdateFirmware))]
|
||||||
|
public ActionResult UpdateFirmware(Int64 batteryNode, Int64 installationId,Token authToken)
|
||||||
|
{
|
||||||
|
var session = Db.GetSession(authToken);
|
||||||
|
var installationToUpdate = Db.GetInstallationById(installationId);
|
||||||
|
Console.WriteLine("Inside firmware function controller,batteryNode="+batteryNode+ "and installation is "+installationId);
|
||||||
|
|
||||||
|
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
||||||
|
if (installationToUpdate != null)
|
||||||
|
{
|
||||||
|
session.RunScriptInBackground(installationToUpdate.VpnIp, batteryNode);
|
||||||
|
}
|
||||||
|
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
||||||
|
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
[HttpPost(nameof(EditInstallationConfig))]
|
[HttpPost(nameof(EditInstallationConfig))]
|
||||||
public async Task<ActionResult<IEnumerable<Object>>> EditInstallationConfig([FromBody] Configuration config, Int64 installationId, Token authToken)
|
public async Task<ActionResult<IEnumerable<Object>>> EditInstallationConfig([FromBody] Configuration config, Int64 installationId, Token authToken)
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System.Diagnostics;
|
||||||
using InnovEnergy.App.Backend.Database;
|
using InnovEnergy.App.Backend.Database;
|
||||||
using InnovEnergy.App.Backend.Relations;
|
using InnovEnergy.App.Backend.Relations;
|
||||||
using InnovEnergy.Lib.Utils;
|
using InnovEnergy.Lib.Utils;
|
||||||
|
@ -65,6 +66,27 @@ public static class SessionMethods
|
||||||
.Do(() => installation.ParentId = parentId)
|
.Do(() => installation.ParentId = parentId)
|
||||||
.Apply(Db.Update);
|
.Apply(Db.Update);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async Task<Boolean> RunScriptInBackground(this Session? session, String vpnIp, Int64 batteryNode)
|
||||||
|
{
|
||||||
|
string scriptPath = "/home/ubuntu/backend/uploadBatteryFw/update_firmware.sh";
|
||||||
|
|
||||||
|
await Task.Run(() =>
|
||||||
|
{
|
||||||
|
Process process = new Process();
|
||||||
|
process.StartInfo.FileName = "/bin/bash";
|
||||||
|
process.StartInfo.Arguments = $"{scriptPath} {vpnIp} {batteryNode}"; // Pass batteryNode as argument to the script
|
||||||
|
process.StartInfo.UseShellExecute = false;
|
||||||
|
process.StartInfo.RedirectStandardOutput = true;
|
||||||
|
|
||||||
|
process.Start();
|
||||||
|
process.WaitForExit(); // This can be removed if you don't need to wait for the process to finish
|
||||||
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static async Task<Boolean> SendInstallationConfig(this Session? session, Int64 installationId, Configuration configuration)
|
public static async Task<Boolean> SendInstallationConfig(this Session? session, Int64 installationId, Configuration configuration)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue