[NF] Aufgeräumt

This commit is contained in:
2017-10-02 18:32:06 +02:00
parent 8d80a132dc
commit b1efd55025
67 changed files with 591 additions and 1110 deletions
+10 -1
View File
@@ -1,12 +1,14 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26403.7
VisualStudioVersion = 15.0.26730.16
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
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils-IoT", "..\Utils\IoT\Utils-IoT.csproj", "{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -21,8 +23,15 @@ Global
{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
{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1B2A7AC0-6D12-415F-89CF-9C5AFADDD227}
EndGlobalSection
EndGlobal
+3 -3
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
</startup>
</configuration>
</configuration>
@@ -1,38 +0,0 @@
using System;
using System.Collections.Generic;
namespace IoTBot.Connector {
public abstract class ADataBackend {
public abstract event MqttMessage MessageIncomming;
public abstract event MqttMessage MessageSending;
public delegate void MqttMessage(ADataBackend sender, MqttEventArgs e);
public static ADataBackend GetInstance(Dictionary<String, String> dictionary) {
String object_sensor = "IoTBot.Connector." + Char.ToUpper(dictionary["type"][0]) + dictionary["type"].Substring(1).ToLower();
Type t = null;
try {
t = Type.GetType(object_sensor, true);
} catch (TypeLoadException) {
throw new ArgumentException("settings.ini: " + dictionary["type"] + " is not a Connector");
}
return (ADataBackend)t.GetConstructor(new Type[] { typeof(Dictionary<String, String>) }).Invoke(new Object[] { dictionary });
}
public abstract void Send(String topic, String data);
public abstract void Dispose();
}
public class MqttEventArgs : EventArgs {
public MqttEventArgs() : base() { }
public MqttEventArgs(String message, String topic) {
this.Topic = topic;
this.Message = message;
this.Date = DateTime.Now;
}
public String Topic { get; private set; }
public String Message { get; private set; }
public DateTime Date { get; private set; }
}
}
@@ -1,121 +0,0 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text.RegularExpressions;
namespace IoTBot.Connector {
class Mosquitto : ADataBackend, IDisposable {
private Process p;
private String message;
public override event MqttMessage MessageIncomming;
public override event MqttMessage MessageSending;
public Mosquitto(Dictionary<String, String> mqtt_settings) {
this.settings = mqtt_settings;
//mosquitto_sub --cafile ca.pem --cert cert.pem --key cert.key -h swb.broker.flex4grid.eu -p 8883 -t "#" -v -d
this.message = "";
this.p = new Process();
this.p.StartInfo.FileName = "mosquitto_sub";
String args = "-h " + this.settings["server"]+" ";
if(this.settings.ContainsKey("port")) {
args += "-p "+ this.settings["port"]+" ";
}
if (this.settings.ContainsKey("cafile")) {
args += "--cafile " + this.settings["cafile"] + " ";
}
if (this.settings.ContainsKey("cert")) {
args += "--cert " + this.settings["cert"] + " ";
}
if (this.settings.ContainsKey("key")) {
args += "--key " + this.settings["key"] + " ";
}
this.p.StartInfo.Arguments = args+"-t \"#\" -v -d";
this.p.StartInfo.CreateNoWindow = true;
this.p.StartInfo.UseShellExecute = false;
this.p.StartInfo.RedirectStandardOutput = true;
this.p.StartInfo.RedirectStandardError = true;
this.p.OutputDataReceived += this.P_OutputDataReceived;
this.p.ErrorDataReceived += this.P_ErrorDataReceived;
this.p.Start();
this.p.BeginOutputReadLine();
}
public override void Send(String topic, String data) {
Process send = new Process();
send.StartInfo.FileName = "mosquitto_pub";
String args = "-h " + this.settings["server"] + " ";
if (this.settings.ContainsKey("port")) {
args += "-p " + this.settings["port"] + " ";
}
if (this.settings.ContainsKey("cafile")) {
args += "--cafile " + this.settings["cafile"] + " ";
}
if (this.settings.ContainsKey("cert")) {
args += "--cert " + this.settings["cert"] + " ";
}
if (this.settings.ContainsKey("key")) {
args += "--key " + this.settings["key"] + " ";
}
send.StartInfo.Arguments = args + "-m \""+data.Replace("\"","\\\"")+"\" -t \""+topic+"\" -d";
send.StartInfo.CreateNoWindow = true;
send.StartInfo.UseShellExecute = false;
send.StartInfo.RedirectStandardOutput = true;
send.StartInfo.RedirectStandardError = true;
send.Start();
send.WaitForExit();
MessageSending?.Invoke(this, new MqttEventArgs(data, topic));
}
private void P_ErrorDataReceived(Object sender, DataReceivedEventArgs e) {
if (e.Data != null) {
throw new NotImplementedException(e.Data);
}
}
private void P_OutputDataReceived(Object sender, DataReceivedEventArgs e) {
if (e.Data != null) {
if (e.Data.StartsWith("Client mosqsub")) {
if (this.message != "" && this.message.IndexOf(" received PUBLISH ") > 0) {
MatchCollection matches = (new Regex("^Client mosqsub[\\|/].*received PUBLISH \\(.*,.*,.*,.*, '(.*)'.*\\)\\)\n[^ ]* (.*)$", RegexOptions.IgnoreCase | RegexOptions.Singleline)).Matches(this.message);
String topic = matches[0].Groups[1].Value;
String message = matches[0].Groups[2].Value.Trim();
this.MessageIncomming?.Invoke(this, new MqttEventArgs(message, topic));
}
this.message = e.Data + "\n";
} else {
this.message += e.Data + "\n";
}
}
}
#region IDisposable Support
private Boolean disposedValue = false; // Dient zur Erkennung redundanter Aufrufe.
private readonly Dictionary<String, String> settings;
protected virtual void Dispose(Boolean disposing) {
if (!this.disposedValue) {
if (disposing) {
this.p.CancelOutputRead();
if (!this.p.HasExited) {
this.p.Kill();
}
this.p.Close();
}
this.p = null;
this.disposedValue = true;
}
}
~Mosquitto() {
Dispose(false);
}
public override void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
}
}
@@ -1,65 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using uPLibrary.Networking.M2Mqtt;
using uPLibrary.Networking.M2Mqtt.Messages;
namespace IoTBot.Connector {
class Mqtt : ADataBackend, IDisposable {
private MqttClient client;
public override event MqttMessage MessageIncomming;
public override event MqttMessage MessageSending;
public Mqtt(Dictionary<String, String> settings) {
if(settings.ContainsKey("port")) {
this.client = new MqttClient(settings["server"], Int32.Parse(settings["port"]), false, null, null, MqttSslProtocols.None);
} else {
this.client = new MqttClient(settings["server"]);
}
Connect();
}
private 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, new MqttEventArgs(Encoding.UTF8.GetString(e.Message), e.Topic));
}
public override void Send(String topic, String data) {
this.client.Publish(topic, Encoding.UTF8.GetBytes(data));
this.MessageSending?.Invoke(this, new MqttEventArgs(data, topic));
}
#region IDisposable Support
private Boolean disposedValue = false;
protected virtual void Dispose(Boolean disposing) {
if(!this.disposedValue) {
if(disposing) {
this.client.MqttMsgPublishReceived -= this.Client_MqttMsgPublishReceived;
this.client.Unsubscribe(new String[] { "#" });
this.client.Disconnect();
}
this.client = null;
this.disposedValue = true;
}
}
~Mqtt() {
Dispose(false);
}
public override void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
}
}
@@ -1,54 +0,0 @@
using BlubbFish.Utils;
using System;
using Telegram.Bot;
using Telegram.Bot.Args;
using Telegram.Bot.Exceptions;
using Telegram.Bot.Types;
namespace IoTBot.Connector {
class Telegram {
private static Telegram instance;
private TelegramBotClient bot;
private ChatId chat;
public delegate void TelegramMessage(Object sender, Message e);
public event TelegramMessage MessageIncomming;
public event TelegramMessage MessageSending;
private Telegram() {
this.bot = new TelegramBotClient(InIReader.GetInstance("settings.ini").GetValue("general", "telegram-key"));
this.bot.OnMessage += this.Bot_OnMessage;
this.Connect();
}
private void Bot_OnMessage(Object sender, MessageEventArgs e) {
this.MessageIncomming?.Invoke(this, e.Message);
}
public static Telegram Instance {
get {
if(instance == null) {
instance = new Telegram();
}
return instance;
}
}
private void Connect() {
this.bot.StartReceiving();
this.chat = new ChatId(InIReader.GetInstance("settings.ini").GetValue("general", "chatid"));
}
public async void Send(String text) {
try {
Message x = await this.bot.SendTextMessageAsync(this.chat, text);
this.MessageSending?.Invoke(this, x);
} catch(ApiRequestException e) {
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(e.Message+" "+e.ErrorCode+" "+e.Parameters);
Console.ForegroundColor = ConsoleColor.White;
}
}
}
}
+6 -16
View File
@@ -8,7 +8,7 @@
<OutputType>WinExe</OutputType>
<RootNamespace>Dashboard</RootNamespace>
<AssemblyName>Dashboard</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<PublishUrl>publish\</PublishUrl>
@@ -26,6 +26,7 @@
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -50,12 +51,6 @@
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="LitJson, Version=0.9.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\LitJson.0.9.0\lib\LitJson.dll</HintPath>
</Reference>
<Reference Include="M2Mqtt.Net, Version=4.3.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\M2Mqtt.4.3.0.0\lib\net45\M2Mqtt.Net.dll</HintPath>
</Reference>
<Reference Include="OxyPlot, Version=1.0.0.0, Culture=neutral, PublicKeyToken=638079a8f0bd61e9, processorArchitecture=MSIL">
<HintPath>..\packages\OxyPlot.Core.1.0.0\lib\net45\OxyPlot.dll</HintPath>
</Reference>
@@ -67,7 +62,6 @@
<Reference Include="System.Windows.Forms.DataVisualization" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
@@ -76,9 +70,6 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Connector\ADataBackend.cs" />
<Compile Include="Connector\Mosquitto.cs" />
<Compile Include="Connector\Mqtt.cs" />
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
@@ -87,11 +78,6 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Sensor\ASensor.cs" />
<Compile Include="Sensor\Flex4GridPower.cs" />
<Compile Include="Sensor\Power.cs" />
<Compile Include="Sensor\Flex4GridSwitch.cs" />
<Compile Include="Sensor\Switch.cs" />
<Compile Include="Tracings\ATracings.cs" />
<Compile Include="Tracings\Graph.cs" />
<Compile Include="Tracings\Meter.cs" />
@@ -128,6 +114,10 @@
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Utils\IoT\Utils-IoT.csproj">
<Project>{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}</Project>
<Name>Utils-IoT</Name>
</ProjectReference>
<ProjectReference Include="..\..\Utils\Utils\Utils.csproj">
<Project>{fac8ce64-bf13-4ece-8097-aeb5dd060098}</Project>
<Name>Utils</Name>
+2 -2
View File
@@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.Windows.Forms;
using BlubbFish.Utils;
using IoTBot.Connector;
using IoTBot.Sensor;
using Dashboard.Tracings;
using BlubbFish.Utils.IoT.Sensor;
using BlubbFish.Utils.IoT.Connector;
namespace Dashboard {
public partial class Dashboard : Form {
@@ -19,7 +19,7 @@ namespace Dashboard.Properties {
// -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.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
@@ -12,7 +12,7 @@ namespace Dashboard.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.1.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.3.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
@@ -1,121 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
using IoTBot.Connector;
namespace IoTBot.Sensor {
public abstract class ASensor : IDisposable {
protected String topic;
protected Int32 pollcount;
private Dictionary<String, String> settings;
protected ADataBackend backend;
private Thread updateThread;
private Boolean pollEnabled = false;
public ASensor(Dictionary<String, String> settings, String name, ADataBackend backend) {
this.GetBool = true;
this.GetFloat = 0.0f;
this.GetInt = 0;
this.topic = (settings.Keys.Contains("topic")) ? settings["topic"] : "";
this.settings = settings;
this.Title = (settings.Keys.Contains("title")) ? settings["title"] : "";
this.Name = name;
this.backend = backend;
this.backend.MessageIncomming += this.IncommingMqttMessage;
if (settings.Keys.Contains("polling")) {
this.pollEnabled = true;
this.Polling = Int32.Parse(settings["polling"]);
this.pollcount = this.Polling;
this.updateThread = new Thread(this.SensorPolling);
this.updateThread.Start();
}
}
private void SensorPolling() {
while(this.pollEnabled) {
Thread.Sleep(1000);
this.Poll();
}
}
private void IncommingMqttMessage(Object sender, MqttEventArgs e) {
if(Regex.Match(e.Topic, this.topic).Success) {
if (this.UpdateValue(e)) {
this.Timestamp = DateTime.Now;
this.Update?.Invoke(this, e);
}
}
}
internal static ASensor GetInstance(ADataBackend backend, Dictionary<String, String> dictionary, String name) {
String object_sensor = "IoTBot.Sensor." + Char.ToUpper(dictionary["type"][0]) + dictionary["type"].Substring(1).ToLower();
Type t = null;
try {
t = Type.GetType(object_sensor, true);
} catch(TypeLoadException) {
throw new ArgumentException("sensor.ini: " + dictionary["type"] + " is not a Sensor");
}
return (ASensor)t.GetConstructor(new Type[] { typeof(Dictionary<String, String>), typeof(String), typeof(ADataBackend) }).Invoke(new Object[] { dictionary, name, backend });
}
protected virtual void Poll() {
if(this.pollcount++ >= this.Polling) {
this.pollcount = 1;
this.backend.Send(this.topic + "/status","");
}
}
internal virtual void SetBool(Boolean v) {
this.backend.Send(this.topic + "/set", v ? "on" : "off");
}
protected abstract Boolean UpdateValue(MqttEventArgs e);
public Single GetFloat { get; protected set; }
public Boolean GetBool { get; protected set; }
public Int32 GetInt { get; protected set; }
public Types Datatypes { get; protected set; }
public DateTime Timestamp { get; protected set; }
public Int32 Polling { get; private set; }
public String Title { get; protected set; }
public String Name { get; internal set; }
public enum Types {
Bool,
Int,
Float
}
public delegate void UpdatedValue(ASensor sender, EventArgs e);
public event UpdatedValue Update;
#region IDisposable Support
private Boolean disposedValue = false;
protected virtual void Dispose(Boolean disposing) {
if(!this.disposedValue) {
if(disposing) {
this.pollEnabled = false;
if (this.updateThread != null && this.updateThread.ThreadState == ThreadState.Running) {
this.updateThread.Abort();
while (this.updateThread.ThreadState != ThreadState.Aborted) { }
}
this.backend.MessageIncomming -= this.IncommingMqttMessage;
}
this.settings = null;
this.updateThread = null;
this.disposedValue = true;
}
}
~ASensor() {
Dispose(false);
}
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
}
}
@@ -1,52 +0,0 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text.RegularExpressions;
using IoTBot.Connector;
using LitJson;
namespace IoTBot.Sensor {
class Flex4gridswitch : ASensor {
private String id;
public Flex4gridswitch(Dictionary<String, String> settings, String name, ADataBackend backend) : base(settings, name, backend) {
this.Datatypes = Types.Bool;
this.id = settings["id"];
}
protected override Boolean UpdateValue(MqttEventArgs e) {
CultureInfo info = new CultureInfo("de-DE");
info.NumberFormat.NumberDecimalSeparator = ".";
CultureInfo.DefaultThreadCurrentCulture = info;
CultureInfo.DefaultThreadCurrentUICulture = info;
System.Threading.Thread.CurrentThread.CurrentCulture = info;
System.Threading.Thread.CurrentThread.CurrentUICulture = info;
try {
JsonData data = JsonMapper.ToObject(e.Message);
if (data.Keys.Contains("id") && data["id"].ToString() == this.id) {
this.GetBool = data["status"].ToString() == "active" ? true : false;
return true;
}
if(data.Keys.Contains(this.id)) {
this.GetBool = data[this.id].ToString() == "active" ? true : false;
return true;
}
} catch (Exception) {
}
return false;
}
protected override void Poll() {
if (this.pollcount++ >= this.Polling) {
this.pollcount = 1;
String hid = Regex.Match(this.topic, "/flex4grid/v1/households/([^/]*)/device/state").Groups[1].Value;
this.backend.Send("/flex4grid/v1/households/" + hid + "/devices/state/request", "{\"timestamp\": \"" + DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ffffff'Z'") + "\"}");
}
}
internal override void SetBool(Boolean v) {
String hid = Regex.Match(this.topic, "/flex4grid/v1/households/([^/]*)/device/state").Groups[1].Value;
this.backend.Send("/flex4grid/v1/households/" + hid + "/device/actuate", "{\"command\":\""+(v ? "ON" : "OFF") + "\",\"deviceId\":\""+ this.id + "\",\"timestamp\":\"" + DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ffffff'Z'") + "\"}");
}
}
}
@@ -1,34 +0,0 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using IoTBot.Connector;
using LitJson;
namespace IoTBot.Sensor {
class Flex4gridpower : ASensor {
private String id;
public Flex4gridpower(Dictionary<String, String> settings, String name, ADataBackend backend) : base(settings, name, backend) {
this.Datatypes = Types.Float;
this.id = settings["id"];
}
protected override Boolean UpdateValue(MqttEventArgs e) {
CultureInfo info = new CultureInfo("de-DE");
info.NumberFormat.NumberDecimalSeparator = ".";
CultureInfo.DefaultThreadCurrentCulture = info;
CultureInfo.DefaultThreadCurrentUICulture = info;
System.Threading.Thread.CurrentThread.CurrentCulture = info;
System.Threading.Thread.CurrentThread.CurrentUICulture = info;
try {
JsonData data = JsonMapper.ToObject(e.Message);
if(data["id"].ToString() == this.id) {
this.GetFloat = Single.Parse(data["power"].ToString());
return true;
}
} catch (Exception) {
}
return false;
}
}
}
@@ -1,20 +0,0 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using IoTBot.Connector;
namespace IoTBot.Sensor {
class Luminanz : ASensor {
public Luminanz(Dictionary<String, String> settings, String name, ADataBackend backend) : base(settings, name, backend) {
this.GetBool = true;
this.GetFloat = 0.0f;
this.GetInt = 0;
this.Datatypes = Types.Int;
}
protected override Boolean UpdateValue(MqttEventArgs e) {
this.GetInt = Int32.Parse(e.Message, new CultureInfo("en-US"));
return true;
}
}
}
@@ -1,16 +0,0 @@
using System;
using System.Collections.Generic;
using IoTBot.Connector;
namespace IoTBot.Sensor {
class Pir : ASensor {
public Pir(Dictionary<String, String> settings, String name, ADataBackend backend) : base(settings, name, backend) {
this.Datatypes = Types.Bool;
}
protected override Boolean UpdateValue(MqttEventArgs e) {
this.GetBool = (e.Message.ToLower() == "on") ? true : false;
return true;
}
}
}
@@ -1,20 +0,0 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using IoTBot.Connector;
namespace IoTBot.Sensor {
class Power : ASensor {
public Power(Dictionary<String, String> settings, String name, ADataBackend backend) : base(settings, name, backend) {
this.GetBool = true;
this.GetFloat = 0.0f;
this.GetInt = 0;
this.Datatypes = Types.Float;
}
protected override Boolean UpdateValue(MqttEventArgs e) {
this.GetFloat = Single.Parse(e.Message, new CultureInfo("en-US"));
return true;
}
}
}
@@ -1,16 +0,0 @@
using System;
using System.Collections.Generic;
using IoTBot.Connector;
namespace IoTBot.Sensor {
class Switch : ASensor {
public Switch(Dictionary<System.String, System.String> settings, String name, ADataBackend backend) : base(settings, name, backend) {
this.Datatypes = Types.Bool;
}
protected override Boolean UpdateValue(MqttEventArgs e) {
this.GetBool = (e.Message.ToLower() == "on") ? true : false;
return true;
}
}
}
@@ -1,20 +0,0 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using IoTBot.Connector;
namespace IoTBot.Sensor {
class Temperatur : ASensor {
public Temperatur(Dictionary<String, String> settings, String name, ADataBackend backend) : base(settings, name, backend) {
this.GetBool = true;
this.GetFloat = 0.0f;
this.GetInt = 0;
this.Datatypes = Types.Float;
}
protected override Boolean UpdateValue(MqttEventArgs e) {
this.GetFloat = Single.Parse(e.Message, new CultureInfo("en-US"));
return true;
}
}
}
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using IoTBot.Sensor;
using BlubbFish.Utils.IoT.Sensor;
namespace Dashboard.Tracings {
public abstract class ATracings {
@@ -22,8 +22,8 @@ namespace Dashboard.Tracings {
this.settings = settings;
}
protected abstract void SensorsUpdate(ASensor sender, EventArgs e);
protected abstract void SensorUpdate(ASensor sender, EventArgs e);
protected abstract void SensorsUpdate(Object sender, EventArgs e);
protected abstract void SensorUpdate(Object sender, EventArgs e);
public abstract Panel GetPanel();
internal static ATracings GetInstance(String v, Dictionary<String, ASensor> sensorList, Dictionary<String, String> dictionary) {
String object_sensor = "Dashboard.Tracings." + Char.ToUpper(v[0]) + v.Substring(1);
+19 -19
View File
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using IoTBot.Sensor;
using BlubbFish.Utils.IoT.Sensor;
using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Series;
@@ -68,14 +68,14 @@ namespace Dashboard.Tracings {
panel.Size = new System.Drawing.Size(fieldWidth, 200);
return panel;
}
protected override void SensorUpdate(ASensor sender, EventArgs e) {
protected override void SensorUpdate(Object sender, EventArgs e) {
Single v = 0;
switch (sender.Datatypes) {
case ASensor.Types.Bool: v = sender.GetBool ? 1 : 0; break;
case ASensor.Types.Int: v = sender.GetInt; break;
case ASensor.Types.Float: v = sender.GetFloat; break;
switch (((ASensor)sender).Datatypes) {
case ASensor.Types.Bool: v = ((ASensor)sender).GetBool ? 1 : 0; break;
case ASensor.Types.Int: v = ((ASensor)sender).GetInt; break;
case ASensor.Types.Float: v = ((ASensor)sender).GetFloat; break;
}
this.hist.Enqueue(new Tuple<DateTime, Single>(sender.Timestamp, v));
this.hist.Enqueue(new Tuple<DateTime, Single>(((ASensor)sender).Timestamp, v));
if (this.MaximumDrawn < v) {
this.MaximumDrawn = v;
}
@@ -86,7 +86,7 @@ namespace Dashboard.Tracings {
this.plot.BeginInvoke((MethodInvoker)delegate {
this.Model.Axes[1].Maximum = this.MaximumDrawn * 1.1;
this.Model.Axes[1].AbsoluteMaximum = this.MaximumDrawn * 1.1;
this.Model.Axes[0].AbsoluteMaximum = DateTimeAxis.ToDouble(sender.Timestamp);
this.Model.Axes[0].AbsoluteMaximum = DateTimeAxis.ToDouble(((ASensor)sender).Timestamp);
((LineSeries)this.Model.Series[0]).Points.Clear();
try {
foreach(Tuple<DateTime, Single> temp in this.hist) {
@@ -98,26 +98,26 @@ namespace Dashboard.Tracings {
}
}
protected override void SensorsUpdate(ASensor sender, EventArgs e) {
protected override void SensorsUpdate(Object sender, EventArgs e) {
Single v = 0;
if (!this.hists.ContainsKey(sender.Name)) {
this.hists.Add(sender.Name, new Queue<Tuple<DateTime, Single>>());
this.hists_last.Add(sender.Name, 0);
if (!this.hists.ContainsKey(((ASensor)sender).Name)) {
this.hists.Add(((ASensor)sender).Name, new Queue<Tuple<DateTime, Single>>());
this.hists_last.Add(((ASensor)sender).Name, 0);
}
switch (sender.Datatypes) {
switch (((ASensor)sender).Datatypes) {
case ASensor.Types.Bool:
v = sender.GetBool ? 1 : 0;
v = ((ASensor)sender).GetBool ? 1 : 0;
break;
case ASensor.Types.Int:
v = sender.GetInt;
v = ((ASensor)sender).GetInt;
break;
case ASensor.Types.Float:
v = sender.GetFloat;
v = ((ASensor)sender).GetFloat;
break;
}
this.hists_last[sender.Name] = v;
this.hists_last[((ASensor)sender).Name] = v;
foreach (KeyValuePair<String, Queue<Tuple<DateTime, Single>>> item in this.hists) {
item.Value.Enqueue(new Tuple<DateTime, Single>(sender.Timestamp, this.hists_last[item.Key]));
item.Value.Enqueue(new Tuple<DateTime, Single>(((ASensor)sender).Timestamp, this.hists_last[item.Key]));
if (this.MaximumDrawn < this.hists_last[item.Key]) {
this.MaximumDrawn = this.hists_last[item.Key];
}
@@ -131,7 +131,7 @@ namespace Dashboard.Tracings {
try {
this.Model.Axes[1].Maximum = this.MaximumDrawn * 1.1;
this.Model.Axes[1].AbsoluteMaximum = this.MaximumDrawn * 1.1;
this.Model.Axes[0].AbsoluteMaximum = DateTimeAxis.ToDouble(sender.Timestamp);
this.Model.Axes[0].AbsoluteMaximum = DateTimeAxis.ToDouble(((ASensor)sender).Timestamp);
((LineSeries)item).Points.Clear();
foreach (Tuple<DateTime, Single> temp in this.hists[item.TrackerKey]) {
((LineSeries)item).Points.Add(new DataPoint(DateTimeAxis.ToDouble(temp.Item1), temp.Item2));
@@ -1,9 +1,9 @@
using System.Collections.Generic;
using IoTBot.Sensor;
using System;
using System.Windows.Forms;
using System.Linq;
using System.Globalization;
using BlubbFish.Utils.IoT.Sensor;
namespace Dashboard.Tracings {
class Meter : ATracings {
@@ -45,16 +45,16 @@ namespace Dashboard.Tracings {
return panel;
}
protected override void SensorsUpdate(ASensor sender, EventArgs e) {
protected override void SensorsUpdate(Object sender, EventArgs e) {
throw new NotImplementedException();
}
protected override void SensorUpdate(ASensor sender, EventArgs e) {
protected override void SensorUpdate(Object sender, EventArgs e) {
String value = "";
switch(sender.Datatypes) {
case ASensor.Types.Bool: this.DisplayAverage.Enqueue((sender.GetBool) ? 1 : 0); value = sender.GetBool.ToString(new CultureInfo("de-DE")); break;
case ASensor.Types.Int: this.DisplayAverage.Enqueue(sender.GetInt); value = sender.GetInt.ToString(); break;
case ASensor.Types.Float: this.DisplayAverage.Enqueue(sender.GetFloat); value = sender.GetFloat.ToString(new CultureInfo("de-DE")); break;
switch(((ASensor)sender).Datatypes) {
case ASensor.Types.Bool: this.DisplayAverage.Enqueue((((ASensor)sender).GetBool) ? 1 : 0); value = ((ASensor)sender).GetBool.ToString(new CultureInfo("de-DE")); break;
case ASensor.Types.Int: this.DisplayAverage.Enqueue(((ASensor)sender).GetInt); value = ((ASensor)sender).GetInt.ToString(); break;
case ASensor.Types.Float: this.DisplayAverage.Enqueue(((ASensor)sender).GetFloat); value = ((ASensor)sender).GetFloat.ToString(new CultureInfo("de-DE")); break;
}
if(this.DisplayAverage.Count > this.DisplayItems) {
this.DisplayAverage.Dequeue();
@@ -3,26 +3,26 @@ using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows.Forms;
using IoTBot.Sensor;
using BlubbFish.Utils.IoT.Sensor;
namespace Dashboard.Tracings {
class Powermeter : Meter {
public Powermeter(ASensor sensor, Dictionary<String, String> settings) : base(sensor, settings) {
}
protected override void SensorUpdate(ASensor sender, EventArgs e) {
protected override void SensorUpdate(Object sender, EventArgs e) {
String value = "";
switch (sender.Datatypes) {
switch (((ASensor)sender).Datatypes) {
case ASensor.Types.Bool:
this.DisplayAverage.Enqueue((sender.GetBool) ? 1 : 0);
value = sender.GetBool.ToString(new CultureInfo("de-DE"));
this.DisplayAverage.Enqueue((((ASensor)sender).GetBool) ? 1 : 0);
value = ((ASensor)sender).GetBool.ToString(new CultureInfo("de-DE"));
break;
case ASensor.Types.Int:
this.DisplayAverage.Enqueue(sender.GetInt);
value = sender.GetInt.ToString();
this.DisplayAverage.Enqueue(((ASensor)sender).GetInt);
value = ((ASensor)sender).GetInt.ToString();
break;
case ASensor.Types.Float:
this.DisplayAverage.Enqueue(sender.GetFloat);
value = sender.GetFloat.ToString(new CultureInfo("de-DE"));
this.DisplayAverage.Enqueue(((ASensor)sender).GetFloat);
value = ((ASensor)sender).GetFloat.ToString(new CultureInfo("de-DE"));
break;
}
if (this.DisplayAverage.Count > this.DisplayItems) {
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Forms;
using IoTBot.Connector;
using IoTBot.Sensor;
using BlubbFish.Utils.IoT.Sensor;
namespace Dashboard.Tracings {
class Switcher : ATracings {
@@ -65,19 +63,19 @@ namespace Dashboard.Tracings {
}
}
protected override void SensorUpdate(ASensor sender, EventArgs e) {
protected override void SensorUpdate(Object sender, EventArgs e) {
this.label.BeginInvoke((MethodInvoker)delegate {
this.label.Text = sender.GetBool?"Eingeschaltet":"Ausgeschaltet";
this.label.Text = ((ASensor)sender).GetBool?"Eingeschaltet":"Ausgeschaltet";
});
this.button1.BeginInvoke((MethodInvoker)delegate {
this.button1.Enabled = !sender.GetBool;
this.button1.Enabled = !((ASensor)sender).GetBool;
});
this.button2.BeginInvoke((MethodInvoker)delegate {
this.button2.Enabled = sender.GetBool;
this.button2.Enabled = ((ASensor)sender).GetBool;
});
}
protected override void SensorsUpdate(ASensor sender, EventArgs e) {
protected override void SensorsUpdate(Object sender, EventArgs e) {
throw new NotImplementedException();
}
}
Binary file not shown.