Пример #1
0
        private static async Task <List <Inverter> > ReadInverterProduction(EnvoyDataProvider envoyDataProvider)
        {
            Console.WriteLine("Read inverter producton");

            var inverters = await envoyDataProvider.GetInverterProduction();

            if (inverters == null)
            {
                throw new Exception("No inverter data found");
            }

            Console.WriteLine("  S/N\t\tReportTime\t\t\tWatts");

            foreach (var inverter in inverters)
            {
                if (inverter.LastReportDate > 0)
                {
                    var reportTime = DateTimeOffset.FromUnixTimeSeconds(inverter.LastReportDate);

                    Console.WriteLine($"  {inverter.SerialNumber}\t{reportTime.ToLocalTime()}\t{inverter.LastReportWatts}");
                }
            }

            Console.WriteLine($"  Total watts: {inverters.Sum(i => i.LastReportWatts)}");

            return(inverters);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
            }
        }
Пример #4
0
        private static async Task <List <Inverter> > ReadInverterInfo(EnvoyDataProvider envoyDataProvider)
        {
            Console.WriteLine("Read inverter producton");

            var inverters = await envoyDataProvider.GetInverterInfo();

            if (inverters == null)
            {
                throw new Exception("No inverter data found");
            }

            Console.WriteLine("  S/N\t\tReportTime\t\t\tWatts\tMax\tProd\tImage");

            foreach (var inverter in inverters)
            {
                if (inverter.Production.LastReportDate > 0)
                {
                    var reportTime = DateTimeOffset.FromUnixTimeSeconds(inverter.Production.LastReportDate);

                    var line = new List <string>
                    {
                        inverter.Production.SerialNumber,
                        Convert.ToString(reportTime.ToLocalTime()),
                        Convert.ToString(inverter.Production.LastReportWatts),
                        Convert.ToString(inverter.Production.MaxReportWatts),
                        Convert.ToString(inverter.DeviceInfo?.Producing),
                        Convert.ToString(inverter.DeviceInfo?.ImagePnumRunning),
                    };

                    Console.WriteLine($"  {string.Join("\t", line)}");
                }
            }

            Console.WriteLine($"  Count: {inverters.Count}");
            Console.WriteLine($"  Total watts: {inverters.Sum(i => i.Production.LastReportWatts)}");

            return(inverters);
        }
Пример #5
0
        static async Task Main(string[] args)
        {
            Console.WriteLine($"Current date/time: {DateTimeOffset.Now}");
            Console.WriteLine($"Local timezone: {TimeZoneInfo.Local}");

            var appSettings = ReadAppConfiguration();
            var logger      = new ConsoleLogger();

            Console.WriteLine($"Use Envoy: {appSettings.EnvoyBaseUrl} as {appSettings.EnvoyUsername}");

            try
            {
                await Retry.Do(async() =>
                {
                    var envoyDataProvider = new EnvoyDataProvider(appSettings.EnvoyUsername, appSettings.EnvoyPassword, appSettings.EnvoyBaseUrl);
                    var weatherProvider   = GetWeatherProvider(appSettings, logger);

                    var systemProduction = await ReadSystemProduction(envoyDataProvider);
                    var inverters        = await ReadInverterInfo(envoyDataProvider);

                    var outputs = new List <IOutput>();

                    AddOutputs(appSettings, logger, weatherProvider, outputs);

                    if (outputs.Count == 0)
                    {
                        throw new Exception("No output found to write to");
                    }

                    await Task.WhenAll(outputs.Select(o => WriteToOutput(inverters, systemProduction, o)));
                }, retryInterval : TimeSpan.FromSeconds(1), maxAttemptCount : 50);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.ToString());
            }
        }