Update publishing only the reading value from the meter

This commit is contained in:
atef 2024-07-01 15:12:59 +02:00
parent dca4543a13
commit 94c1324f06
1 changed files with 21 additions and 39 deletions

View File

@ -15,6 +15,7 @@ public static class SchneiderMeterDriver
{
return Run(hostName, ModbusTcpClient.DefaultPort, dbusAddress);
}
public static async Task<Exception> Run(String hostName, UInt16 port, Bus dbusAddress)
{
// var ep = new UnixDomainSocketEndPoint("/home/eef/graber_dbus.sock");
@ -27,24 +28,13 @@ public static class SchneiderMeterDriver
var schneiderStatus = Observable
.Interval(Config.UpdatePeriod)
.Select(_ => schneider.Read())
.Where(reading => reading != null)
.Publish();
var x = schneider.Read();
var poller = schneiderStatus.Connect();
var properties = Config.DefaultProperties;
// Step 1: Access Config.Signals
var signalsCollection = Config.Signals;
/*var signals = Config
.Signals
.Select(signal => schneiderStatus.Select(signal.ToVeProperty))
.Merge()
.Do(p => properties.Set(p));*/
var signals = Config
.Signals
.Select(signal => schneiderStatus
@ -69,22 +59,15 @@ public static class SchneiderMeterDriver
properties.Set(p);
});
// Log initial signals
/*Console.WriteLine("Initial Signals:");
foreach (var signal in signalsCollection)
{
Console.WriteLine($"Signal: {signal}");
}*/
// TODO: remove when possible
// Apparently some VE services need to be periodically reminded that
// this service is /Connected
Console.WriteLine("Goes to subscribe");
schneiderStatus.Subscribe(_ => properties.Set("/Connected", 1));
Console.WriteLine("Subscribed successfully");
// Wait until status is read once to make sure all
// properties are set when we go onto the bus.
var dbus = schneiderStatus
.Skip(1)
.Take(1)
@ -94,7 +77,6 @@ public static class SchneiderMeterDriver
.MergeErrors(dbus)
.Finally(poller.Dispose)
.SelectErrors();
}