diff --git a/Wetterstation/Form1.Designer.cs b/Wetterstation/Form1.Designer.cs index 7de02f9fb2ea80a9e90fa022be14e9241ac567f2..d2544c51db4b37c25682e3e2279466e7981bbdf4 100644 --- a/Wetterstation/Form1.Designer.cs +++ b/Wetterstation/Form1.Designer.cs @@ -843,6 +843,7 @@ namespace Wetterstation this.pbTendenzPressure.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; this.pbTendenzPressure.TabIndex = 71; this.pbTendenzPressure.TabStop = false; + this.pbTendenzPressure.Visible = false; // // pictureBox2 // @@ -868,6 +869,7 @@ namespace Wetterstation this.pbTendenzTempOut.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; this.pbTendenzTempOut.TabIndex = 75; this.pbTendenzTempOut.TabStop = false; + this.pbTendenzTempOut.Visible = false; // // pbTendenzTempIn // @@ -881,6 +883,7 @@ namespace Wetterstation this.pbTendenzTempIn.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; this.pbTendenzTempIn.TabIndex = 76; this.pbTendenzTempIn.TabStop = false; + this.pbTendenzTempIn.Visible = false; // // Hintergrund // diff --git a/Wetterstation/Form1.cs b/Wetterstation/Form1.cs index 3b6138b129a17db48af8b308d2b3183fe7aea2f6..9910cb2c6aac74363fc1d17ceeaba870b0932864 100644 --- a/Wetterstation/Form1.cs +++ b/Wetterstation/Form1.cs @@ -169,7 +169,6 @@ namespace Wetterstation } 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); } @@ -242,10 +241,12 @@ namespace Wetterstation dynamic weatherData = JsonConvert.DeserializeObject(message.ToString()); if (!node1Out.temperature) { - lbAussenTemp.Invoke(new Action(() => { lbAussenTemp.Text = Math.Round((double)weatherData.temp, 1) + " °C"; })); + lbAussenTemp.Invoke(new Action(() => { lbAussenTemp.Text = weatherData.temp + " °C"; })); lbTempOutMin.Invoke(new Action(() => { lbTempOutMin.Text = weatherData.tempMin + " °C"; })); lbTempOutMax.Invoke(new Action(() => { lbTempOutMax.Text = weatherData.tempMax + " °C"; })); - owm.Temperatures = Math.Round((double)weatherData.temp, 1); + owm.Temperatures = weatherData.temp; + if (owm._temperatures.Count < 10) pbTendenzTempOut.Invoke(new Action(() => { pbTendenzTempOut.Visible = false; })); + else pbTendenzTempOut.Invoke(new Action(() => { pbTendenzTempOut.Visible = true; })); pbTendenzTempOut.Invoke(new Action(() => { pbTendenzTempOut.Image = RotateImage((Bitmap)global::Wetterstation.Properties.Resources.ResourceManager.GetObject("Tendenz"), owm.tempTendenz()); })); } if(!node1Out.humidity) @@ -264,7 +265,9 @@ namespace Wetterstation if (!node1Out.pressure && !node1In.pressure) { lbLuftdruck.Invoke(new Action(() => { lbLuftdruck.Text = weatherData.pressure + " mbar"; })); - owm.Pressures = weatherData.pressure; + owm.Pressures = (double)weatherData.pressure; + if (owm._pressures.Count < 10) pbTendenzPressure.Invoke(new Action(() => { pbTendenzPressure.Visible = false; })); + else pbTendenzPressure.Invoke(new Action(() => { pbTendenzPressure.Visible = true; })); pbTendenzPressure.Invoke(new Action(() => { pbTendenzPressure.Image = RotateImage((Bitmap)global::Wetterstation.Properties.Resources.ResourceManager.GetObject("Tendenz"), owm.pressureTendenz()); })); } if(!node1Out.rain) @@ -278,7 +281,9 @@ namespace Wetterstation } lbSnow3h.Invoke(new Action(() => { lbSnow3h.Text = weatherData.snow3h + " mm/h"; })); } - catch (Exception ignored) { } + catch (Exception ignored) { + Console.WriteLine(ignored.Message); + } } private Bitmap RotateImage(Bitmap bmp, float angle) { @@ -335,6 +340,7 @@ namespace Wetterstation Console.WriteLine(message); try { + dynamic weatherData = JsonConvert.DeserializeObject(message.ToString()); if (weatherData[0]["client"] == WeatherstationSettings.node1Id && weatherData[0]["sensor"] == WeatherstationSettings.node1Innen) { @@ -346,48 +352,56 @@ namespace Wetterstation 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) + if (weatherData[0]["client"] == node1In.host && weatherData[0]["sensor"] == node1In.name && 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"; })); + lbInnenTemp.Invoke(new Action(() => { lbInnenTemp.Text = weatherData[0]["temperature"] + " °C"; })); lbTempInMin.Invoke(new Action(() => { lbTempInMin.Text = node1In.tempMin + " °C"; })); lbTempInMax.Invoke(new Action(() => { lbTempInMax.Text = node1In.tempMax + " °C"; })); - node1In.Temperatures = weatherData[0]["temperature"]; + node1In.Temperatures = (double)weatherData[0]["temperature"]; + if (node1In._temperatures.Count < 10) pbTendenzTempIn.Invoke(new Action(() => { pbTendenzTempIn.Visible = false; })); + else pbTendenzTempIn.Invoke(new Action(() => { pbTendenzTempIn.Visible = true; })); pbTendenzTempIn.Invoke(new Action(() => { pbTendenzTempIn.Image = RotateImage((Bitmap)global::Wetterstation.Properties.Resources.ResourceManager.GetObject("Tendenz"), node1In.tempTendenz()); })); } - if (weatherData[0]["client"] == WeatherstationSettings.node1Id && weatherData[0]["sensor"] == WeatherstationSettings.node1Innen && weatherData[0]["humidity"] != null) + if (weatherData[0]["client"] == node1In.host && weatherData[0]["sensor"] == node1In.name && weatherData[0]["humidity"] != 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) + if (weatherData[0]["client"] == node1In.host && weatherData[0]["sensor"] == node1In.name && weatherData[0]["pressure"] != null) { node1In.pressure = true; lbLuftdruck.Invoke(new Action(() => { lbLuftdruck.Text = weatherData[0]["pressure"] + " hPa"; })); - node1In.Pressures = weatherData[0]["pressure"]; + node1In.Pressures = (double)weatherData[0]["pressure"]; + if (node1In._pressures.Count < 10) pbTendenzPressure.Invoke(new Action(() => { pbTendenzPressure.Visible = false; })); + else pbTendenzPressure.Invoke(new Action(() => { pbTendenzPressure.Visible = true; })); pbTendenzPressure.Invoke(new Action(() => { pbTendenzPressure.Image = RotateImage((Bitmap)global::Wetterstation.Properties.Resources.ResourceManager.GetObject("Tendenz"), node1In.pressureTendenz()); })); } - if (weatherData[0]["client"] == WeatherstationSettings.node1Id && weatherData[0]["sensor"] == WeatherstationSettings.node1Aussen && weatherData[0]["temperature"] != null) + if (weatherData[0]["client"] == node1Out.host && weatherData[0]["sensor"] == node1Out.name && weatherData[0]["temperature"] != null) { 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"; })); + lbAussenTemp.Invoke(new Action(() => { lbAussenTemp.Text = weatherData[0]["temperature"] + " °C"; })); lbTempOutMin.Invoke(new Action(() => { lbTempOutMin.Text = node1Out.tempMin + " °C"; })); lbTempOutMax.Invoke(new Action(() => { lbTempOutMax.Text = node1Out.tempMax + " °C"; })); - node1Out.Temperatures = weatherData[0]["temperature"]; + node1Out.Temperatures = (double)weatherData[0]["temperature"]; + if (node1Out._temperatures.Count < 10) pbTendenzTempOut.Invoke(new Action(() => { pbTendenzTempOut.Visible = false; })); + else pbTendenzTempOut.Invoke(new Action(() => { pbTendenzTempOut.Visible = true; })); pbTendenzTempOut.Invoke(new Action(() => { pbTendenzTempOut.Image = RotateImage((Bitmap)global::Wetterstation.Properties.Resources.ResourceManager.GetObject("Tendenz"), node1Out.tempTendenz()); })); } - if (weatherData[0]["client"] == WeatherstationSettings.node1Id && weatherData[0]["sensor"] == WeatherstationSettings.node1Aussen && weatherData[0]["humidity"] != null) + if (weatherData[0]["client"] == node1Out.host && weatherData[0]["sensor"] == node1Out.name && weatherData[0]["humidity"] != null) { node1Out.humidity = true; lbLuftfeuchtAussen.Invoke(new Action(() => { lbLuftfeuchtAussen.Text = weatherData[0]["humidity"] + " %"; })); } } - catch (Exception ignored) { } + catch (Exception ignored) { + Console.WriteLine(ignored.Message); + } } public void updateFormComplete() { diff --git a/Wetterstation/Sensor.cs b/Wetterstation/Sensor.cs index 54eb722930da0163131ba64f3ef9e7905047855c..a297b9069a3cabc607c52535b6331c205d46e0de 100644 --- a/Wetterstation/Sensor.cs +++ b/Wetterstation/Sensor.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; namespace Wetterstation { - class Sensor + public class Sensor { public String host { get; set; } public String name { get; set; } @@ -17,8 +17,8 @@ namespace Wetterstation public bool snow { get; set; } public double tempMin { get; set; } public double tempMax { get; set; } - private List<double> _temperatures; - private List<double> _pressures; + public List<double> _temperatures = new List<double>(); + public List<double> _pressures = new List<double>(); public double Temperatures { set