[NF] First Release
[NF] Finish Switcher
This commit is contained in:
parent
39c0ab4e3c
commit
d21ded9f33
@ -64,6 +64,8 @@
|
||||
<Compile Include="Tracings\ATracings.cs" />
|
||||
<Compile Include="Tracings\Graph.cs" />
|
||||
<Compile Include="Tracings\Meter.cs" />
|
||||
<Compile Include="Tracings\PowerMeter.cs" />
|
||||
<Compile Include="Tracings\Switcher.cs" />
|
||||
<EmbeddedResource Include="Form1.resx">
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
|
6
Mqtt-Dashboard/Form1.Designer.cs
generated
6
Mqtt-Dashboard/Form1.Designer.cs
generated
@ -29,7 +29,7 @@
|
||||
//
|
||||
// statusStrip1
|
||||
//
|
||||
this.statusStrip1.Location = new System.Drawing.Point(0, 304);
|
||||
this.statusStrip1.Location = new System.Drawing.Point(0, 370);
|
||||
this.statusStrip1.Name = "statusStrip1";
|
||||
this.statusStrip1.Size = new System.Drawing.Size(843, 22);
|
||||
this.statusStrip1.TabIndex = 0;
|
||||
@ -39,14 +39,14 @@
|
||||
//
|
||||
this.flowLayoutPanel2.Location = new System.Drawing.Point(12, 12);
|
||||
this.flowLayoutPanel2.Name = "flowLayoutPanel2";
|
||||
this.flowLayoutPanel2.Size = new System.Drawing.Size(819, 289);
|
||||
this.flowLayoutPanel2.Size = new System.Drawing.Size(819, 355);
|
||||
this.flowLayoutPanel2.TabIndex = 3;
|
||||
//
|
||||
// Dashboard
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(843, 326);
|
||||
this.ClientSize = new System.Drawing.Size(843, 392);
|
||||
this.Controls.Add(this.flowLayoutPanel2);
|
||||
this.Controls.Add(this.statusStrip1);
|
||||
this.Name = "Dashboard";
|
||||
|
@ -7,6 +7,7 @@ using Dashboard.Tracings;
|
||||
using BlubbFish.Utils;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Dashboard.tracings;
|
||||
|
||||
namespace Dashboard {
|
||||
public partial class Dashboard : Form {
|
||||
@ -24,11 +25,17 @@ namespace Dashboard {
|
||||
this.updateThread.Start();
|
||||
|
||||
this.FormClosed += this.Dashboard_FormClosed;
|
||||
this.SizeChanged += this.Dashboard_SizeChanged;
|
||||
|
||||
Mqtt.Instance.MessageIncomming += this.Instance_MessageIncomming;
|
||||
}
|
||||
|
||||
private void GenerateSensors() {
|
||||
private void Dashboard_SizeChanged(Object sender, EventArgs e) {
|
||||
this.flowLayoutPanel2.Size = new System.Drawing.Size(this.Size.Width - 40, this.Size.Width - 76);
|
||||
//this.Size.Height
|
||||
}
|
||||
|
||||
private void GenerateSensors() {
|
||||
InIReader ini = InIReader.GetInstance("sensor.ini");
|
||||
List<String> sensorini = ini.GetSections();
|
||||
foreach(String sensor in sensorini) {
|
||||
@ -47,10 +54,11 @@ namespace Dashboard {
|
||||
foreach(String tracing in tracingini) {
|
||||
ATracings t;
|
||||
switch(ini.GetValue(tracing, "type").ToLower()) {
|
||||
case "graph": t = new Graph(this.sensors[ini.GetValue(tracing, "sensor").ToLower()],ini.GetSection(tracing)); break;
|
||||
case "meter": t = new Meter(this.sensors[ini.GetValue(tracing, "sensor").ToLower()], ini.GetSection(tracing)); break;
|
||||
default:
|
||||
throw new ArgumentException("tracings.ini: " + tracing + " section has a missconfiguration in type");
|
||||
case "graph": t = new Graph(this.sensors[ini.GetValue(tracing, "sensor").ToLower()],ini.GetSection(tracing)); break;
|
||||
case "meter": t = new Meter(this.sensors[ini.GetValue(tracing, "sensor").ToLower()], ini.GetSection(tracing)); break;
|
||||
case "powermeter": t = new PowerMeter(this.sensors[ini.GetValue(tracing, "sensor").ToLower()], ini.GetSection(tracing)); break;
|
||||
case "switcher": t = new Switcher(this.sensors[ini.GetValue(tracing, "sensor").ToLower()], ini.GetSection(tracing)); break;
|
||||
default: throw new ArgumentException("tracings.ini: " + tracing + " section has a missconfiguration in type");
|
||||
}
|
||||
this.flowLayoutPanel2.Controls.Add(t.GetPanel());
|
||||
}
|
||||
|
@ -57,5 +57,9 @@ namespace Dashboard.Sensor {
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
internal virtual void SetBool(Boolean v) {
|
||||
Mqtt.Instance.Send(this.topic + "/set", v ? "on" : "off");
|
||||
}
|
||||
}
|
||||
}
|
@ -7,18 +7,22 @@ using System.Globalization;
|
||||
|
||||
namespace Dashboard.Tracings {
|
||||
class Meter : ATracings {
|
||||
private Int32 DisplayItems;
|
||||
private Queue<Single> DisplayAverage = new Queue<Single>();
|
||||
private String DisplayUnit;
|
||||
private Label label1;
|
||||
private Label label2;
|
||||
protected Int32 DisplayItems;
|
||||
protected Queue<Single> DisplayAverage = new Queue<Single>();
|
||||
protected Label label1;
|
||||
protected Label label2;
|
||||
|
||||
public Meter(ASensor sensor, Dictionary<String, String> settings) : base(sensor, settings) {
|
||||
this.DisplayUnit = (settings.Keys.Contains("unit")) ? settings["unit"] : "";
|
||||
this.DisplayItems = (settings.Keys.Contains("items")) ? Int32.Parse(settings["items"]) : 1000;
|
||||
|
||||
this.label1 = new Label();
|
||||
this.label2 = new Label();
|
||||
}
|
||||
public override Panel GetPanel() {
|
||||
Panel panel = new Panel();
|
||||
Panel panel = new Panel() {
|
||||
BorderStyle = BorderStyle.FixedSingle,
|
||||
Size = new System.Drawing.Size(200, 100)
|
||||
};
|
||||
|
||||
this.label1 = new Label() {
|
||||
Font = new System.Drawing.Font("Lucida Sans Typewriter", 27.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((Byte)(0))),
|
||||
@ -27,6 +31,7 @@ namespace Dashboard.Tracings {
|
||||
Text = "",
|
||||
TextAlign = System.Drawing.ContentAlignment.TopCenter
|
||||
};
|
||||
panel.Controls.Add(this.label1);
|
||||
|
||||
this.label2 = new Label() {
|
||||
AutoSize = true,
|
||||
@ -34,11 +39,9 @@ namespace Dashboard.Tracings {
|
||||
Size = new System.Drawing.Size(96, 13),
|
||||
Text = ""
|
||||
};
|
||||
|
||||
panel.BorderStyle = BorderStyle.FixedSingle;
|
||||
panel.Controls.Add(this.label2);
|
||||
panel.Controls.Add(this.label1);
|
||||
panel.Size = new System.Drawing.Size(200, 100);
|
||||
|
||||
|
||||
return panel;
|
||||
}
|
||||
protected override void SensorUpdate(Object sender, EventArgs e) {
|
||||
@ -53,10 +56,10 @@ namespace Dashboard.Tracings {
|
||||
}
|
||||
Single average = this.DisplayAverage.Sum() / this.DisplayAverage.Count();
|
||||
this.label1.BeginInvoke((MethodInvoker)delegate {
|
||||
this.label1.Text = value+" "+this.DisplayUnit;
|
||||
this.label1.Text = value;
|
||||
});
|
||||
this.label2.BeginInvoke((MethodInvoker)delegate {
|
||||
this.label2.Text = "Durchschnitt: " + Math.Round(average, 2) + " " + this.DisplayUnit;
|
||||
this.label2.Text = "Durchschnitt: " + Math.Round(average, 2);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
44
Mqtt-Dashboard/Tracings/PowerMeter.cs
Normal file
44
Mqtt-Dashboard/Tracings/PowerMeter.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Dashboard.Sensor;
|
||||
|
||||
namespace Dashboard.Tracings {
|
||||
class PowerMeter : Meter {
|
||||
public PowerMeter(ASensor sensor, Dictionary<String, String> settings) : base(sensor, settings) {
|
||||
}
|
||||
protected override void SensorUpdate(Object sender, EventArgs e) {
|
||||
String value = "";
|
||||
switch (this.sensor.Datatypes) {
|
||||
case ASensor.Types.Bool:
|
||||
this.DisplayAverage.Enqueue((this.sensor.GetBool) ? 1 : 0);
|
||||
value = this.sensor.GetBool.ToString(new CultureInfo("de-DE"));
|
||||
break;
|
||||
case ASensor.Types.Int:
|
||||
this.DisplayAverage.Enqueue(this.sensor.GetInt);
|
||||
value = this.sensor.GetInt.ToString();
|
||||
break;
|
||||
case ASensor.Types.Float:
|
||||
this.DisplayAverage.Enqueue(this.sensor.GetFloat);
|
||||
value = this.sensor.GetFloat.ToString(new CultureInfo("de-DE"));
|
||||
break;
|
||||
}
|
||||
if (this.DisplayAverage.Count > this.DisplayItems) {
|
||||
this.DisplayAverage.Dequeue();
|
||||
}
|
||||
Single average = this.DisplayAverage.Sum() / this.DisplayAverage.Count();
|
||||
try {
|
||||
this.label1.BeginInvoke((MethodInvoker)delegate {
|
||||
this.label1.Text = value + " W";
|
||||
});
|
||||
this.label2.BeginInvoke((MethodInvoker)delegate {
|
||||
this.label2.Text = "Durchschnitt: " + Math.Round(average, 2) + " W";
|
||||
});
|
||||
} catch (Exception) { }
|
||||
}
|
||||
}
|
||||
}
|
81
Mqtt-Dashboard/Tracings/Switcher.cs
Normal file
81
Mqtt-Dashboard/Tracings/Switcher.cs
Normal file
@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Windows.Forms;
|
||||
using Dashboard.Connector;
|
||||
using Dashboard.Sensor;
|
||||
using Dashboard.Tracings;
|
||||
|
||||
namespace Dashboard.tracings {
|
||||
class Switcher : ATracings {
|
||||
private Label label;
|
||||
private Button button1;
|
||||
private Button button2;
|
||||
|
||||
public Switcher(ASensor sensor, Dictionary<System.String, System.String> settings) : base(sensor, settings) {
|
||||
this.label = new Label();
|
||||
this.button1 = new Button();
|
||||
this.button2 = new Button();
|
||||
}
|
||||
|
||||
public override Panel GetPanel() {
|
||||
Panel panel = new Panel() {
|
||||
BorderStyle = BorderStyle.FixedSingle,
|
||||
Size = new System.Drawing.Size(200, 100)
|
||||
};
|
||||
|
||||
this.label = new Label() {
|
||||
AutoSize = true,
|
||||
Location = new System.Drawing.Point(69, 16),
|
||||
Size = new System.Drawing.Size(35, 13),
|
||||
Text = ""
|
||||
};
|
||||
panel.Controls.Add(this.label);
|
||||
|
||||
this.button1 = new Button() {
|
||||
BackColor = System.Drawing.Color.FromArgb(0, 192, 0),
|
||||
Location = new System.Drawing.Point(94, 67),
|
||||
Name = "on",
|
||||
Size = new System.Drawing.Size(45, 23),
|
||||
Text = "ON",
|
||||
UseVisualStyleBackColor = false
|
||||
};
|
||||
this.button1.Click += this.ButtonClicker;
|
||||
panel.Controls.Add(this.button1);
|
||||
|
||||
this.button2 = new Button() {
|
||||
BackColor = System.Drawing.Color.Red,
|
||||
Location = new System.Drawing.Point(145, 67),
|
||||
Name = "off",
|
||||
Size = new System.Drawing.Size(45, 23),
|
||||
Text = "OFF",
|
||||
UseVisualStyleBackColor = false
|
||||
};
|
||||
this.button2.Click += this.ButtonClicker;
|
||||
panel.Controls.Add(this.button2);
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
private void ButtonClicker(Object sender, EventArgs e) {
|
||||
Button b = (Button)sender;
|
||||
if (b.Name == "on") {
|
||||
this.sensor.SetBool(true);
|
||||
} else if(b.Name == "off") {
|
||||
this.sensor.SetBool(false);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SensorUpdate(Object sender, EventArgs e) {
|
||||
this.label.BeginInvoke((MethodInvoker)delegate {
|
||||
this.label.Text = this.sensor.GetBool?"Eingeschaltet":"Ausgeschaltet";
|
||||
});
|
||||
this.button1.BeginInvoke((MethodInvoker)delegate {
|
||||
this.button1.Enabled = !this.sensor.GetBool;
|
||||
});
|
||||
this.button2.BeginInvoke((MethodInvoker)delegate {
|
||||
this.button2.Enabled = this.sensor.GetBool;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
BIN
Mqtt-Dashboard/bin/Release/Dashboard.exe
Normal file
BIN
Mqtt-Dashboard/bin/Release/Dashboard.exe
Normal file
Binary file not shown.
BIN
Mqtt-Dashboard/bin/Release/M2Mqtt.Net.dll
Normal file
BIN
Mqtt-Dashboard/bin/Release/M2Mqtt.Net.dll
Normal file
Binary file not shown.
BIN
Mqtt-Dashboard/bin/Release/Utils.dll
Normal file
BIN
Mqtt-Dashboard/bin/Release/Utils.dll
Normal file
Binary file not shown.
24
Mqtt-Dashboard/bin/Release/sensor.ini
Normal file
24
Mqtt-Dashboard/bin/Release/sensor.ini
Normal file
@ -0,0 +1,24 @@
|
||||
[Thinkpad]
|
||||
topic=zway/wohnzimmer/thinkpad/power
|
||||
type=Power
|
||||
polling=10
|
||||
|
||||
[Tv]
|
||||
topic=zway/wohnzimmer/tV/power
|
||||
type=Power
|
||||
polling=10
|
||||
|
||||
[Kühlschrank]
|
||||
topic=zway/küche/kuehlschrank/power
|
||||
type=Power
|
||||
polling=10
|
||||
|
||||
[TvSW]
|
||||
topic=zway/wohnzimmer/tV/switch
|
||||
type=switch
|
||||
polling=10
|
||||
|
||||
;[Ventilator]
|
||||
;topic=zway/power/test/wVentilator
|
||||
;type=Power
|
||||
;polling=10
|
2
Mqtt-Dashboard/bin/Release/settings.ini
Normal file
2
Mqtt-Dashboard/bin/Release/settings.ini
Normal file
@ -0,0 +1,2 @@
|
||||
[general]
|
||||
mqtt-server=localhost
|
45
Mqtt-Dashboard/bin/Release/tracings.ini
Normal file
45
Mqtt-Dashboard/bin/Release/tracings.ini
Normal file
@ -0,0 +1,45 @@
|
||||
[ThinkpadMeter]
|
||||
sensor=Thinkpad
|
||||
type=PowerMeter
|
||||
items=100
|
||||
|
||||
[TvMeter]
|
||||
sensor=Tv
|
||||
type=PowerMeter
|
||||
items=100
|
||||
|
||||
[KühlschrankrMeter]
|
||||
sensor=Kühlschrank
|
||||
type=PowerMeter
|
||||
items=100
|
||||
|
||||
[ThinkpadGraph]
|
||||
sensor=Thinkpad
|
||||
type=Graph
|
||||
items=100
|
||||
|
||||
[TvGraph]
|
||||
sensor=Tv
|
||||
type=Graph
|
||||
items=100
|
||||
|
||||
[KühlschrankGraph]
|
||||
sensor=Kühlschrank
|
||||
type=Graph
|
||||
items=100
|
||||
|
||||
[TvSWMeter]
|
||||
sensor=TvSW
|
||||
type=Switcher
|
||||
items=100
|
||||
|
||||
;[VentilatorGraph]
|
||||
;sensor=Ventilator
|
||||
;type=Graph
|
||||
;items=100
|
||||
|
||||
;[VentilatorMeter]
|
||||
;sensor=Ventilator
|
||||
;type=Meter
|
||||
;unit=W
|
||||
;items=100
|
@ -1,19 +1,24 @@
|
||||
;[Thinkpad]
|
||||
;topic=zway/wohnzimmer/thinkpad/power
|
||||
;type=Power
|
||||
;polling=10
|
||||
|
||||
;[Tv]
|
||||
;topic=zway/wohnzimmer/tV/power
|
||||
;type=Power
|
||||
;polling=10
|
||||
|
||||
;[Kühlschrank]
|
||||
;topic=zway/küche/kuehlschrank/power
|
||||
;type=Power
|
||||
;polling=10
|
||||
|
||||
[Ventilator]
|
||||
topic=zway/power/test/wVentilator
|
||||
[Thinkpad]
|
||||
topic=zway/wohnzimmer/thinkpad/power
|
||||
type=Power
|
||||
polling=10
|
||||
polling=10
|
||||
|
||||
[Tv]
|
||||
topic=zway/wohnzimmer/tV/power
|
||||
type=Power
|
||||
polling=10
|
||||
|
||||
[Kühlschrank]
|
||||
topic=zway/küche/kuehlschrank/power
|
||||
type=Power
|
||||
polling=10
|
||||
|
||||
[TvSW]
|
||||
topic=zway/wohnzimmer/tV/switch
|
||||
type=switch
|
||||
polling=10
|
||||
|
||||
;[Ventilator]
|
||||
;topic=zway/power/test/wVentilator
|
||||
;type=Power
|
||||
;polling=10
|
@ -1,2 +1,2 @@
|
||||
[general]
|
||||
mqtt-server=129.26.160.65
|
||||
mqtt-server=localhost
|
@ -1,22 +1,45 @@
|
||||
;[ThinkpadGraph]
|
||||
;sensor=Thinkpad
|
||||
;type=Graph
|
||||
[ThinkpadMeter]
|
||||
sensor=Thinkpad
|
||||
type=PowerMeter
|
||||
items=100
|
||||
|
||||
;[TvGraph]
|
||||
;sensor=Tv
|
||||
;type=Graph
|
||||
[TvMeter]
|
||||
sensor=Tv
|
||||
type=PowerMeter
|
||||
items=100
|
||||
|
||||
;[KühlschrankGraph]
|
||||
;sensor=Kühlschrank
|
||||
;type=Graph
|
||||
[KühlschrankrMeter]
|
||||
sensor=Kühlschrank
|
||||
type=PowerMeter
|
||||
items=100
|
||||
|
||||
[VentilatorGraph]
|
||||
sensor=Ventilator
|
||||
[ThinkpadGraph]
|
||||
sensor=Thinkpad
|
||||
type=Graph
|
||||
items=100
|
||||
|
||||
[VentilatorMeter]
|
||||
sensor=Ventilator
|
||||
type=Meter
|
||||
unit=W
|
||||
items=100
|
||||
[TvGraph]
|
||||
sensor=Tv
|
||||
type=Graph
|
||||
items=100
|
||||
|
||||
[KühlschrankGraph]
|
||||
sensor=Kühlschrank
|
||||
type=Graph
|
||||
items=100
|
||||
|
||||
[TvSWMeter]
|
||||
sensor=TvSW
|
||||
type=Switcher
|
||||
items=100
|
||||
|
||||
;[VentilatorGraph]
|
||||
;sensor=Ventilator
|
||||
;type=Graph
|
||||
;items=100
|
||||
|
||||
;[VentilatorMeter]
|
||||
;sensor=Ventilator
|
||||
;type=Meter
|
||||
;unit=W
|
||||
;items=100
|
Loading…
Reference in New Issue
Block a user