private static async Task <SystemProduction> ReadSystemProduction(EnvoyDataProvider envoyDataProvider) { Console.WriteLine("Read system producton"); var production = await envoyDataProvider.GetSystemProduction(); if (production == null) { throw new Exception("No production data found"); } var inverters = production.FirstOrDefault(p => p.Type == "inverters"); if (inverters == null) { throw new Exception("No inverter data found"); } var readingTime = DateTimeOffset.FromUnixTimeSeconds(inverters.ReadingTime); Console.WriteLine($" ActiveCount: {inverters.ActiveCount}"); Console.WriteLine($" ReadingTime: {readingTime.ToLocalTime()}"); Console.WriteLine($" Type: {inverters.Type}"); Console.WriteLine($" WhLifeTime: {inverters.WhLifeTime}"); Console.WriteLine($" WNow: {inverters.WNow}"); return(inverters); }
static async Task Main(string[] args) { Console.WriteLine(DateTimeOffset.Now); var appSettings = ReadAppConfiguration(); Console.WriteLine($"Use Envoy: {appSettings.EnvoyBaseUrl} as {appSettings.EnvoyUsername}"); while (true) { try { var envoyDataProvider = new EnvoyDataProvider(appSettings.EnvoyUsername, appSettings.EnvoyPassword, appSettings.EnvoyBaseUrl); var data = await envoyDataProvider.GetSystemProduction(); var invertersPower = data.Production.FirstOrDefault(p => p.Type == "inverters"); var production = data.Production.FirstOrDefault(p => p.MeasurementType == "production"); var consumption = data.Consumption.FirstOrDefault(p => p.MeasurementType == "total-consumption"); var inverters = await ReadInverterProduction(envoyDataProvider); var influxDb = new Output.InfluxDB(appSettings); await influxDb.WriteAsync(invertersPower, production, consumption, inverters); } catch (Exception ex) { Console.Error.WriteLine(ex); } Thread.Sleep(60 * 1000); } }