diff --git a/Wetterstation/Form1.Designer.cs b/Wetterstation/Form1.Designer.cs index 91e3cf25c9fac86f426e8cd127111eafb697fe3d..49406d8c4df404fc06c8f5450ac0d8dbdd952601 100644 --- a/Wetterstation/Form1.Designer.cs +++ b/Wetterstation/Form1.Designer.cs @@ -71,10 +71,10 @@ namespace Wetterstation this.label2 = new System.Windows.Forms.Label(); this.lbInnen = new System.Windows.Forms.Label(); this.lbAussen = new System.Windows.Forms.Label(); - this.label5 = new System.Windows.Forms.Label(); - this.lbTempMax = new System.Windows.Forms.Label(); - this.lbTempMin = new System.Windows.Forms.Label(); - this.label8 = new System.Windows.Forms.Label(); + this.lbTempInMax = new System.Windows.Forms.Label(); + this.lbTempOutMax = new System.Windows.Forms.Label(); + this.lbTempOutMin = new System.Windows.Forms.Label(); + this.lbTempInMin = new System.Windows.Forms.Label(); this.lbForecastTemp1 = new System.Windows.Forms.Label(); this.lbForecastTemp2 = new System.Windows.Forms.Label(); this.lbForecastTemp3 = new System.Windows.Forms.Label(); @@ -555,57 +555,57 @@ namespace Wetterstation this.lbAussen.TabIndex = 50; this.lbAussen.Text = "Aussen"; // - // label5 - // - this.label5.AutoSize = true; - this.label5.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(90)))), ((int)(((byte)(10)))), ((int)(((byte)(80)))), ((int)(((byte)(147))))); - this.label5.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label5.ForeColor = System.Drawing.SystemColors.ButtonFace; - this.label5.Location = new System.Drawing.Point(697, 358); - this.label5.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label5.Name = "label5"; - this.label5.Size = new System.Drawing.Size(51, 17); - this.label5.TabIndex = 51; - this.label5.Text = "NA C°"; - // - // lbTempMax - // - this.lbTempMax.AutoSize = true; - this.lbTempMax.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(90)))), ((int)(((byte)(10)))), ((int)(((byte)(80)))), ((int)(((byte)(147))))); - this.lbTempMax.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.lbTempMax.ForeColor = System.Drawing.SystemColors.ButtonFace; - this.lbTempMax.Location = new System.Drawing.Point(787, 358); - this.lbTempMax.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.lbTempMax.Name = "lbTempMax"; - this.lbTempMax.Size = new System.Drawing.Size(51, 17); - this.lbTempMax.TabIndex = 52; - this.lbTempMax.Text = "NA C°"; - // - // lbTempMin - // - this.lbTempMin.AutoSize = true; - this.lbTempMin.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(90)))), ((int)(((byte)(10)))), ((int)(((byte)(80)))), ((int)(((byte)(147))))); - this.lbTempMin.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.lbTempMin.ForeColor = System.Drawing.SystemColors.ButtonFace; - this.lbTempMin.Location = new System.Drawing.Point(787, 385); - this.lbTempMin.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.lbTempMin.Name = "lbTempMin"; - this.lbTempMin.Size = new System.Drawing.Size(51, 17); - this.lbTempMin.TabIndex = 54; - this.lbTempMin.Text = "NA C°"; - // - // label8 - // - this.label8.AutoSize = true; - this.label8.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(90)))), ((int)(((byte)(10)))), ((int)(((byte)(80)))), ((int)(((byte)(147))))); - this.label8.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label8.ForeColor = System.Drawing.SystemColors.ButtonFace; - this.label8.Location = new System.Drawing.Point(699, 385); - this.label8.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label8.Name = "label8"; - this.label8.Size = new System.Drawing.Size(51, 17); - this.label8.TabIndex = 53; - this.label8.Text = "NA C°"; + // lbTempInMax + // + this.lbTempInMax.AutoSize = true; + this.lbTempInMax.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(90)))), ((int)(((byte)(10)))), ((int)(((byte)(80)))), ((int)(((byte)(147))))); + this.lbTempInMax.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lbTempInMax.ForeColor = System.Drawing.SystemColors.ButtonFace; + this.lbTempInMax.Location = new System.Drawing.Point(697, 358); + this.lbTempInMax.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.lbTempInMax.Name = "lbTempInMax"; + this.lbTempInMax.Size = new System.Drawing.Size(51, 17); + this.lbTempInMax.TabIndex = 51; + this.lbTempInMax.Text = "NA C°"; + // + // lbTempOutMax + // + this.lbTempOutMax.AutoSize = true; + this.lbTempOutMax.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(90)))), ((int)(((byte)(10)))), ((int)(((byte)(80)))), ((int)(((byte)(147))))); + this.lbTempOutMax.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lbTempOutMax.ForeColor = System.Drawing.SystemColors.ButtonFace; + this.lbTempOutMax.Location = new System.Drawing.Point(787, 358); + this.lbTempOutMax.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.lbTempOutMax.Name = "lbTempOutMax"; + this.lbTempOutMax.Size = new System.Drawing.Size(51, 17); + this.lbTempOutMax.TabIndex = 52; + this.lbTempOutMax.Text = "NA C°"; + // + // lbTempOutMin + // + this.lbTempOutMin.AutoSize = true; + this.lbTempOutMin.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(90)))), ((int)(((byte)(10)))), ((int)(((byte)(80)))), ((int)(((byte)(147))))); + this.lbTempOutMin.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lbTempOutMin.ForeColor = System.Drawing.SystemColors.ButtonFace; + this.lbTempOutMin.Location = new System.Drawing.Point(787, 385); + this.lbTempOutMin.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.lbTempOutMin.Name = "lbTempOutMin"; + this.lbTempOutMin.Size = new System.Drawing.Size(51, 17); + this.lbTempOutMin.TabIndex = 54; + this.lbTempOutMin.Text = "NA C°"; + // + // lbTempInMin + // + this.lbTempInMin.AutoSize = true; + this.lbTempInMin.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(90)))), ((int)(((byte)(10)))), ((int)(((byte)(80)))), ((int)(((byte)(147))))); + this.lbTempInMin.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lbTempInMin.ForeColor = System.Drawing.SystemColors.ButtonFace; + this.lbTempInMin.Location = new System.Drawing.Point(699, 385); + this.lbTempInMin.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.lbTempInMin.Name = "lbTempInMin"; + this.lbTempInMin.Size = new System.Drawing.Size(51, 17); + this.lbTempInMin.TabIndex = 53; + this.lbTempInMin.Text = "NA C°"; // // lbForecastTemp1 // @@ -811,7 +811,7 @@ namespace Wetterstation this.pbTendenzInnen.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(90)))), ((int)(((byte)(10)))), ((int)(((byte)(80)))), ((int)(((byte)(147))))); this.pbTendenzInnen.Image = global::Wetterstation.Properties.Resources.pfeil_unten; this.pbTendenzInnen.Location = new System.Drawing.Point(1012, 123); - this.pbTendenzInnen.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.pbTendenzInnen.Margin = new System.Windows.Forms.Padding(4); this.pbTendenzInnen.Name = "pbTendenzInnen"; this.pbTendenzInnen.Size = new System.Drawing.Size(27, 62); this.pbTendenzInnen.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; @@ -823,7 +823,7 @@ namespace Wetterstation this.pictureBox2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(90)))), ((int)(((byte)(10)))), ((int)(((byte)(80)))), ((int)(((byte)(147))))); this.pictureBox2.Image = global::Wetterstation.Properties.Resources.pfeil_unten; this.pictureBox2.Location = new System.Drawing.Point(1213, 63); - this.pictureBox2.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.pictureBox2.Margin = new System.Windows.Forms.Padding(4); this.pictureBox2.Name = "pictureBox2"; this.pictureBox2.Size = new System.Drawing.Size(13, 15); this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; @@ -856,10 +856,10 @@ namespace Wetterstation this.Controls.Add(this.lbForecastTemp3); this.Controls.Add(this.lbForecastTemp2); this.Controls.Add(this.lbForecastTemp1); - this.Controls.Add(this.lbTempMin); - this.Controls.Add(this.label8); - this.Controls.Add(this.lbTempMax); - this.Controls.Add(this.label5); + this.Controls.Add(this.lbTempOutMin); + this.Controls.Add(this.lbTempInMin); + this.Controls.Add(this.lbTempOutMax); + this.Controls.Add(this.lbTempInMax); this.Controls.Add(this.lbAussen); this.Controls.Add(this.lbInnen); this.Controls.Add(this.label2); @@ -949,10 +949,10 @@ namespace Wetterstation private Label label2; private Label lbInnen; private Label lbAussen; - private Label label5; - private Label lbTempMin; - private Label label8; - private Label lbTempMax; + private Label lbTempInMax; + private Label lbTempOutMin; + private Label lbTempInMin; + private Label lbTempOutMax; private Label lbForecastTemp1; private Label lbForecastTemp2; private Label lbForecastTemp3; diff --git a/Wetterstation/Form1.cs b/Wetterstation/Form1.cs index 5c493aa6b2741f315a8b512fcbedd94b4314e825..9fafc36fe7177822b09ac22727961e8cf411b7b0 100644 --- a/Wetterstation/Form1.cs +++ b/Wetterstation/Form1.cs @@ -19,6 +19,10 @@ namespace Wetterstation private MqttClient myClient; SettingsModel WeatherstationSettings = new SettingsModel(); String graphLastTimestamp = null; + Sensor node1In = new Sensor(); + Sensor node1Out = new Sensor(); + Sensor owm = new Sensor(); + public Hintergrund() { InitializeComponent(); @@ -237,17 +241,28 @@ namespace Wetterstation try { dynamic weatherData = JsonConvert.DeserializeObject(message.ToString()); - //lbAussenTemp.Invoke(new Action(() => { lbAussenTemp.Text = weatherData.temp + " °C"; })); - lbTempMin.Invoke(new Action(() => { lbTempMin.Text = weatherData.tempMin + " °C"; })); - lbTempMax.Invoke(new Action(() => { lbTempMax.Text = weatherData.tempMax + " °C"; })); - lbLuftfeuchtAussen.Invoke(new Action(() => { lbLuftfeuchtAussen.Text = weatherData.humidity + " %"; })); - lbWindSpeed.Invoke(new Action(() => { lbWindSpeed.Text = weatherData.windSpeed + " ms"; })); - lbWindricht.Invoke(new Action(() => { lbWindricht.Text = weatherData.windDeg + " °"; })); - lbLuftdruck.Invoke(new Action(() => { lbLuftdruck.Text = weatherData.pressure + " mbar"; })); - pbKompassrose.Invoke(new Action(() => { pbKompassrose.Image = RotateImage((Bitmap)global::Wetterstation.Properties.Resources.ResourceManager.GetObject("WindRose_neu"), (int)weatherData.windDeg); })); - lbRain1h.Invoke(new Action(() => { lbRain1h.Text = weatherData.rain1h + " L/h"; })); + if (!node1Out.temperature) + { + lbAussenTemp.Invoke(new Action(() => { lbAussenTemp.Text = Math.Round((double)weatherData.temp, 1) + " °C"; })); + lbTempOutMin.Invoke(new Action(() => { lbTempOutMin.Text = weatherData.tempMin + " °C"; })); + lbTempOutMax.Invoke(new Action(() => { lbTempOutMax.Text = weatherData.tempMax + " °C"; })); + } + if(!node1Out.humidity) + lbLuftfeuchtAussen.Invoke(new Action(() => { lbLuftfeuchtAussen.Text = weatherData.humidity + " %"; })); + if(!node1Out.windSpeed) + lbWindSpeed.Invoke(new Action(() => { lbWindSpeed.Text = weatherData.windSpeed + " ms"; })); + if (!node1Out.windDegre) + { + lbWindricht.Invoke(new Action(() => { lbWindricht.Text = weatherData.windDeg + " °"; })); + pbKompassrose.Invoke(new Action(() => { pbKompassrose.Image = RotateImage((Bitmap)global::Wetterstation.Properties.Resources.ResourceManager.GetObject("WindRose_neu"), (int)weatherData.windDeg); })); + } + if (!node1Out.pressure && !node1In.pressure) + lbLuftdruck.Invoke(new Action(() => { lbLuftdruck.Text = weatherData.pressure + " mbar"; })); + if(!node1Out.rain) + lbRain1h.Invoke(new Action(() => { lbRain1h.Text = weatherData.rain1h + " L/h"; })); lbRain3h.Invoke(new Action(() => { lbRain3h.Text = weatherData.rain3h + " L/h"; })); - lbSnow1h.Invoke(new Action(() => { lbSnow1h.Text = weatherData.snow1h + " mm/h"; })); + if (!node1Out.snow) + lbSnow1h.Invoke(new Action(() => { lbSnow1h.Text = weatherData.snow1h + " mm/h"; })); lbSnow3h.Invoke(new Action(() => { lbSnow3h.Text = weatherData.snow3h + " mm/h"; })); } catch (Exception ignored) { } @@ -306,35 +321,53 @@ namespace Wetterstation Console.WriteLine("Entered updateFormSensors"); try { - dynamic weatherData = JsonConvert.DeserializeObject(message.ToString()); - - Console.WriteLine("---- bin in update Form Sensors -----"); - Console.WriteLine("++++++++++++ Komplette Daten anzeigen " + weatherData); - - //lbInnenTemp.Invoke(new Action(() => { lbInnenTemp.Text = weatherData.sensors[0].temperature + " °C"; })); if (weatherData[0]["client"] == WeatherstationSettings.node1Id && weatherData[0]["sensor"] == WeatherstationSettings.node1Innen) { - lbInnenTemp.Invoke(new Action(() => { lbInnenTemp.Text = weatherData[0]["temperature"] + " °C"; })); + node1In.host = weatherData[0]["client"]; + node1In.name = weatherData[0]["sensor"]; + } + if (weatherData[0]["client"] == WeatherstationSettings.node1Id && weatherData[0]["sensor"] == WeatherstationSettings.node1Aussen) + { + node1Out.host = weatherData[0]["client"]; + node1Out.name = weatherData[0]["sensor"]; + } + if (weatherData[0]["client"] == WeatherstationSettings.node1Id && weatherData[0]["sensor"] == WeatherstationSettings.node1Innen && weatherData[0]["temperature"] != null) + { + node1In.temperature = true; + if ((double)weatherData[0]["temperature"] > node1In.tempMax) node1In.tempMax = weatherData[0]["temperature"]; + if ((double)weatherData[0]["temperature"] < node1In.tempMin) node1In.tempMin = weatherData[0]["temperature"]; + lbInnenTemp.Invoke(new Action(() => { lbInnenTemp.Text = Math.Round((double)weatherData[0]["temperature"], 1) + " °C"; })); + lbTempInMin.Invoke(new Action(() => { lbTempInMin.Text = node1In.tempMin + " °C"; })); + lbTempInMax.Invoke(new Action(() => { lbTempInMax.Text = node1In.tempMax + " °C"; })); + } + if (weatherData[0]["client"] == WeatherstationSettings.node1Id && weatherData[0]["sensor"] == WeatherstationSettings.node1Innen && weatherData[0]["himidity"] != null) + { + node1In.humidity = true; lbLuftFeuchtInnen.Invoke(new Action(() => { lbLuftFeuchtInnen.Text = weatherData[0]["humidity"] + " %"; })); + } + if (weatherData[0]["client"] == WeatherstationSettings.node1Id && weatherData[0]["sensor"] == WeatherstationSettings.node1Innen && weatherData[0]["pressure"] != null) + { + node1In.pressure = true; lbLuftdruck.Invoke(new Action(() => { lbLuftdruck.Text = weatherData[0]["pressure"] + " hPa"; })); } - - - - if (weatherData[0]["client"] == WeatherstationSettings.node1Id && weatherData[0]["sensor"] == WeatherstationSettings.node1Aussen) + if (weatherData[0]["client"] == WeatherstationSettings.node1Id && weatherData[0]["sensor"] == WeatherstationSettings.node1Aussen && weatherData[0]["temperature"] != null) { - lbAussenTemp.Invoke(new Action(() => { lbAussenTemp.Text = weatherData[0]["temperature"] + " °C"; })); + node1Out.temperature = true; + if ((double)weatherData[0]["temperature"] > node1Out.tempMax) node1Out.tempMax = weatherData[0]["temperature"]; + if ((double)weatherData[0]["temperature"] < node1Out.tempMin) node1Out.tempMin = weatherData[0]["temperature"]; + lbAussenTemp.Invoke(new Action(() => { lbAussenTemp.Text = Math.Round((double)weatherData[0]["temperature"], 1) + " °C"; })); + lbTempOutMin.Invoke(new Action(() => { lbTempOutMin.Text = node1Out.tempMin + " °C"; })); + lbTempOutMax.Invoke(new Action(() => { lbTempOutMax.Text = node1Out.tempMax + " °C"; })); + } + if (weatherData[0]["client"] == WeatherstationSettings.node1Id && weatherData[0]["sensor"] == WeatherstationSettings.node1Aussen && weatherData[0]["humidity"] != null) + { + node1Out.humidity = true; + lbLuftfeuchtAussen.Invoke(new Action(() => { lbLuftfeuchtAussen.Text = weatherData[0]["humidity"] + " %"; })); } } catch (Exception ignored) { } - - - //Console.WriteLine("weatherData[\"sensors\"] => " + weatherData[0]["temperature"]); - - - } public void updateFormComplete() { diff --git a/Wetterstation/Sensor.cs b/Wetterstation/Sensor.cs new file mode 100644 index 0000000000000000000000000000000000000000..d9de0c382c976c3b93327e727560f165105b910e --- /dev/null +++ b/Wetterstation/Sensor.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Wetterstation +{ + class Sensor + { + public String host { get; set; } + public String name { get; set; } + public bool temperature { get; set; } + public bool humidity { get; set; } + public bool pressure { get; set; } + public bool co2 { get; set; } + public bool windSpeed { get; set; } + public bool windDegre { get; set; } + public bool rain { get; set; } + public bool snow { get; set; } + public double tempMin { get; set; } + public double tempMax { get; set; } + } +} diff --git a/Wetterstation/Wetterstation.csproj b/Wetterstation/Wetterstation.csproj index a7ddf17a758ae706400461c898e9e2456cddbdd0..12ea40bfbabaae40e3c60bf33b287fa8e721b265 100644 --- a/Wetterstation/Wetterstation.csproj +++ b/Wetterstation/Wetterstation.csproj @@ -91,6 +91,7 @@ <Reference Include="WindowsFormsIntegration" /> </ItemGroup> <ItemGroup> + <Compile Include="Sensor.cs" /> <Compile Include="SqliteDataAccess.cs" /> <Compile Include="SettingsModel.cs" /> <Compile Include="Form1.cs">