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);
|
return Run(hostName, ModbusTcpClient.DefaultPort, dbusAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<Exception> Run(String hostName, UInt16 port, Bus dbusAddress)
|
public static async Task<Exception> Run(String hostName, UInt16 port, Bus dbusAddress)
|
||||||
{
|
{
|
||||||
// var ep = new UnixDomainSocketEndPoint("/home/eef/graber_dbus.sock");
|
// var ep = new UnixDomainSocketEndPoint("/home/eef/graber_dbus.sock");
|
||||||
|
@ -25,26 +26,15 @@ public static class SchneiderMeterDriver
|
||||||
|
|
||||||
|
|
||||||
var schneiderStatus = Observable
|
var schneiderStatus = Observable
|
||||||
.Interval(Config.UpdatePeriod)
|
.Interval(Config.UpdatePeriod)
|
||||||
.Select(_ => schneider.Read())
|
.Select(_ => schneider.Read())
|
||||||
.Publish();
|
.Where(reading => reading != null)
|
||||||
|
.Publish();
|
||||||
|
|
||||||
var x = schneider.Read();
|
|
||||||
|
|
||||||
var poller = schneiderStatus.Connect();
|
var poller = schneiderStatus.Connect();
|
||||||
|
|
||||||
var properties = Config.DefaultProperties;
|
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
|
var signals = Config
|
||||||
.Signals
|
.Signals
|
||||||
.Select(signal => schneiderStatus
|
.Select(signal => schneiderStatus
|
||||||
|
@ -62,39 +52,31 @@ public static class SchneiderMeterDriver
|
||||||
return property;
|
return property;
|
||||||
})
|
})
|
||||||
.Where(property => property != null))
|
.Where(property => property != null))
|
||||||
.Merge()
|
.Merge()
|
||||||
.Do(p =>
|
.Do(p =>
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Setting property: {p}");
|
Console.WriteLine($"Setting property: {p}");
|
||||||
properties.Set(p);
|
properties.Set(p);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Log initial signals
|
// TODO: remove when possible
|
||||||
/*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
|
// Apparently some VE services need to be periodically reminded that
|
||||||
// this service is /Connected
|
// this service is /Connected
|
||||||
Console.WriteLine("Goes to subscribe");
|
Console.WriteLine("Goes to subscribe");
|
||||||
schneiderStatus.Subscribe(_ => properties.Set("/Connected", 1));
|
schneiderStatus.Subscribe(_ => properties.Set("/Connected", 1));
|
||||||
Console.WriteLine("Subscribed successfully");
|
Console.WriteLine("Subscribed successfully");
|
||||||
|
|
||||||
// Wait until status is read once to make sure all
|
// Wait until status is read once to make sure all
|
||||||
// properties are set when we go onto the bus.
|
// properties are set when we go onto the bus.
|
||||||
|
|
||||||
var dbus = schneiderStatus
|
var dbus = schneiderStatus
|
||||||
.Skip(1)
|
.Skip(1)
|
||||||
.Take(1)
|
.Take(1)
|
||||||
.SelectMany(_ => PublishPropertiesOnDBus(properties, dbusAddress));
|
.SelectMany(_ => PublishPropertiesOnDBus(properties, dbusAddress));
|
||||||
|
|
||||||
return await signals
|
|
||||||
.MergeErrors(dbus)
|
|
||||||
.Finally(poller.Dispose)
|
|
||||||
.SelectErrors();
|
|
||||||
|
|
||||||
|
return await signals
|
||||||
|
.MergeErrors(dbus)
|
||||||
|
.Finally(poller.Dispose)
|
||||||
|
.SelectErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue