Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
Frontend
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Klaus Merzbach
Frontend
Commits
247a3f85
Commit
247a3f85
authored
5 years ago
by
Dennis Eisold
Browse files
Options
Downloads
Patches
Plain Diff
Added next forecast closes #11
parent
a3ab16f5
No related branches found
No related tags found
No related merge requests found
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Wetterstation/Form1.Designer.cs
+415
-35
415 additions, 35 deletions
Wetterstation/Form1.Designer.cs
Wetterstation/Form1.cs
+44
-9
44 additions, 9 deletions
Wetterstation/Form1.cs
with
459 additions
and
44 deletions
Wetterstation/Form1.Designer.cs
+
415
−
35
View file @
247a3f85
This diff is collapsed.
Click to expand it.
Wetterstation/Form1.cs
+
44
−
9
View file @
247a3f85
...
...
@@ -122,7 +122,7 @@ namespace Wetterstation
lbUhr
.
Text
=
DateTime
.
Now
.
ToLongTimeString
();
lbDatum
.
Text
=
DateTime
.
Now
.
ToShortDateString
();
}
//MQTT connect
//
MQTT connect
public
void
mqttStart
()
{
String
topic_publish
=
"/wetterstation/backend/"
+
WeatherstationSettings
.
frontendId
+
"/"
;
...
...
@@ -143,6 +143,7 @@ namespace Wetterstation
this
.
myClient
.
Publish
(
topic_publish
,
Encoding
.
UTF8
.
GetBytes
(
"Request_frontend"
));
}
// Send message per MQTT
public
void
msgPublish
(
String
topic
,
String
message
)
{
Console
.
Write
(
"Sending via MQTT: "
);
...
...
@@ -150,6 +151,7 @@ namespace Wetterstation
Console
.
WriteLine
(
"Message: "
+
message
);
this
.
myClient
.
Publish
(
topic
,
Encoding
.
UTF8
.
GetBytes
(
message
));
}
// Got message from MQTT
private
void
client_recievedMessage
(
object
sender
,
MqttMsgPublishEventArgs
e
)
{
// Handle message received
...
...
@@ -163,6 +165,10 @@ namespace Wetterstation
{
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"
))
{
this
.
updateFormSensors
(
message
);
...
...
@@ -174,6 +180,7 @@ namespace Wetterstation
}
}
// Update graph on frontend
public
void
updateFormChart
(
String
message
)
{
double
temp
;
...
...
@@ -230,8 +237,7 @@ namespace Wetterstation
}
}
}
// momentan noch von openweathermap
// Update general weather objects on frontend
public
void
updateFormWeather
(
String
message
)
{
Console
.
WriteLine
(
"Entered updateFormWeather"
);
...
...
@@ -276,19 +282,20 @@ namespace Wetterstation
}
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
)
{
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
)
{
Console
.
WriteLine
(
ignored
.
Message
);
}
}
// Rotate an image
private
Bitmap
RotateImage
(
Bitmap
bmp
,
float
angle
)
{
float
height
=
bmp
.
Height
;
...
...
@@ -304,13 +311,15 @@ namespace Wetterstation
}
return
rotatedImage
;
}
// Update forecast images
public
void
updateFormForecast
(
String
message
)
{
Console
.
WriteLine
(
"Entered updateFormForecast"
);
try
{
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"
;
}));
lbForecastDay1
.
Invoke
(
new
Action
(()
=>
{
lbForecastDay1
.
Text
=
getDayFromDateString
(
weatherData
[
0
].
from
.
ToString
());
}));
...
...
@@ -319,7 +328,7 @@ namespace Wetterstation
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"
);
}));
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
());
}));
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
}
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
)
{
DateTime
dt
=
DateTime
.
ParseExact
(
strDate
,
"yyyy-MM-dd HH:mm:ss"
,
CultureInfo
.
InvariantCulture
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment