Skip to content
Snippets Groups Projects
Commit 9c3d1715 authored by Dennis Eisold's avatar Dennis Eisold
Browse files

Merge branch 'master' into 'master'

# Conflicts:
#   Wetterstation/Form1.Designer.cs
parents e7327000 8cb16e1e
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
...@@ -122,7 +122,7 @@ namespace Wetterstation ...@@ -122,7 +122,7 @@ namespace Wetterstation
lbUhr.Text = DateTime.Now.ToLongTimeString(); lbUhr.Text = DateTime.Now.ToLongTimeString();
lbDatum.Text = DateTime.Now.ToShortDateString(); lbDatum.Text = DateTime.Now.ToShortDateString();
} }
//MQTT connect // MQTT connect
public void mqttStart() public void mqttStart()
{ {
String topic_publish = "/wetterstation/backend/" + WeatherstationSettings.frontendId + "/"; String topic_publish = "/wetterstation/backend/" + WeatherstationSettings.frontendId + "/";
...@@ -143,6 +143,7 @@ namespace Wetterstation ...@@ -143,6 +143,7 @@ namespace Wetterstation
this.myClient.Publish(topic_publish, Encoding.UTF8.GetBytes("Request_frontend")); this.myClient.Publish(topic_publish, Encoding.UTF8.GetBytes("Request_frontend"));
} }
// Send message per MQTT
public void msgPublish(String topic, String message) public void msgPublish(String topic, String message)
{ {
Console.Write("Sending via MQTT: "); Console.Write("Sending via MQTT: ");
...@@ -150,6 +151,7 @@ namespace Wetterstation ...@@ -150,6 +151,7 @@ namespace Wetterstation
Console.WriteLine("Message: " + message); Console.WriteLine("Message: " + message);
this.myClient.Publish(topic, Encoding.UTF8.GetBytes(message)); this.myClient.Publish(topic, Encoding.UTF8.GetBytes(message));
} }
// Got message from MQTT
private void client_recievedMessage(object sender, MqttMsgPublishEventArgs e) private void client_recievedMessage(object sender, MqttMsgPublishEventArgs e)
{ {
// Handle message received // Handle message received
...@@ -163,6 +165,10 @@ namespace Wetterstation ...@@ -163,6 +165,10 @@ namespace Wetterstation
{ {
this.updateFormForecast(message); this.updateFormForecast(message);
} }
else if (e.Topic.Equals(WeatherstationSettings.mqtt_topic_frontend + WeatherstationSettings.frontendId + "/forecastNext"))
{
this.updateFormForecastNext(message);
}
else if (e.Topic.Equals(WeatherstationSettings.mqtt_topic_frontend + WeatherstationSettings.frontendId + "/sensors")) else if (e.Topic.Equals(WeatherstationSettings.mqtt_topic_frontend + WeatherstationSettings.frontendId + "/sensors"))
{ {
this.updateFormSensors(message); this.updateFormSensors(message);
...@@ -174,6 +180,7 @@ namespace Wetterstation ...@@ -174,6 +180,7 @@ namespace Wetterstation
} }
} }
// Update graph on frontend
public void updateFormChart(String message) public void updateFormChart(String message)
{ {
double temp; double temp;
...@@ -230,8 +237,7 @@ namespace Wetterstation ...@@ -230,8 +237,7 @@ namespace Wetterstation
} }
} }
} }
// Update general weather objects on frontend
// momentan noch von openweathermap
public void updateFormWeather(String message) public void updateFormWeather(String message)
{ {
Console.WriteLine("Entered updateFormWeather"); Console.WriteLine("Entered updateFormWeather");
...@@ -276,19 +282,20 @@ namespace Wetterstation ...@@ -276,19 +282,20 @@ namespace Wetterstation
} }
if(!node1Out.rain) if(!node1Out.rain)
{ {
lbRain1h.Invoke(new Action(() => { lbRain1h.Text = weatherData.rain1h + " L/h"; })); lbRain1h.Invoke(new Action(() => { lbRain1h.Text = weatherData.rain1h + " mm"; }));
} }
lbRain3h.Invoke(new Action(() => { lbRain3h.Text = weatherData.rain3h + " L/h"; })); lbRain3h.Invoke(new Action(() => { lbRain3h.Text = weatherData.rain3h + " mm"; }));
if (!node1Out.snow) if (!node1Out.snow)
{ {
lbSnow1h.Invoke(new Action(() => { lbSnow1h.Text = weatherData.snow1h + " mm/h"; })); lbSnow1h.Invoke(new Action(() => { lbSnow1h.Text = weatherData.snow1h + " mm"; }));
} }
lbSnow3h.Invoke(new Action(() => { lbSnow3h.Text = weatherData.snow3h + " mm/h"; })); lbSnow3h.Invoke(new Action(() => { lbSnow3h.Text = weatherData.snow3h + " mm"; }));
} }
catch (Exception ignored) { catch (Exception ignored) {
Console.WriteLine(ignored.Message); Console.WriteLine(ignored.Message);
} }
} }
// Rotate an image
private Bitmap RotateImage(Bitmap bmp, float angle) private Bitmap RotateImage(Bitmap bmp, float angle)
{ {
float height = bmp.Height; float height = bmp.Height;
...@@ -304,13 +311,15 @@ namespace Wetterstation ...@@ -304,13 +311,15 @@ namespace Wetterstation
} }
return rotatedImage; return rotatedImage;
} }
// Update forecast images
public void updateFormForecast(String message) public void updateFormForecast(String message)
{ {
Console.WriteLine("Entered updateFormForecast"); Console.WriteLine("Entered updateFormForecast");
try try
{ {
dynamic weatherData = JsonConvert.DeserializeObject(message.ToString()); dynamic weatherData = JsonConvert.DeserializeObject(message.ToString());
if(weatherData[0].icon1 != null) lbForecastImage1.Invoke(new Action(() => { lbForecastImage1.Image = global::Wetterstation.Properties.Resources.ResourceManager.GetObject("_" + weatherData[0].icon1 + "_2x"); }));
if (weatherData[0].icon1 != null) lbForecastImage1.Invoke(new Action(() => { lbForecastImage1.Image = global::Wetterstation.Properties.Resources.ResourceManager.GetObject("_" + weatherData[0].icon1 + "_2x"); }));
lbForecastTemp1.Invoke(new Action(() => { lbForecastTemp1.Text = weatherData[0].temp + " °C"; })); lbForecastTemp1.Invoke(new Action(() => { lbForecastTemp1.Text = weatherData[0].temp + " °C"; }));
lbForecastDay1.Invoke(new Action(() => { lbForecastDay1.Text = getDayFromDateString(weatherData[0].from.ToString()); })); lbForecastDay1.Invoke(new Action(() => { lbForecastDay1.Text = getDayFromDateString(weatherData[0].from.ToString()); }));
...@@ -319,7 +328,7 @@ namespace Wetterstation ...@@ -319,7 +328,7 @@ namespace Wetterstation
lbForecastDay2.Invoke(new Action(() => { lbForecastDay2.Text = getDayFromDateString(weatherData[1].from.ToString()); })); lbForecastDay2.Invoke(new Action(() => { lbForecastDay2.Text = getDayFromDateString(weatherData[1].from.ToString()); }));
if (weatherData[2].icon1 != null) lbForecastImage3.Invoke(new Action(() => { lbForecastImage3.Image = global::Wetterstation.Properties.Resources.ResourceManager.GetObject("_" + weatherData[2].icon1 + "_2x"); })); if (weatherData[2].icon1 != null) lbForecastImage3.Invoke(new Action(() => { lbForecastImage3.Image = global::Wetterstation.Properties.Resources.ResourceManager.GetObject("_" + weatherData[2].icon1 + "_2x"); }));
lbForecastTemp3.Invoke(new Action(() => { lbForecastTemp3.Text = weatherData[2].temp + " °C"; }));lbForecastDay1.Invoke(new Action(() => { lbForecastDay1.Text = getDayFromDateString(weatherData[0].from.ToString()); })); lbForecastTemp3.Invoke(new Action(() => { lbForecastTemp3.Text = weatherData[2].temp + " °C"; })); lbForecastDay1.Invoke(new Action(() => { lbForecastDay1.Text = getDayFromDateString(weatherData[0].from.ToString()); }));
lbForecastDay3.Invoke(new Action(() => { lbForecastDay3.Text = getDayFromDateString(weatherData[2].from.ToString()); })); lbForecastDay3.Invoke(new Action(() => { lbForecastDay3.Text = getDayFromDateString(weatherData[2].from.ToString()); }));
if (weatherData[3].icon1 != null) lbForecastImage4.Invoke(new Action(() => { lbForecastImage4.Image = global::Wetterstation.Properties.Resources.ResourceManager.GetObject("_" + weatherData[3].icon1 + "_2x"); })); if (weatherData[3].icon1 != null) lbForecastImage4.Invoke(new Action(() => { lbForecastImage4.Image = global::Wetterstation.Properties.Resources.ResourceManager.GetObject("_" + weatherData[3].icon1 + "_2x"); }));
...@@ -332,6 +341,32 @@ namespace Wetterstation ...@@ -332,6 +341,32 @@ namespace Wetterstation
} }
catch (Exception ignored) { } catch (Exception ignored) { }
} }
// Update next forecast
public void updateFormForecastNext(String message)
{
Console.WriteLine("Entered updateFormForecastNext");
try
{
dynamic weatherData = JsonConvert.DeserializeObject(message.ToString());
if (weatherData.icon1 != null) pbForecastNext.Invoke(new Action(() => { pbForecastNext.Image = global::Wetterstation.Properties.Resources.ResourceManager.GetObject("_" + weatherData.icon1 + "_2x"); }));
lbForecastNextFrom.Invoke(new Action(() => { lbForecastNextFrom.Text = getTimeFromDateString(weatherData.from.ToString()); }));
lbForecastNextClouds.Invoke(new Action(() => { lbForecastNextClouds.Text = weatherData.clouds; }));
lbForecastNextHumidity.Invoke(new Action(() => { lbForecastNextHumidity.Text = weatherData.humidity; }));
lbForecastNextPressure.Invoke(new Action(() => { lbForecastNextPressure.Text = weatherData.pressure; }));
lbForecastNextRain.Invoke(new Action(() => { lbForecastNextRain.Text = weatherData.rain3h; }));
lbForecastNextSnow.Invoke(new Action(() => { lbForecastNextSnow.Text = weatherData.snow3h; }));
lbForecastNextTemp.Invoke(new Action(() => { lbForecastNextTemp.Text = weatherData.temp; }));
lbForecastNextWindSpeed.Invoke(new Action(() => { lbForecastNextWindSpeed.Text = weatherData.windSpeed; }));
}
catch (Exception ignored) { }
}
public String getTimeFromDateString(String strDate)
{
DateTime dt = DateTime.ParseExact(strDate, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
CultureInfo culture = new CultureInfo("de-DE");
return dt.ToString("HH:mm");
}
public String getDayFromDateString(String strDate) public String getDayFromDateString(String strDate)
{ {
DateTime dt = DateTime.ParseExact(strDate, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture); DateTime dt = DateTime.ParseExact(strDate, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
......
...@@ -78,7 +78,7 @@ namespace Wetterstation ...@@ -78,7 +78,7 @@ namespace Wetterstation
oldTemp = temp; oldTemp = temp;
} }
} }
if ((up > 5 || down > 5) && _temperatures.Count == 10) if ((up > 2 || down > 2) && _temperatures.Count == 10)
{ {
if (up > down) return 180; if (up > down) return 180;
else if (down > up) return 0; else if (down > up) return 0;
...@@ -112,7 +112,7 @@ namespace Wetterstation ...@@ -112,7 +112,7 @@ namespace Wetterstation
} }
} }
if ((up > 5 || down > 5) && _pressures.Count == 10) { if ((up > 2 || down > 2) && _pressures.Count == 10) {
if (up > down) return 180; if (up > down) return 180;
else if (down > up) return 0; else if (down > up) return 0;
else return -1; else return -1;
...@@ -144,7 +144,7 @@ namespace Wetterstation ...@@ -144,7 +144,7 @@ namespace Wetterstation
oldHumidity = humidity; oldHumidity = humidity;
} }
} }
if ((up > 5 || down > 5) && _humiditys.Count == 10) if ((up > 2 || down > 2) && _humiditys.Count == 10)
{ {
if (up > down) return 180; if (up > down) return 180;
else if (down > up) return 0; else if (down > up) return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment