Update publishing only the reading value from the meter
This commit is contained in:
parent
dca4543a13
commit
94c1324f06
|
@ -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");
|
||||
|
@ -25,26 +26,15 @@ public static class SchneiderMeterDriver
|
|||
|
||||
|
||||
var schneiderStatus = Observable
|
||||
.Interval(Config.UpdatePeriod)
|
||||
.Select(_ => schneider.Read())
|
||||
.Publish();
|
||||
.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
|
||||
|
@ -62,39 +52,31 @@ public static class SchneiderMeterDriver
|
|||
return property;
|
||||
})
|
||||
.Where(property => property != null))
|
||||
.Merge()
|
||||
.Do(p =>
|
||||
{
|
||||
Console.WriteLine($"Setting property: {p}");
|
||||
properties.Set(p);
|
||||
});
|
||||
.Merge()
|
||||
.Do(p =>
|
||||
{
|
||||
Console.WriteLine($"Setting property: {p}");
|
||||
properties.Set(p);
|
||||
});
|
||||
|
||||
// Log initial signals
|
||||
/*Console.WriteLine("Initial Signals:");
|
||||
foreach (var signal in signalsCollection)
|
||||
{
|
||||
Console.WriteLine($"Signal: {signal}");
|
||||
}*/
|
||||
|
||||
// TODO: remove when possible
|
||||
// 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)
|
||||
.SelectMany(_ => PublishPropertiesOnDBus(properties, dbusAddress));
|
||||
|
||||
return await signals
|
||||
.MergeErrors(dbus)
|
||||
.Finally(poller.Dispose)
|
||||
.SelectErrors();
|
||||
.Skip(1)
|
||||
.Take(1)
|
||||
.SelectMany(_ => PublishPropertiesOnDBus(properties, dbusAddress));
|
||||
|
||||
return await signals
|
||||
.MergeErrors(dbus)
|
||||
.Finally(poller.Dispose)
|
||||
.SelectErrors();
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue