From c634625f0e994e78cece2248e67f35a67a0ccc8c Mon Sep 17 00:00:00 2001 From: BlubbFish Date: Sun, 6 Aug 2017 21:24:15 +0000 Subject: [PATCH] [NF] Simple Dashboard Initial Commit --- Dashboard.sln | 28 ++++ Mqtt-Dashboard/App.config | 6 + Mqtt-Dashboard/Connector/Mqtt.cs | 37 ++++++ Mqtt-Dashboard/Dashboard.csproj | 100 ++++++++++++++ Mqtt-Dashboard/Form1.Designer.cs | 80 ++++++++++++ Mqtt-Dashboard/Form1.cs | 28 ++++ Mqtt-Dashboard/Form1.resx | 123 ++++++++++++++++++ Mqtt-Dashboard/Program.cs | 16 +++ Mqtt-Dashboard/Properties/AssemblyInfo.cs | 36 +++++ .../Properties/Resources.Designer.cs | 63 +++++++++ Mqtt-Dashboard/Properties/Resources.resx | 117 +++++++++++++++++ .../Properties/Settings.Designer.cs | 26 ++++ Mqtt-Dashboard/Properties/Settings.settings | 7 + Mqtt-Dashboard/Tracings/ATracings.cs | 10 ++ Mqtt-Dashboard/Tracings/Graph.cs | 10 ++ Mqtt-Dashboard/packages.config | 4 + Mqtt-Dashboard/settings.ini | 2 + 17 files changed, 693 insertions(+) create mode 100644 Dashboard.sln create mode 100644 Mqtt-Dashboard/App.config create mode 100644 Mqtt-Dashboard/Connector/Mqtt.cs create mode 100644 Mqtt-Dashboard/Dashboard.csproj create mode 100644 Mqtt-Dashboard/Form1.Designer.cs create mode 100644 Mqtt-Dashboard/Form1.cs create mode 100644 Mqtt-Dashboard/Form1.resx create mode 100644 Mqtt-Dashboard/Program.cs create mode 100644 Mqtt-Dashboard/Properties/AssemblyInfo.cs create mode 100644 Mqtt-Dashboard/Properties/Resources.Designer.cs create mode 100644 Mqtt-Dashboard/Properties/Resources.resx create mode 100644 Mqtt-Dashboard/Properties/Settings.Designer.cs create mode 100644 Mqtt-Dashboard/Properties/Settings.settings create mode 100644 Mqtt-Dashboard/Tracings/ATracings.cs create mode 100644 Mqtt-Dashboard/Tracings/Graph.cs create mode 100644 Mqtt-Dashboard/packages.config create mode 100644 Mqtt-Dashboard/settings.ini diff --git a/Dashboard.sln b/Dashboard.sln new file mode 100644 index 0000000..ad124b7 --- /dev/null +++ b/Dashboard.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26403.7 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dashboard", "Mqtt-Dashboard\Dashboard.csproj", "{16AC0F61-0B60-4A1D-A827-B3BFDBA9AAC7}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils", "..\Utils\Utils\Utils.csproj", "{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {16AC0F61-0B60-4A1D-A827-B3BFDBA9AAC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {16AC0F61-0B60-4A1D-A827-B3BFDBA9AAC7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {16AC0F61-0B60-4A1D-A827-B3BFDBA9AAC7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {16AC0F61-0B60-4A1D-A827-B3BFDBA9AAC7}.Release|Any CPU.Build.0 = Release|Any CPU + {FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Mqtt-Dashboard/App.config b/Mqtt-Dashboard/App.config new file mode 100644 index 0000000..d740e88 --- /dev/null +++ b/Mqtt-Dashboard/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Mqtt-Dashboard/Connector/Mqtt.cs b/Mqtt-Dashboard/Connector/Mqtt.cs new file mode 100644 index 0000000..f291bef --- /dev/null +++ b/Mqtt-Dashboard/Connector/Mqtt.cs @@ -0,0 +1,37 @@ +using System; +using System.Text; +using BlubbFish.Utils; +using uPLibrary.Networking.M2Mqtt; +using uPLibrary.Networking.M2Mqtt.Messages; + +namespace Dashboard.Connector { + class Mqtt { + private static Mqtt instance; + private MqttClient client; + + public delegate void MqttMessage(Object sender, MqttMsgPublishEventArgs e); + + public event MqttMessage MessageIncomming; + + private Mqtt() { + this.client = new MqttClient(InIReader.GetInstance("settings.ini").GetValue("general", "mqtt-server")); + } + public static Mqtt Instance { + get { + if(instance == null) { + instance = new Mqtt(); + } + return instance; + } + } + public void Connect() { + this.client.MqttMsgPublishReceived += this.Client_MqttMsgPublishReceived; + this.client.Connect(Guid.NewGuid().ToString()); + this.client.Subscribe(new String[] { "#" }, new Byte[] { MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE }); + } + + private void Client_MqttMsgPublishReceived(Object sender, MqttMsgPublishEventArgs e) { + this.MessageIncomming?.Invoke(this, e); + } + } +} diff --git a/Mqtt-Dashboard/Dashboard.csproj b/Mqtt-Dashboard/Dashboard.csproj new file mode 100644 index 0000000..886b263 --- /dev/null +++ b/Mqtt-Dashboard/Dashboard.csproj @@ -0,0 +1,100 @@ + + + + + Debug + AnyCPU + {16AC0F61-0B60-4A1D-A827-B3BFDBA9AAC7} + WinExe + Dashboard + Dashboard + v4.5.2 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\M2Mqtt.4.3.0.0\lib\net45\M2Mqtt.Net.dll + + + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + PreserveNewest + + + + + + + + {fac8ce64-bf13-4ece-8097-aeb5dd060098} + Utils + + + + \ No newline at end of file diff --git a/Mqtt-Dashboard/Form1.Designer.cs b/Mqtt-Dashboard/Form1.Designer.cs new file mode 100644 index 0000000..52832df --- /dev/null +++ b/Mqtt-Dashboard/Form1.Designer.cs @@ -0,0 +1,80 @@ +namespace Dashboard { + partial class Dashboard { + /// + /// Erforderliche Designervariable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Verwendete Ressourcen bereinigen. + /// + /// True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False. + protected override void Dispose(bool disposing) { + if (disposing && (components != null)) { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Vom Windows Form-Designer generierter Code + + /// + /// Erforderliche Methode für die Designerunterstützung. + /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. + /// + private void InitializeComponent() { + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); + this.statusStrip1 = new System.Windows.Forms.StatusStrip(); + this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart(); + ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit(); + this.SuspendLayout(); + // + // statusStrip1 + // + this.statusStrip1.Location = new System.Drawing.Point(0, 304); + this.statusStrip1.Name = "statusStrip1"; + this.statusStrip1.Size = new System.Drawing.Size(843, 22); + this.statusStrip1.TabIndex = 0; + this.statusStrip1.Text = "statusStrip1"; + // + // chart1 + // + chartArea1.Name = "ChartArea1"; + this.chart1.ChartAreas.Add(chartArea1); + legend1.Name = "Legend1"; + this.chart1.Legends.Add(legend1); + this.chart1.Location = new System.Drawing.Point(62, 21); + this.chart1.Name = "chart1"; + series1.ChartArea = "ChartArea1"; + series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series1.Legend = "Legend1"; + series1.Name = "Series1"; + this.chart1.Series.Add(series1); + this.chart1.Size = new System.Drawing.Size(324, 166); + this.chart1.TabIndex = 1; + this.chart1.Text = "chart1"; + // + // 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.Controls.Add(this.chart1); + this.Controls.Add(this.statusStrip1); + this.Name = "Dashboard"; + this.Text = "Dashboard"; + ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.StatusStrip statusStrip1; + private System.Windows.Forms.DataVisualization.Charting.Chart chart1; + } +} + diff --git a/Mqtt-Dashboard/Form1.cs b/Mqtt-Dashboard/Form1.cs new file mode 100644 index 0000000..b38465d --- /dev/null +++ b/Mqtt-Dashboard/Form1.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Dashboard.Connector; + +namespace Dashboard { + public partial class Dashboard : Form { + public Dashboard() { + InitializeComponent(); + Mqtt.Instance.Connect(); + this.chart1.ChartAreas[0].AxisX.Maximum = 100; + Mqtt.Instance.MessageIncomming += this.Instance_MessageIncomming; + } + + private void Instance_MessageIncomming(Object sender, uPLibrary.Networking.M2Mqtt.Messages.MqttMsgPublishEventArgs e) { + if(e.Topic == "zway/wohnzimmer/thinkpad/power") { + + } + System.Diagnostics.Debug.WriteLine("Received = " + Encoding.UTF8.GetString(e.Message) + " on topic " + e.Topic); + } + } +} diff --git a/Mqtt-Dashboard/Form1.resx b/Mqtt-Dashboard/Form1.resx new file mode 100644 index 0000000..a97b9fc --- /dev/null +++ b/Mqtt-Dashboard/Form1.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Mqtt-Dashboard/Program.cs b/Mqtt-Dashboard/Program.cs new file mode 100644 index 0000000..83d5bef --- /dev/null +++ b/Mqtt-Dashboard/Program.cs @@ -0,0 +1,16 @@ +using System; +using System.Windows.Forms; + +namespace Dashboard { + static class Program { + /// + /// Der Haupteinstiegspunkt für die Anwendung. + /// + [STAThread] + static void Main() { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Dashboard()); + } + } +} diff --git a/Mqtt-Dashboard/Properties/AssemblyInfo.cs b/Mqtt-Dashboard/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..61ae7fa --- /dev/null +++ b/Mqtt-Dashboard/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die einer Assembly zugeordnet sind. +[assembly: AssemblyTitle("Mqtt-Dashboard")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Mqtt-Dashboard")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly +// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von +// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird +[assembly: Guid("16ac0f61-0b60-4a1d-a827-b3bfdba9aac7")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, +// übernehmen, indem Sie "*" eingeben: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Mqtt-Dashboard/Properties/Resources.Designer.cs b/Mqtt-Dashboard/Properties/Resources.Designer.cs new file mode 100644 index 0000000..90cab43 --- /dev/null +++ b/Mqtt-Dashboard/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +//------------------------------------------------------------------------------ + +namespace Dashboard.Properties { + using System; + + + /// + /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. + /// + // Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert + // -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. + // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen + // mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Dashboard.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle + /// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/Mqtt-Dashboard/Properties/Resources.resx b/Mqtt-Dashboard/Properties/Resources.resx new file mode 100644 index 0000000..ffecec8 --- /dev/null +++ b/Mqtt-Dashboard/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Mqtt-Dashboard/Properties/Settings.Designer.cs b/Mqtt-Dashboard/Properties/Settings.Designer.cs new file mode 100644 index 0000000..deec467 --- /dev/null +++ b/Mqtt-Dashboard/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +//------------------------------------------------------------------------------ + +namespace Dashboard.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.1.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/Mqtt-Dashboard/Properties/Settings.settings b/Mqtt-Dashboard/Properties/Settings.settings new file mode 100644 index 0000000..abf36c5 --- /dev/null +++ b/Mqtt-Dashboard/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Mqtt-Dashboard/Tracings/ATracings.cs b/Mqtt-Dashboard/Tracings/ATracings.cs new file mode 100644 index 0000000..ca62c88 --- /dev/null +++ b/Mqtt-Dashboard/Tracings/ATracings.cs @@ -0,0 +1,10 @@ +using System; + +namespace Dashboard.Tracings { + public abstract class ATracings { + public abstract Int32 ElementWidth { get; } + public abstract Int32 ElementHeight { get; } + + public abstract void SetSensor(ASensor s); + } +} \ No newline at end of file diff --git a/Mqtt-Dashboard/Tracings/Graph.cs b/Mqtt-Dashboard/Tracings/Graph.cs new file mode 100644 index 0000000..4d5eff2 --- /dev/null +++ b/Mqtt-Dashboard/Tracings/Graph.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Dashboard.Tracings { + class Graph : ATracings { + } +} diff --git a/Mqtt-Dashboard/packages.config b/Mqtt-Dashboard/packages.config new file mode 100644 index 0000000..d651a22 --- /dev/null +++ b/Mqtt-Dashboard/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Mqtt-Dashboard/settings.ini b/Mqtt-Dashboard/settings.ini new file mode 100644 index 0000000..d392063 --- /dev/null +++ b/Mqtt-Dashboard/settings.ini @@ -0,0 +1,2 @@ +[general] +mqtt-server=localhost \ No newline at end of file