From a5c6d7ecb284355a6115a0a7442aadae28773af8 Mon Sep 17 00:00:00 2001 From: atef Date: Tue, 26 Nov 2024 11:20:34 +0100 Subject: [PATCH] Update Emu meter driver for Victron --- csharp/App/EmuMeterDriver/Config.cs | 10 ++-- csharp/App/EmuMeterDriver/EmuMeterDriver.cs | 2 +- csharp/App/EmuMeterDriver/Signal.cs | 4 +- csharp/App/EmuMeterDriver/deploy.sh | 61 +++++++++++++++++++++ 4 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 csharp/App/EmuMeterDriver/deploy.sh diff --git a/csharp/App/EmuMeterDriver/Config.cs b/csharp/App/EmuMeterDriver/Config.cs index 0b5182735..c78c9490d 100644 --- a/csharp/App/EmuMeterDriver/Config.cs +++ b/csharp/App/EmuMeterDriver/Config.cs @@ -28,12 +28,12 @@ public static class Config new(s => s.Ac.L1.Voltage, "/Ac/L1/Voltage", "0.0 A"), new(s => s.Ac.L2.Voltage, "/Ac/L2/Voltage", "0.0 A"), new(s => s.Ac.L3.Voltage, "/Ac/L3/Voltage", "0.0 A"), - new(s => (s.Ac.L1.Voltage + s.Ac.L2.Voltage + s.Ac.L3.Voltage) / 3.0m, "/Ac/Voltage", "0.0 A"), + new(s => (s.Ac.L1.Voltage + s.Ac.L2.Voltage + s.Ac.L3.Voltage) / 3, "/Ac/Voltage", "0.0 A"), - new(s => s.Ac.L1.ActivePower, "/Ac/L1/Power", "0 W"), - new(s => s.Ac.L2.ActivePower, "/Ac/L2/Power", "0 W"), - new(s => s.Ac.L3.ActivePower, "/Ac/L3/Power", "0 W"), - new(s => s.Ac.ActivePower, "/Ac/Power", "0 W"), + new(s => s.Ac.L1.Power.Active, "/Ac/L1/Power", "0 W"), + new(s => s.Ac.L2.Power.Active, "/Ac/L2/Power", "0 W"), + new(s => s.Ac.L3.Power.Active, "/Ac/L3/Power", "0 W"), + new(s => s.Ac.Power.Active, "/Ac/Power", "0 W"), // new(s => s.EnergyImportL123, "Ac/Energy/Forward", "0.00 kWh"), // new(s => s.EnergyExportL123, "Ac/Energy/Reverse", "0.00 kWh"), diff --git a/csharp/App/EmuMeterDriver/EmuMeterDriver.cs b/csharp/App/EmuMeterDriver/EmuMeterDriver.cs index 9c57f2c7a..0aa36aa30 100644 --- a/csharp/App/EmuMeterDriver/EmuMeterDriver.cs +++ b/csharp/App/EmuMeterDriver/EmuMeterDriver.cs @@ -25,7 +25,7 @@ public static class EmuMeterDriver var meterStatus = Observable .Interval(Config.UpdatePeriod) - .Select(_ => emuMeter.ReadStatus()) + .Select(_ => emuMeter.Read()) .Publish(); var poller = meterStatus.Connect(); diff --git a/csharp/App/EmuMeterDriver/Signal.cs b/csharp/App/EmuMeterDriver/Signal.cs index d291d174c..7d22b547b 100644 --- a/csharp/App/EmuMeterDriver/Signal.cs +++ b/csharp/App/EmuMeterDriver/Signal.cs @@ -6,9 +6,9 @@ namespace InnovEnergy.App.EmuMeterDriver; // TODO: Does not compile -public record Signal(Func Source, ObjectPath Path, String Format = "") +public record Signal(Func Source, ObjectPath Path, String Format = "") { - public VeProperty ToVeProperty(EmuMeterStatus status) + public VeProperty ToVeProperty(EmuMeterRegisters status) { var value = Source(status); return new VeProperty(Path, value, String.Format($"{{0:{Format}}}", value)); diff --git a/csharp/App/EmuMeterDriver/deploy.sh b/csharp/App/EmuMeterDriver/deploy.sh new file mode 100644 index 000000000..eacfec15f --- /dev/null +++ b/csharp/App/EmuMeterDriver/deploy.sh @@ -0,0 +1,61 @@ +#!/bin/bash + + +csproj="SchneiderMeterDriver.csproj" +exe="SchneiderMeterDriver" +remote="10.2.4.114" +platform="linux-arm" +netVersion="net6.0" +config="Release" +host="root@$remote" +dir="/opt/innovenergy/$exe" +log_dir="/var/log/SchneiderMeterDriver" + +set -e + +# Publish the project locally +dotnet publish "$csproj" -c $config -r $platform -p:SuppressTrimmAnalysisWarnings=true -p:PublishSingleFile=true -p:PublishTrimmed=true -p:DebugType=None -p:DebugSymbols=false --self-contained true + +# Sync the published files to the remote server +rsync -av "bin/$config/$netVersion/$platform/publish/" "$host:$dir" + +# Execute commands on the remote server +ssh "$host" << 'EOF' +set -e + +# Remount the root filesystem with read and write permissions +mount -o remount,rw / + +# Create service and log directories +mkdir -p /opt/innovenergy/SchneiderMeterDriver/service +mkdir -p /opt/innovenergy/SchneiderMeterDriver/service/log +mkdir -p /var/log/SchneiderMeterDriver + +# Create the service run script +cat << 'EOL' > /opt/innovenergy/SchneiderMeterDriver/service/run +#!/bin/sh +exec 2>&1 +exec softlimit -d 200000000 -s 2000000 -a 200000000 /opt/innovenergy/SchneiderMeterDriver/SchniederDriver +EOL +chmod +x /opt/innovenergy/SchneiderMeterDriver/service/run + +# Create the log run script +cat << 'EOL' > /opt/innovenergy/SchneiderMeterDriver/service/log/run +#!/bin/sh +exec 2>&1 +exec multilog t s25000 n4 /var/log/SchneiderMeterDriver +EOL +chmod +x /opt/innovenergy/SchneiderMeterDriver/service/log/run + +# Create the symbolic link for the service +ln -sf /opt/innovenergy/SchneiderMeterDriver/service /service/SchneiderMeterDriver + +# Wait a bit for the symlink to be recognized + +sleep 2 + +# Start the service +start SchneiderMeterDriver +EOF + +echo "Deployment and service setup completed successfully."