From f4888320163eef04792f77b154f18a77710f6bf7 Mon Sep 17 00:00:00 2001
From: Roger Petri <roger@worfelden.de>
Date: Tue, 4 Feb 2020 17:53:49 +0100
Subject: [PATCH] Senswortwerte vom Backend den entsprechenden Labels
 zugeordnet

---
 Wetterstation/Form1.Designer.cs | 18 ++++++-----
 Wetterstation/Form1.cs          | 56 +++++++++++++++++++++++++--------
 2 files changed, 53 insertions(+), 21 deletions(-)

diff --git a/Wetterstation/Form1.Designer.cs b/Wetterstation/Form1.Designer.cs
index fef9870..ffeb52e 100644
--- a/Wetterstation/Form1.Designer.cs
+++ b/Wetterstation/Form1.Designer.cs
@@ -161,7 +161,7 @@ namespace Wetterstation
             this.pictureBox1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
             this.pictureBox1.Image = global::Wetterstation.Properties.Resources.WindRose_neu;
             this.pictureBox1.Location = new System.Drawing.Point(1160, 59);
-            this.pictureBox1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
+            this.pictureBox1.Margin = new System.Windows.Forms.Padding(4);
             this.pictureBox1.Name = "pictureBox1";
             this.pictureBox1.Size = new System.Drawing.Size(120, 120);
             this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
@@ -180,6 +180,7 @@ namespace Wetterstation
             this.lbInnenTemp.Size = new System.Drawing.Size(262, 93);
             this.lbInnenTemp.TabIndex = 13;
             this.lbInnenTemp.Text = "NA C°";
+            this.lbInnenTemp.Click += new System.EventHandler(this.LbInnenTemp_Click);
             // 
             // lbAussenTemp
             // 
@@ -220,6 +221,7 @@ namespace Wetterstation
             this.lbLuftFeuchtInnen.Size = new System.Drawing.Size(180, 70);
             this.lbLuftFeuchtInnen.TabIndex = 17;
             this.lbLuftFeuchtInnen.Text = "NA %";
+            this.lbLuftFeuchtInnen.Click += new System.EventHandler(this.LbLuftFeuchtInnen_Click);
             // 
             // lbWindricht
             // 
@@ -291,7 +293,7 @@ namespace Wetterstation
             // 
             this.lbForecastImage2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(90)))), ((int)(((byte)(10)))), ((int)(((byte)(80)))), ((int)(((byte)(147)))));
             this.lbForecastImage2.Location = new System.Drawing.Point(236, 334);
-            this.lbForecastImage2.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
+            this.lbForecastImage2.Margin = new System.Windows.Forms.Padding(4);
             this.lbForecastImage2.Name = "lbForecastImage2";
             this.lbForecastImage2.Size = new System.Drawing.Size(71, 68);
             this.lbForecastImage2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
@@ -302,7 +304,7 @@ namespace Wetterstation
             // 
             this.lbForecastImage3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(90)))), ((int)(((byte)(10)))), ((int)(((byte)(80)))), ((int)(((byte)(147)))));
             this.lbForecastImage3.Location = new System.Drawing.Point(307, 334);
-            this.lbForecastImage3.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
+            this.lbForecastImage3.Margin = new System.Windows.Forms.Padding(4);
             this.lbForecastImage3.Name = "lbForecastImage3";
             this.lbForecastImage3.Size = new System.Drawing.Size(71, 68);
             this.lbForecastImage3.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
@@ -313,7 +315,7 @@ namespace Wetterstation
             // 
             this.lbForecastImage4.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(90)))), ((int)(((byte)(10)))), ((int)(((byte)(80)))), ((int)(((byte)(147)))));
             this.lbForecastImage4.Location = new System.Drawing.Point(376, 334);
-            this.lbForecastImage4.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
+            this.lbForecastImage4.Margin = new System.Windows.Forms.Padding(4);
             this.lbForecastImage4.Name = "lbForecastImage4";
             this.lbForecastImage4.Size = new System.Drawing.Size(71, 68);
             this.lbForecastImage4.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
@@ -324,7 +326,7 @@ namespace Wetterstation
             // 
             this.lbForecastImage5.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(90)))), ((int)(((byte)(10)))), ((int)(((byte)(80)))), ((int)(((byte)(147)))));
             this.lbForecastImage5.Location = new System.Drawing.Point(441, 334);
-            this.lbForecastImage5.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
+            this.lbForecastImage5.Margin = new System.Windows.Forms.Padding(4);
             this.lbForecastImage5.Name = "lbForecastImage5";
             this.lbForecastImage5.Size = new System.Drawing.Size(71, 68);
             this.lbForecastImage5.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
@@ -468,7 +470,7 @@ namespace Wetterstation
             this.lbForecastImage1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(90)))), ((int)(((byte)(10)))), ((int)(((byte)(80)))), ((int)(((byte)(147)))));
             this.lbForecastImage1.InitialImage = global::Wetterstation.Properties.Resources._01d_2x;
             this.lbForecastImage1.Location = new System.Drawing.Point(165, 334);
-            this.lbForecastImage1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
+            this.lbForecastImage1.Margin = new System.Windows.Forms.Padding(4);
             this.lbForecastImage1.Name = "lbForecastImage1";
             this.lbForecastImage1.Size = new System.Drawing.Size(71, 68);
             this.lbForecastImage1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
@@ -481,7 +483,7 @@ namespace Wetterstation
             this.btSystemKnopf.BackgroundImage = global::Wetterstation.Properties.Resources.Zahnrad12;
             this.btSystemKnopf.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
             this.btSystemKnopf.Location = new System.Drawing.Point(1291, 847);
-            this.btSystemKnopf.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
+            this.btSystemKnopf.Margin = new System.Windows.Forms.Padding(4);
             this.btSystemKnopf.Name = "btSystemKnopf";
             this.btSystemKnopf.Size = new System.Drawing.Size(40, 37);
             this.btSystemKnopf.TabIndex = 46;
@@ -716,7 +718,7 @@ namespace Wetterstation
             this.Controls.Add(this.lbHintergrund);
             this.Controls.Add(this.lbCity);
             this.DoubleBuffered = true;
-            this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
+            this.Margin = new System.Windows.Forms.Padding(4);
             this.Name = "Hintergrund";
             this.Text = "Wetterstation";
             this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Hintergrund_FormClosed);
diff --git a/Wetterstation/Form1.cs b/Wetterstation/Form1.cs
index 30a3cad..8c93f31 100644
--- a/Wetterstation/Form1.cs
+++ b/Wetterstation/Form1.cs
@@ -24,6 +24,7 @@ namespace Wetterstation
         MassueredValue humidityValue;
         MassueredValue pressureValue;
 
+
         //Variable fuer den Debugmodues
         private bool debug = false;
 
@@ -164,7 +165,7 @@ namespace Wetterstation
         {
             // Handle message received
             var message = System.Text.Encoding.Default.GetString(e.Message);
-            System.Console.WriteLine("Message received: " + message);
+            //System.Console.WriteLine("Message received: " + message);
             Console.WriteLine("With Topic: " + e.Topic);
 
             if (e.Topic.Equals(WeatherstationSettings.mqtt_topic_frontend + WeatherstationSettings.frontendId + "/weather"))
@@ -197,6 +198,7 @@ namespace Wetterstation
             //Console.WriteLine("---- und das steht in weatherData -----");
             //Console.WriteLine(weatherData);
 
+            /*
             Console.WriteLine("---- und das steht in results[0][series][0][columns] -----");
             Console.WriteLine("weatherData[\"results\"][0][\"series\"][0][\"columns\"][0] = > " + weatherData["results"][0]["series"][0]["columns"][0]);
             Console.WriteLine("weatherData[\"results\"][0][\"series\"][0][\"columns\"][1] = > " + weatherData["results"][0]["series"][0]["columns"][1]);
@@ -212,10 +214,10 @@ namespace Wetterstation
             Console.WriteLine("weatherData[\"results\"][0][\"series\"][0][\"values\"][65][2] => " + weatherData["results"][0]["series"][0]["values"][65][2]);
             Console.WriteLine("weatherData[\"results\"][0][\"series\"][0][\"values\"][65][3] => " + weatherData["results"][0]["series"][0]["values"][65][3]);
             Console.WriteLine("weatherData[\"results\"][0][\"series\"][0][\"values\"][65][4] => " + weatherData["results"][0]["series"][0]["values"][65][4]);
-            
+            */
 
 
-            Console.WriteLine(weatherData["results"][0]["series"][0]["values"][85][2]);
+            //Console.WriteLine(weatherData["results"][0]["series"][0]["values"][85][2]);
 
             //temperatureValue.dtTimestamp = weatherData["results"][0]["series"][0]["values"][1][0];
             //temperatureValue.dValue = weatherData["results"][0]["series"][0]["values"][85][2];
@@ -225,10 +227,6 @@ namespace Wetterstation
             //Console.WriteLine("Datum: " + temperatureValue.dtTimestamp + " hat Wert: " + temperatureValue.dValue);
 
             //Laufvariablen fuer For-Schleife
-            int i = 0;
-            int j = 0;
-
-
 
             //while((weatherData["results"][0]["series"][0]["columns"][0]))
             //{
@@ -237,10 +235,6 @@ namespace Wetterstation
             //}
             
                               
-            
-
-
-
             //foreach()
             //Console.WriteLine(weatherData["results"]["columns"]["values"]);
 
@@ -252,19 +246,20 @@ namespace Wetterstation
             */
         }
 
+        // momentan noch von openweathermap
         public void updateFormWeather(String message)
         {
             Console.WriteLine("Entered updateFormWeather");
             try
             {
                 dynamic weatherData = JsonConvert.DeserializeObject(message.ToString());
-                lbAussenTemp.Invoke(new Action(() => { lbAussenTemp.Text = weatherData.temp + " °C"; }));
+                //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"; }));
+                //lbLuftdruck.Invoke(new Action(() => { lbLuftdruck.Text = weatherData.pressure + " mbar"; }));         //kommt jetzt von den internen Sensoren BME280
                 pictureBox1.Invoke(new Action(() => {
                     pictureBox1.Image = RotateImage((Bitmap)global::Wetterstation.Properties.Resources.ResourceManager.GetObject("WindRose_neu"), (int)weatherData.windDeg);
                 }));
@@ -330,10 +325,35 @@ 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"; }));
+                    lbLuftFeuchtInnen.Invoke(new Action(() => { lbLuftFeuchtInnen.Text = weatherData[0]["humidity"] + " %"; }));
+                    lbLuftdruck.Invoke(new Action(() => { lbLuftdruck.Text = weatherData[0]["pressure"] + " hPa"; }));
+                }
+
+
+
+                if (weatherData[0]["client"] == WeatherstationSettings.node1Id && weatherData[0]["sensor"] == WeatherstationSettings.node1Aussen)
+                {
+                    lbAussenTemp.Invoke(new Action(() => { lbAussenTemp.Text = weatherData[0]["temperature"] + " °C"; }));
+                }
+
             }
             catch (Exception ignored) { }
+
+            
+            //Console.WriteLine("weatherData[\"sensors\"] => " + weatherData[0]["temperature"]);
+
+
+
         }
 
         public void updateFormComplete()
@@ -381,5 +401,15 @@ namespace Wetterstation
         {
 
         }
+
+        private void LbInnenTemp_Click(object sender, EventArgs e)
+        {
+
+        }
+
+        private void LbLuftFeuchtInnen_Click(object sender, EventArgs e)
+        {
+
+        }
     }
 }
-- 
GitLab