Beispiel #1
0
        private static async Task WriteDataToInfluxDb()
        {
            try
            {
                AIO_Values values = await FetchValuesFromAIO();

                //first the current data point
                bool success = await influxClient.CreateDatabaseAsync(influxDbName);  //create db if not exist

                if (success)
                {
                    await CreateRetentionPolicy();                                       // craete retention policy for minute data points if not exists

                    var point  = CreateInfluxSeries(values);                             //create the influx point
                    var result = await influxClient.PostPointAsync(influxDbName, point); //save the data point

                    Console.Write("Wrote point to influx db");
                }
                //Now the longterm data
                success = await influxClient.CreateDatabaseAsync(influxDbNameLongterm);  //create longeterm db if not exist

                if (success)
                {
                    await CreateRetentionPolicyLongterm();

                    MonthlyValues monthlyValues = await GetCurrentMonthAggregation();  //check if we already have aggregations for the last month and year
                    await InsertMonthlyValues(monthlyValues);
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }
        }
Beispiel #2
0
        private static InfluxDatapoint <InfluxValueField> CreateInfluxSeries(AIO_Values values)
        {
            var influxValues = new InfluxDatapoint <InfluxValueField>();

            influxValues.UtcTimestamp = DateTime.UtcNow;
            influxValues.Fields.Add("Pv", new InfluxValueField(values.Pv));
            influxValues.Fields.Add("Load", new InfluxValueField(values.Load));
            influxValues.Fields.Add("Inv", new InfluxValueField(values.Inv));
            influxValues.Fields.Add("Demand", new InfluxValueField(values.Demand));
            influxValues.Fields.Add("FeedIn", new InfluxValueField(values.FeedIn));
            influxValues.Fields.Add("Grid", new InfluxValueField(values.Grid));
            influxValues.Fields.Add("BatteryP", new InfluxValueField(values.BatteryP));
            influxValues.Fields.Add("BatterySoc", new InfluxValueField(values.BatterySoc));
            influxValues.Fields.Add("Temp", new InfluxValueField(values.Temp));
            influxValues.Fields.Add("ADC", new InfluxValueField(values.ADC));

            influxValues.MeasurementName = measurement_points;
            influxValues.Precision       = TimePrecision.Seconds;
            influxValues.Retention       = new InfluxRetentionPolicy()
            {
                Name = ret_policy_point
            };
            return(influxValues);
        }
Beispiel #3
0
        private static async Task <AIO_Values> FetchValuesFromAIO()
        {
            AIO_Values values  = new AIO_Values();
            var        htmlWeb = new HtmlWeb();
            var        doc     = await htmlWeb.LoadFromWebAsync(aio_url);

            // Using LINQ to get HTML table
            var HTMLTableTRList = from table in doc.DocumentNode.SelectNodes("//table").Cast <HtmlNode>()
                                  from row in table.SelectNodes("//tr").Cast <HtmlNode>()
                                  from cell in row.SelectNodes("th|td").Cast <HtmlNode>()
                                  select new { Table_Name = table.Id, Cell_Text = cell.InnerText };

            // now parsing output from tabel
            int i = 0;

            foreach (var cell in HTMLTableTRList)

            {
                if (cell.Cell_Text == "BT_SOC")
                {
                    values.BatterySoc = float.Parse(HTMLTableTRList.ElementAt(i + 1).Cell_Text, System.Globalization.CultureInfo.InvariantCulture);
                }
                if (cell.Cell_Text == "BT_P")
                {
                    values.BatteryP = float.Parse(HTMLTableTRList.ElementAt(i + 1).Cell_Text, System.Globalization.CultureInfo.InvariantCulture);
                }
                if (cell.Cell_Text == "LOAD_P(30s)")
                {
                    values.Load = float.Parse(HTMLTableTRList.ElementAt(i + 1).Cell_Text, System.Globalization.CultureInfo.InvariantCulture);
                }
                if (cell.Cell_Text == "PV_P(30s)")
                {
                    values.Pv = float.Parse(HTMLTableTRList.ElementAt(i + 1).Cell_Text, System.Globalization.CultureInfo.InvariantCulture);
                }
                if (cell.Cell_Text == "GRID_P(30s)")
                {
                    values.Grid = float.Parse(HTMLTableTRList.ElementAt(i + 1).Cell_Text, System.Globalization.CultureInfo.InvariantCulture);
                    if (values.Grid > 0)
                    {
                        values.Demand = values.Grid;
                    }
                    else
                    {
                        values.FeedIn = values.Grid;
                    }
                }
                if (cell.Cell_Text == "INV_P(30s)")
                {
                    values.Inv = float.Parse(HTMLTableTRList.ElementAt(i + 1).Cell_Text, System.Globalization.CultureInfo.InvariantCulture);
                }
                if (cell.Cell_Text == "Temp")
                {
                    values.Temp = float.Parse(HTMLTableTRList.ElementAt(i + 1).Cell_Text, System.Globalization.CultureInfo.InvariantCulture);
                }
                if (cell.Cell_Text == "(ADC)")
                {
                    values.ADC = float.Parse(HTMLTableTRList.ElementAt(i + 1).Cell_Text, System.Globalization.CultureInfo.InvariantCulture);
                    break;
                }
                i++;
            }
            return(values);
        }