From df0983e97ec78faf53489268a45ea82ad662c344 Mon Sep 17 00:00:00 2001 From: atef Date: Thu, 13 Jul 2023 09:42:50 +0200 Subject: [PATCH 1/6] Update tunnel and running script. --- csharp/App/SaliMax/run (Salimax 0001).sh | 15 ++++---- csharp/App/SaliMax/run (Salimax0002).sh | 34 +++++++++++++++++ csharp/App/SaliMax/tunnelstoSalimax0002.sh | 43 ++++++++++++++++++++++ csharp/App/SaliMax/tunnelstoSalimax0003.sh | 2 +- 4 files changed, 86 insertions(+), 8 deletions(-) create mode 100644 csharp/App/SaliMax/run (Salimax0002).sh create mode 100755 csharp/App/SaliMax/tunnelstoSalimax0002.sh diff --git a/csharp/App/SaliMax/run (Salimax 0001).sh b/csharp/App/SaliMax/run (Salimax 0001).sh index 2091f5208..c54c82e6f 100755 --- a/csharp/App/SaliMax/run (Salimax 0001).sh +++ b/csharp/App/SaliMax/run (Salimax 0001).sh @@ -1,33 +1,34 @@ #!/bin/bash dotnet_version='net6.0' -salimax_ip= '10.2.3.104' +salimax_ip='10.2.3.104' username='ie-entwicklung' set -e echo -e "\n============================ Build ============================\n" -dotnet publish \ +dotnet publish \ ./SaliMax.csproj \ + -p:PublishTrimmed=false \ -c Release \ - -r linux-x64 - + -r linux-x64 + echo -e "\n============================ Deploy ============================\n" rsync -v \ ./bin/Release/$dotnet_version/linux-x64/publish/* \ - ie-entwicklung@10.2.3.104:~/salimax + $username@$salimax_ip:~/salimax echo -e "\n============================ Restart Salimax sevice ============================\n" ssh -tt \ - ie-entwicklung@10.2.3.104 \ + $username@$salimax_ip \ sudo systemctl restart salimax.service echo -e "\n============================ Print service output ============================\n" ssh -tt \ - ie-entwicklung@10.2.3.104 \ + $username@$salimax_ip \ journalctl -f -u salimax.service diff --git a/csharp/App/SaliMax/run (Salimax0002).sh b/csharp/App/SaliMax/run (Salimax0002).sh new file mode 100644 index 000000000..44b8fe549 --- /dev/null +++ b/csharp/App/SaliMax/run (Salimax0002).sh @@ -0,0 +1,34 @@ +#!/bin/bash + +dotnet_version='net6.0' +salimax_ip='10.2.4.29' +username='ie-entwicklung' + +set -e + +echo -e "\n============================ Build ============================\n" + +dotnet publish \ + ./SaliMax.csproj \ + -p:PublishTrimmed=false \ + -c Release \ + -r linux-x64 + +echo -e "\n============================ Deploy ============================\n" + +rsync -v \ + ./bin/Release/$dotnet_version/linux-x64/publish/* \ + $username@$salimax_ip:~/salimax + +echo -e "\n============================ Restart Salimax sevice ============================\n" + +ssh -tt \ + $username@$salimax_ip \ + sudo systemctl restart salimax.service + + +echo -e "\n============================ Print service output ============================\n" + +ssh -tt \ + $username@$salimax_ip \ + journalctl -f -u salimax.service \ No newline at end of file diff --git a/csharp/App/SaliMax/tunnelstoSalimax0002.sh b/csharp/App/SaliMax/tunnelstoSalimax0002.sh new file mode 100755 index 000000000..98cd400bd --- /dev/null +++ b/csharp/App/SaliMax/tunnelstoSalimax0002.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +host=ie-entwicklung@10.2.4.29 + +tunnel() { + name=$1 + ip=$2 + rPort=$3 + lPort=$4 + + echo -n "localhost:$lPort $name " + ssh -nNTL "$lPort:$ip:$rPort" "$host" 2> /dev/null & + + until nc -vz 127.0.0.1 $lPort 2> /dev/null + do + echo -n . + sleep 0.3 + done + + echo "ok" +} + +echo "" + +tunnel "Trumpf Inverter (http) " 10.0.2.1 80 9001 +tunnel "Trumpf DCDC (http) " 10.0.3.1 80 9002 +tunnel "Ext Emu Meter (http) " 10.0.4.1 80 9003 +tunnel "Int Emu Meter (http) " 10.0.4.2 80 9004 +tunnel "AMPT (http) " 10.0.5.1 8080 9005 + +#tunnel "Trumpf Inverter (modbus)" 10.0.2.1 502 3001 +#tunnel "Trumpf DCDC (modbus) " 10.0.3.1 502 3002 +#tunnel "Ext Emu Meter (modbus) " 10.0.4.1 502 3003 +#tunnel "Int Emu Meter " 10.0.4.2 502 3004 +#tunnel "AMPT (modbus) " 10.0.5.1 502 3005 +#tunnel "Batteries " 127.0.0.1 6855 3007 + + +echo +echo "press any key to close the tunnels ..." +read -r -n 1 -s +kill $(jobs -p) +echo "done" diff --git a/csharp/App/SaliMax/tunnelstoSalimax0003.sh b/csharp/App/SaliMax/tunnelstoSalimax0003.sh index da40a584a..a5e184247 100755 --- a/csharp/App/SaliMax/tunnelstoSalimax0003.sh +++ b/csharp/App/SaliMax/tunnelstoSalimax0003.sh @@ -33,7 +33,7 @@ tunnel "Trumpf DCDC (modbus) " 10.0.3.1 502 3002 tunnel "Ext Emu Meter (modbus) " 10.0.4.1 502 3003 tunnel "Int Emu Meter " 10.0.4.2 502 3004 tunnel "AMPT (modbus) " 10.0.5.1 502 3005 -tunnel "Batteries " 127.0.0.1 6855 5007 +tunnel "Batteries " 127.0.0.1 6855 3007 echo From dafef572ab82a56ce8ed228311fc8a365182997a Mon Sep 17 00:00:00 2001 From: atef Date: Thu, 13 Jul 2023 09:50:40 +0200 Subject: [PATCH 2/6] Add try Catch over SystemControl write function --- .../TruConvertAc/TruConvertAcDcDevices.cs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/csharp/Lib/Devices/Trumpf/TruConvertAc/TruConvertAcDcDevices.cs b/csharp/Lib/Devices/Trumpf/TruConvertAc/TruConvertAcDcDevices.cs index 31cea2131..0078f19f2 100644 --- a/csharp/Lib/Devices/Trumpf/TruConvertAc/TruConvertAcDcDevices.cs +++ b/csharp/Lib/Devices/Trumpf/TruConvertAc/TruConvertAcDcDevices.cs @@ -17,7 +17,7 @@ public class TruConvertAcDcDevices public TruConvertAcDcDevices(Channel transport) { - var modbusClient = new ModbusTcpClient(transport, 0); + var modbusClient = new ModbusTcpClient(transport, slaveId: 0); _SystemControl = new ModbusDevice(modbusClient); @@ -57,21 +57,21 @@ public class TruConvertAcDcDevices public void Write(AcDcDevicesRecord r) { - if (r.SystemControl is not null) - _SystemControl.Write(r.SystemControl); // must run BEFORE the attached devices - - foreach (var (ctrl, device) in r.Devices.Zip(_AcDcs)) + try { - try + if (r.SystemControl is not null) + _SystemControl.Write(r.SystemControl); // must run BEFORE the attached devices + + foreach (var (ctrl, device) in r.Devices.Zip(_AcDcs)) { device.Write(ctrl); } - catch (Exception e) - { - Console.WriteLine(e); - // TODO: log - } } + catch (Exception e) + { + Console.WriteLine(e); + // TODO: log + } } } \ No newline at end of file From 486abbdf56c9836fd3f267310a5d7799b8b65d02 Mon Sep 17 00:00:00 2001 From: atef Date: Thu, 13 Jul 2023 09:53:13 +0200 Subject: [PATCH 3/6] Switch few function from public to private --- csharp/App/SaliMax/src/SaliMaxRelays/RelaysRecord.cs | 2 +- .../Trumpf/SystemControl/SystemControlRegisters.Modbus.cs | 2 +- csharp/Lib/Utils/TextBlock.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/csharp/App/SaliMax/src/SaliMaxRelays/RelaysRecord.cs b/csharp/App/SaliMax/src/SaliMaxRelays/RelaysRecord.cs index 2f0f98aee..09875bbf2 100644 --- a/csharp/App/SaliMax/src/SaliMaxRelays/RelaysRecord.cs +++ b/csharp/App/SaliMax/src/SaliMaxRelays/RelaysRecord.cs @@ -6,7 +6,7 @@ public class RelaysRecord { private readonly Adam6360DRegisters _Regs; - public RelaysRecord(Adam6360DRegisters regs) => _Regs = regs; + private RelaysRecord(Adam6360DRegisters regs) => _Regs = regs; public Boolean K1GridBusIsConnectedToGrid => _Regs.DigitalInput6; public Boolean K2IslandBusIsConnectedToGridBus => !_Regs.DigitalInput4; diff --git a/csharp/Lib/Devices/Trumpf/SystemControl/SystemControlRegisters.Modbus.cs b/csharp/Lib/Devices/Trumpf/SystemControl/SystemControlRegisters.Modbus.cs index 4ea2187dc..5afaa7e4a 100644 --- a/csharp/Lib/Devices/Trumpf/SystemControl/SystemControlRegisters.Modbus.cs +++ b/csharp/Lib/Devices/Trumpf/SystemControl/SystemControlRegisters.Modbus.cs @@ -26,7 +26,7 @@ public partial record SystemControlRegisters //[Coil(4002)] [HoldingRegister(4002)] public Boolean ResetAlarmsAndWarnings { get; set; } - [HoldingRegister(4007)] public UInt16 TargetSlave { get; set; } + [HoldingRegister(4007)] public UInt16 TargetSlave { get; set; } //[Coil(4011)] [HoldingRegister(4011)] public Boolean UseSlaveIdForAddressing { get; set; } diff --git a/csharp/Lib/Utils/TextBlock.cs b/csharp/Lib/Utils/TextBlock.cs index 2f03efae7..1f7349d78 100644 --- a/csharp/Lib/Utils/TextBlock.cs +++ b/csharp/Lib/Utils/TextBlock.cs @@ -23,7 +23,7 @@ public class TextBlock return new TextBlock(alignedLines); } - public static TextBlock AlignRight(IReadOnlyList things) + private static TextBlock AlignRight(IReadOnlyList things) { var lines = things .SelectMany(GetLines) From 12b0c94d78a9b2ffbb1e4bae00121c8e0d7c5f63 Mon Sep 17 00:00:00 2001 From: atef Date: Thu, 13 Jul 2023 09:53:44 +0200 Subject: [PATCH 4/6] Update Config file and Inverter state --- csharp/App/SaliMax/src/SystemConfig/Config.cs | 12 ++---------- .../Trumpf/TruConvertAc/DataTypes/InverterState.cs | 1 + 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/csharp/App/SaliMax/src/SystemConfig/Config.cs b/csharp/App/SaliMax/src/SystemConfig/Config.cs index 294cf1f5d..36ef337d5 100644 --- a/csharp/App/SaliMax/src/SystemConfig/Config.cs +++ b/csharp/App/SaliMax/src/SystemConfig/Config.cs @@ -51,17 +51,9 @@ public class Config //TODO: let IE choose from config files (Json) and connect t AmptIp = new() { Host = "localhost", Port = 5005}, RelaysIp = new() { Host = "localhost", Port = 5006}, BatteryIp = new() { Host = "localhost", Port = 5007}, - BatteryNodes = new []{ 2, 3, 4, 5, 6 }, + BatteryNodes = new []{ 2, 3, 4, 5, 6 } }, - S3 = new() - { - Bucket = "saliomameiringen", - Region = "sos-ch-dk-2", - Provider = "exo.io", - ContentType = "text/plain; charset=utf-8", - Key = "EXO2bf0cbd97fbfa75aa36ed46f", - Secret = "Bn1CDPqOG-XpDSbYjfIJxojcHTm391vZTc8z8l_fEPs" - } + S3 = null }; #else public static Config Default => new() diff --git a/csharp/Lib/Devices/Trumpf/TruConvertAc/DataTypes/InverterState.cs b/csharp/Lib/Devices/Trumpf/TruConvertAc/DataTypes/InverterState.cs index f1adab68b..3ded5d654 100644 --- a/csharp/Lib/Devices/Trumpf/TruConvertAc/DataTypes/InverterState.cs +++ b/csharp/Lib/Devices/Trumpf/TruConvertAc/DataTypes/InverterState.cs @@ -9,5 +9,6 @@ public enum InverterState : UInt16 AcSyncToGrid = 4, AcCloseContactor = 5, AcConnected = 6, + AcOpenContactor = 7, Alarm = 99 } \ No newline at end of file From a070891e7ee8b59b06625eca67dfaacd5389c37a Mon Sep 17 00:00:00 2001 From: Kim Date: Thu, 13 Jul 2023 10:01:30 +0200 Subject: [PATCH 5/6] Set bucket cors on creation of new installation --- csharp/App/Backend/S3/S3Cmd.cs | 13 ++++++++++++- csharp/App/Backend/db.sqlite | Bin 122880 -> 122880 bytes 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/csharp/App/Backend/S3/S3Cmd.cs b/csharp/App/Backend/S3/S3Cmd.cs index f3fd9160a..0851e5534 100644 --- a/csharp/App/Backend/S3/S3Cmd.cs +++ b/csharp/App/Backend/S3/S3Cmd.cs @@ -46,8 +46,19 @@ public class S3Cmd public async Task CreateBucket(String bucketName) { + var cors = @" + + + * + GET + HEAD + * + + "; var result = await Run(bucketName, "mb"); - return result.ExitCode == 0; + var setCors = await Run(bucketName, "PutBucketCors", cors); + + return result.ExitCode == 0 && setCors.ExitCode == 0; } public async Task DeleteBucket(String bucketName) diff --git a/csharp/App/Backend/db.sqlite b/csharp/App/Backend/db.sqlite index 2fcbf7c64e053a60a0087c98b34bfc9736f54d73..9a363a376558e36a632523bcdff07de64a7ffe59 100644 GIT binary patch delta 956 zcma))&ube;6vuaB*=xm;Y|$1ILLJAh4+aa*&g{<|no8DBTPsUmBw5bEogK|uiX5%A zS*?CRs~D3)pwO5=bIGBnUV3Q}RHdg}`wtXK4!wjNTIjKdQfRlKt$k}B@4@iin=fBJ zya&(u2haJ(*P}Ze$1VBwPb{5pV6gMm`>9R9k3ZkM^IkY|&P|10a^Y_xpN3wJqYK}M z-aIW$MQ^;dIy)O)y|zWU)o^f&K2b;OqtyN`6YCUVkwI01qJ;gYNhHeZ9&Ht!CTgqc znwjn3d?A%H3IbD4GSz{3v}+ssUe4M>aZAt*a@@Q}`Vd0w3qn(rpm<`h9W`62r4zACr+^Ndx^W~q7OfV$P#RVX#q4hGZ^K2$ zc5QcX!hF{fL!wDh9cmg=Oojv~F)B-vo;$gh?R57u)`602yla|8I80RYl93?;FWV~( zTBK@a>dJj(yEX4}(>G7=T#4Si#QKKMI@flYb4*%KZjV;}VlE?1L|CokdL2WGiDn`s zAxl!q+EFe}5{PXd*vFaDLCZwS{l0)R3Ap^}IWAJb=emm%ZTN}$O2Ch0j znH@G*S@wuS8^pQj8jL#3{dcf_w!-s^Yir;mejJ)>fz6A}|Mh?T1Ahwy=B|Jb#*4w9 PL4f0cH<|eY{3iYhKo}m? delta 508 zcmZoTz}|3xeS);0D+2?A91z2R)I=R)M%RrAuKJ8@o0sWFJMi+WGcfZpFz_+(P2?}x zEGY1aSE!MXkzZa^nS+B@S<*R~L6?_v@|jwlR6|3^k8v6Q1 zr2BarR(XW^_?!4w)9lnD!=wU^+s)P1TdYEKS;5Mu@5*OXn0_*z(TRB?|Lx6!2F?7cD$Kr& zgp6U^zAc~8UVxEp`?q?=SNv>XGugI3>t~b}-~~FKoBb98-#flJd;t@Sw6 Date: Thu, 13 Jul 2023 10:16:31 +0200 Subject: [PATCH 6/6] catching moves to same parent --- csharp/App/Backend/DataTypes/Methods/Session.cs | 2 ++ csharp/App/Backend/S3/S3Cmd.cs | 1 + 2 files changed, 3 insertions(+) diff --git a/csharp/App/Backend/DataTypes/Methods/Session.cs b/csharp/App/Backend/DataTypes/Methods/Session.cs index 3ba5641de..4856816cd 100644 --- a/csharp/App/Backend/DataTypes/Methods/Session.cs +++ b/csharp/App/Backend/DataTypes/Methods/Session.cs @@ -54,6 +54,8 @@ public static class SessionMethods var user = session?.User; var installation = Db.GetInstallationById(installationId); var parent = Db.GetFolderById(parentId); + + if(installation.ParentId == parentId) return false; return user is not null && installation is not null diff --git a/csharp/App/Backend/S3/S3Cmd.cs b/csharp/App/Backend/S3/S3Cmd.cs index 0851e5534..6cd4a8f6e 100644 --- a/csharp/App/Backend/S3/S3Cmd.cs +++ b/csharp/App/Backend/S3/S3Cmd.cs @@ -55,6 +55,7 @@ public class S3Cmd * "; + var result = await Run(bucketName, "mb"); var setCors = await Run(bucketName, "PutBucketCors", cors);