diff --git a/Wetterstation/Form1.Designer.cs b/Wetterstation/Form1.Designer.cs index 725fc8cecf94e31d0a10bdd285e006e052d3f028..fef98708cb433fe94c92feeb598fe1b038ed2800 100644 --- a/Wetterstation/Form1.Designer.cs +++ b/Wetterstation/Form1.Designer.cs @@ -448,6 +448,7 @@ namespace Wetterstation this.lbHintergrund.Name = "lbHintergrund"; this.lbHintergrund.Size = new System.Drawing.Size(1312, 436); this.lbHintergrund.TabIndex = 42; + this.lbHintergrund.Click += new System.EventHandler(this.LbHintergrund_Click); // // lbCity // @@ -660,6 +661,7 @@ namespace Wetterstation this.cartesianChart1.Size = new System.Drawing.Size(1309, 310); this.cartesianChart1.TabIndex = 60; this.cartesianChart1.Text = "cartesianChart1"; + this.cartesianChart1.ChildChanged += new System.EventHandler<System.Windows.Forms.Integration.ChildChangedEventArgs>(this.CartesianChart1_ChildChanged); // // Hintergrund // diff --git a/Wetterstation/Form1.cs b/Wetterstation/Form1.cs index 9bb12925c1af11ca529ff663df2b587049fabc46..e2826885970fcfd948fb7d263f7d3ebee2111e06 100644 --- a/Wetterstation/Form1.cs +++ b/Wetterstation/Form1.cs @@ -14,6 +14,19 @@ namespace Wetterstation { public partial class Hintergrund : Form { + public struct MassueredValue + { + public DateTime dtTimestamp; + public double dValue; + }; + + MassueredValue temperatureValue; + MassueredValue humidityValue; + MassueredValue pressureValue; + + //Variable fuer den Debugmodues + private bool debug = false; + private MqttClient myClient; SettingsModel WeatherstationSettings = new SettingsModel(); @@ -40,7 +53,7 @@ namespace Wetterstation new LineSeries { Title = "Temperature", - Values = new ChartValues<double> {4, 6, 5, 2, 7}, + Values = new ChartValues<double> {4, 4, 4, 4, 4}, PointGeometry = null }, new LineSeries @@ -76,19 +89,62 @@ namespace Wetterstation lbDatum.Text = DateTime.Now.ToShortDateString(); } + private void LED_Click(object sender, EventArgs e) + { + + System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Red); + System.Drawing.Graphics formGraphics; + formGraphics = this.CreateGraphics(); + formGraphics.FillEllipse(myBrush, new Rectangle(818, 238, 12, 12)); + myBrush.Dispose(); + formGraphics.Dispose(); + } + + private void Label1_Click(object sender, EventArgs e) + { + System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Red); + System.Drawing.Graphics formGraphics; + formGraphics = this.CreateGraphics(); + formGraphics.FillEllipse(myBrush, new Rectangle(872, 290, 12, 12)); + myBrush.Dispose(); + formGraphics.Dispose(); + } + + private void LED_S_Click(object sender, EventArgs e) + { + System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Red); + System.Drawing.Graphics formGraphics; + formGraphics = this.CreateGraphics(); + formGraphics.FillEllipse(myBrush, new Rectangle(818,350, 12, 12)); + myBrush.Dispose(); + formGraphics.Dispose(); + } + + private void LED_W_Click(object sender, EventArgs e) + { + System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Red); + System.Drawing.Graphics formGraphics; + formGraphics = this.CreateGraphics(); + formGraphics.FillEllipse(myBrush, new Rectangle(764, 290, 12, 12)); + myBrush.Dispose(); + formGraphics.Dispose(); + } + //MQTT connect public void mqttStart() { String topic_publish = "/wetterstation/backend/" + WeatherstationSettings.frontendId + "/"; String topic_subscribe = "/wetterstation/frontend/" + WeatherstationSettings.frontendId + "/#"; + System.Console.WriteLine("Mqtt wird gestartet ...."); // Create Client instance this.myClient = new MqttClient("mqtt.itstall.de"); // Register to message received myClient.MqttMsgPublishReceived += client_recievedMessage; - this.myClient.Connect(WeatherstationSettings.frontendId, "wetterstation", "wetterstation"); + string clientId = Guid.NewGuid().ToString(); + this.myClient.Connect("", "wetterstation", "wetterstation"); // Subscribe to topic this.myClient.Subscribe(new String[] { topic_subscribe }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE }); @@ -110,7 +166,7 @@ namespace Wetterstation var message = System.Text.Encoding.Default.GetString(e.Message); System.Console.WriteLine("Message received: " + message); Console.WriteLine("With Topic: " + e.Topic); - + if (e.Topic.Equals(WeatherstationSettings.mqtt_topic_frontend + WeatherstationSettings.frontendId + "/weather")) { this.updateFormWeather(message); @@ -123,6 +179,77 @@ namespace Wetterstation { this.updateFormSensors(message); } + else if (e.Topic.Equals(WeatherstationSettings.mqtt_topic_frontend + WeatherstationSettings.frontendId + "/graph")) + { + Console.WriteLine("e.Topic Graph " + e.Topic); + Console.WriteLine(WeatherstationSettings.mqtt_topic_frontend + WeatherstationSettings.frontendId + "/graph"); + this.updateFormChart(message); + } + + } + + public void updateFormChart(String message) + { + dynamic weatherData = JsonConvert.DeserializeObject(message.ToString()); + Console.WriteLine("---- bin in update Graph -----"); + //Console.WriteLine(message); + + //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]); + Console.WriteLine("weatherData[\"results\"][0][\"series\"][0][\"columns\"][2] = > " + weatherData["results"][0]["series"][0]["columns"][2]); + Console.WriteLine("weatherData[\"results\"][0][\"series\"][0][\"columns\"][3] = > " + weatherData["results"][0]["series"][0]["columns"][3]); + Console.WriteLine("weatherData[\"results\"][0][\"series\"][0][\"columns\"][4] = > " + weatherData["results"][0]["series"][0]["columns"][4]); + Console.WriteLine(); + + + Console.WriteLine("weatherData[\"results\"][0][\"series\"][0][\"values\"][1][0] => " + weatherData["results"][0]["series"][0]["values"][1][0]); + Console.WriteLine("weatherData[\"results\"][0][\"series\"][0][\"values\"][65][0] => " + weatherData["results"][0]["series"][0]["values"][85][0]); + Console.WriteLine("weatherData[\"results\"][0][\"series\"][0][\"values\"][65][1] => " + weatherData["results"][0]["series"][0]["values"][65][1]); + 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]); + + //temperatureValue.dtTimestamp = weatherData["results"][0]["series"][0]["values"][1][0]; + //temperatureValue.dValue = weatherData["results"][0]["series"][0]["values"][85][2]; + + + + //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])) + //{ + // Console.WriteLine("4 erwaretet: " + i); + // i++; + //} + + + + + + + //foreach() + //Console.WriteLine(weatherData["results"]["columns"]["values"]); + + /* + for(weatherData.) + { + + } + */ } public void updateFormWeather(String message) @@ -138,29 +265,10 @@ namespace Wetterstation 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"; })); - pictureBox1.Invoke(new Action(() => { - pictureBox1.Image = RotateImage((Bitmap)global::Wetterstation.Properties.Resources.ResourceManager.GetObject("WindRose_neu"), (int)weatherData.windDeg); - })); } catch (Exception ignored) { } } - private Bitmap RotateImage(Bitmap bmp, float angle) - { - float height = bmp.Height; - float width = bmp.Width; - int hypotenuse = System.Convert.ToInt32(System.Math.Floor(Math.Sqrt(height * height + width * width))); - Bitmap rotatedImage = new Bitmap(hypotenuse, hypotenuse); - using (Graphics g = Graphics.FromImage(rotatedImage)) - { - g.TranslateTransform((float)rotatedImage.Width / 2, (float)rotatedImage.Height / 2); //set the rotation point as the center into the matrix - g.RotateTransform(angle); //rotate - g.TranslateTransform(-(float)rotatedImage.Width / 2, -(float)rotatedImage.Height / 2); //restore rotation point into the matrix - g.DrawImage(bmp, (hypotenuse - width) / 2, (hypotenuse - height) / 2, width, height); - } - return rotatedImage; - } - public void updateFormForecast(String message) { Console.WriteLine("Entered updateFormForecast"); @@ -203,7 +311,7 @@ namespace Wetterstation try { dynamic weatherData = JsonConvert.DeserializeObject(message.ToString()); - lbInnenTemp.Invoke(new Action(() => { lbInnenTemp.Text = weatherData.sensors[0].temperature + " °C"; })); + //lbInnenTemp.Invoke(new Action(() => { lbInnenTemp.Text = weatherData.sensors[0].temperature + " °C"; })); } catch (Exception ignored) { } } @@ -243,5 +351,15 @@ namespace Wetterstation this.myClient.Disconnect(); Application.Exit(); } + + private void CartesianChart1_ChildChanged(object sender, System.Windows.Forms.Integration.ChildChangedEventArgs e) + { + + } + + private void LbHintergrund_Click(object sender, EventArgs e) + { + + } } } diff --git a/Wetterstation/Settings.Designer.cs b/Wetterstation/Settings.Designer.cs index 8f437302dceeeecdb295885b03e08ecce86fb608..89abaf1400375815e19fcab6e7a5172885f92ba1 100644 --- a/Wetterstation/Settings.Designer.cs +++ b/Wetterstation/Settings.Designer.cs @@ -69,6 +69,7 @@ this.tbHost.Name = "tbHost"; this.tbHost.Size = new System.Drawing.Size(250, 25); this.tbHost.TabIndex = 1; + this.tbHost.TextChanged += new System.EventHandler(this.TbHost_TextChanged); // // tbPort //