From b1efd5502515b29814198d0709e711fee142f7e4 Mon Sep 17 00:00:00 2001 From: BlubbFish Date: Mon, 2 Oct 2017 18:32:06 +0200 Subject: [PATCH] =?UTF-8?q?[NF]=20Aufger=C3=A4umt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 41 ++++++ IoT-Bot/IoT-Bot.sln | 19 ++- IoT-Bot/IoT-Bot/App.config | 18 ++- IoT-Bot/IoT-Bot/Condition/ACondition.cs | 4 +- IoT-Bot/IoT-Bot/Condition/Edge.cs | 6 +- IoT-Bot/IoT-Bot/ConditionWorker.cs | 6 +- IoT-Bot/IoT-Bot/Connector/Mosquitto.cs | 121 ---------------- IoT-Bot/IoT-Bot/Connector/Mqtt.cs | 65 --------- IoT-Bot/IoT-Bot/Connector/Telegram.cs | 54 ------- IoT-Bot/IoT-Bot/IoT-Bot.csproj | 46 +----- IoT-Bot/IoT-Bot/Program.cs | 20 +-- IoT-Bot/IoT-Bot/Sensor/Flex4gridPower.cs | 34 ----- IoT-Bot/IoT-Bot/Sensor/Pir.cs | 16 --- IoT-Bot/IoT-Bot/Sensor/Power.cs | 20 --- IoT-Bot/IoT-Bot/Sensor/Switch.cs | 16 --- IoT-Bot/IoT-Bot/packages.config | 35 +++-- Mqtt-Dashboard/Dashboard.sln | 11 +- Mqtt-Dashboard/Mqtt-Dashboard/App.config | 6 +- .../Mqtt-Dashboard/Connector/ADataBackend.cs | 38 ----- .../Mqtt-Dashboard/Connector/Mosquitto.cs | 121 ---------------- .../Mqtt-Dashboard/Connector/Mqtt.cs | 65 --------- .../Mqtt-Dashboard/Connector/Telegram.cs | 54 ------- .../Mqtt-Dashboard/Dashboard.csproj | 22 +-- Mqtt-Dashboard/Mqtt-Dashboard/Form1.cs | 4 +- .../Properties/Resources.Designer.cs | 2 +- .../Properties/Settings.Designer.cs | 2 +- .../Mqtt-Dashboard/Sensor/ASensor.cs | 121 ---------------- .../Mqtt-Dashboard/Sensor/Flex4GridSwitch.cs | 52 ------- .../Mqtt-Dashboard/Sensor/Luminanz.cs | 20 --- .../Mqtt-Dashboard/Sensor/Temperatur.cs | 20 --- .../Mqtt-Dashboard/Tracings/ATracings.cs | 6 +- .../Mqtt-Dashboard/Tracings/Graph.cs | 38 ++--- .../Mqtt-Dashboard/Tracings/Meter.cs | 14 +- .../Mqtt-Dashboard/Tracings/PowerMeter.cs | 18 +-- .../Mqtt-Dashboard/Tracings/Switcher.cs | 14 +- .../Mqtt-Dashboard/bin/Release/Dashboard.exe | Bin 33280 -> 21504 bytes .../bin/Release/Newtonsoft.Json.dll | Bin 0 -> 653824 bytes .../bin/Release/Telegram.Bot.dll | Bin 0 -> 153088 bytes .../Mqtt-Dashboard/bin/Release/Utils-IoT.dll | Bin 0 -> 21504 bytes .../Mqtt-Dashboard/bin/Release/Utils.dll | Bin 24576 -> 24576 bytes Mqtt-SWB-Dashboard/Mqtt-SWB-Dashboard.sln | 10 +- .../Mqtt-SWB-Dashboard/App.config | 6 +- .../Connector/ADataBackend.cs | 38 ----- .../Mqtt-SWB-Dashboard/MainWindow.xaml.cs | 6 +- .../Mqtt-SWB-Dashboard.csproj | 9 +- .../Properties/Resources.Designer.cs | 99 ++++++------- .../Properties/Settings.Designer.cs | 34 ++--- .../Mqtt-SWB-Dashboard/Stats.cs | 2 +- Utils/IoT.sln | 31 ++++ .../IoT}/Connector/ADataBackend.cs | 6 +- .../IoT}/Connector/Mosquitto.cs | 2 +- .../IoT}/Connector/Mqtt.cs | 2 +- .../IoT}/Connector/Telegram.cs | 25 +++- Utils/IoT/Properties/AssemblyInfo.cs | 36 +++++ .../IoT-Bot => Utils/IoT}/Sensor/ASensor.cs | 12 +- .../IoT}/Sensor/Flex4GridSwitch.cs | 6 +- .../IoT}/Sensor/Flex4gridPower.cs | 4 +- .../IoT-Bot => Utils/IoT}/Sensor/Luminanz.cs | 4 +- .../IoT}/Sensor/Pir.cs | 4 +- .../IoT}/Sensor/Power.cs | 4 +- .../IoT}/Sensor/Switch.cs | 4 +- .../IoT}/Sensor/Temperatur.cs | 4 +- Utils/IoT/Utils-IoT.csproj | 136 ++++++++++++++++++ Utils/IoT/app.config | 15 ++ Utils/IoT/bin/Release/Utils-IoT.dll | Bin 0 -> 21504 bytes Utils/IoT/packages.config | 53 +++++++ Utils/Utils/bin/Release/Utils.dll | Bin 24576 -> 24576 bytes 67 files changed, 591 insertions(+), 1110 deletions(-) delete mode 100644 IoT-Bot/IoT-Bot/Connector/Mosquitto.cs delete mode 100644 IoT-Bot/IoT-Bot/Connector/Mqtt.cs delete mode 100644 IoT-Bot/IoT-Bot/Connector/Telegram.cs delete mode 100644 IoT-Bot/IoT-Bot/Sensor/Flex4gridPower.cs delete mode 100644 IoT-Bot/IoT-Bot/Sensor/Pir.cs delete mode 100644 IoT-Bot/IoT-Bot/Sensor/Power.cs delete mode 100644 IoT-Bot/IoT-Bot/Sensor/Switch.cs delete mode 100644 Mqtt-Dashboard/Mqtt-Dashboard/Connector/ADataBackend.cs delete mode 100644 Mqtt-Dashboard/Mqtt-Dashboard/Connector/Mosquitto.cs delete mode 100644 Mqtt-Dashboard/Mqtt-Dashboard/Connector/Mqtt.cs delete mode 100644 Mqtt-Dashboard/Mqtt-Dashboard/Connector/Telegram.cs delete mode 100644 Mqtt-Dashboard/Mqtt-Dashboard/Sensor/ASensor.cs delete mode 100644 Mqtt-Dashboard/Mqtt-Dashboard/Sensor/Flex4GridSwitch.cs delete mode 100644 Mqtt-Dashboard/Mqtt-Dashboard/Sensor/Luminanz.cs delete mode 100644 Mqtt-Dashboard/Mqtt-Dashboard/Sensor/Temperatur.cs create mode 100644 Mqtt-Dashboard/Mqtt-Dashboard/bin/Release/Newtonsoft.Json.dll create mode 100644 Mqtt-Dashboard/Mqtt-Dashboard/bin/Release/Telegram.Bot.dll create mode 100644 Mqtt-Dashboard/Mqtt-Dashboard/bin/Release/Utils-IoT.dll delete mode 100644 Mqtt-SWB-Dashboard/Mqtt-SWB-Dashboard/Connector/ADataBackend.cs create mode 100644 Utils/IoT.sln rename {IoT-Bot/IoT-Bot => Utils/IoT}/Connector/ADataBackend.cs (81%) rename {Mqtt-SWB-Dashboard/Mqtt-SWB-Dashboard => Utils/IoT}/Connector/Mosquitto.cs (99%) rename {Mqtt-SWB-Dashboard/Mqtt-SWB-Dashboard => Utils/IoT}/Connector/Mqtt.cs (97%) rename {Mqtt-SWB-Dashboard/Mqtt-SWB-Dashboard => Utils/IoT}/Connector/Telegram.cs (62%) create mode 100644 Utils/IoT/Properties/AssemblyInfo.cs rename {IoT-Bot/IoT-Bot => Utils/IoT}/Sensor/ASensor.cs (88%) rename {IoT-Bot/IoT-Bot => Utils/IoT}/Sensor/Flex4GridSwitch.cs (94%) rename {Mqtt-Dashboard/Mqtt-Dashboard => Utils/IoT}/Sensor/Flex4gridPower.cs (93%) rename {IoT-Bot/IoT-Bot => Utils/IoT}/Sensor/Luminanz.cs (87%) rename {Mqtt-Dashboard/Mqtt-Dashboard => Utils/IoT}/Sensor/Pir.cs (83%) rename {Mqtt-Dashboard/Mqtt-Dashboard => Utils/IoT}/Sensor/Power.cs (87%) rename {Mqtt-Dashboard/Mqtt-Dashboard => Utils/IoT}/Sensor/Switch.cs (84%) rename {IoT-Bot/IoT-Bot => Utils/IoT}/Sensor/Temperatur.cs (87%) create mode 100644 Utils/IoT/Utils-IoT.csproj create mode 100644 Utils/IoT/app.config create mode 100644 Utils/IoT/bin/Release/Utils-IoT.dll create mode 100644 Utils/IoT/packages.config diff --git a/.gitignore b/.gitignore index 08ea109..34c17c7 100644 --- a/.gitignore +++ b/.gitignore @@ -90,3 +90,44 @@ /Mqtt-Dashboard/Mqtt-Dashboard/Connector/.svn /Mqtt-Dashboard/Mqtt-Dashboard/Sensor/.svn /IoT-Bot/IoT-Bot/bin/Debug +/.gitattributes +/Utils/Utils/bin/Release/Utils.dll.CodeAnalysisLog.xml +/Utils/Utils/bin/Release/Utils.dll.lastcodeanalysissucceeded +/Utils/packages +/Utils/IoT/.vs/Utils-IoT/v15 +/Utils/IoT/bin/Debug +/Utils/IoT/bin/Release/M2Mqtt.Net.pdb +/Utils/IoT/bin/Release/LitJson.dll +/Utils/IoT/bin/Release/M2Mqtt.Net.dll +/Utils/IoT/bin/Release/Microsoft.Win32.Primitives.dll +/Utils/IoT/bin/Release/Newtonsoft.Json.dll +/Utils/IoT/bin/Release/Newtonsoft.Json.xml +/Utils/IoT/bin/Release/System.AppContext.dll +/Utils/IoT/bin/Release/System.Console.dll +/Utils/IoT/bin/Release/System.Diagnostics.DiagnosticSource.dll +/Utils/IoT/bin/Release/System.Diagnostics.DiagnosticSource.xml +/Utils/IoT/bin/Release/System.Globalization.Calendars.dll +/Utils/IoT/bin/Release/System.IO.Compression.dll +/Utils/IoT/bin/Release/System.IO.Compression.ZipFile.dll +/Utils/IoT/bin/Release/System.IO.FileSystem.dll +/Utils/IoT/bin/Release/System.IO.FileSystem.Primitives.dll +/Utils/IoT/bin/Release/System.Net.Http.dll +/Utils/IoT/bin/Release/System.Net.Sockets.dll +/Utils/IoT/bin/Release/System.Runtime.InteropServices.RuntimeInformation.dll +/Utils/IoT/bin/Release/System.Security.Cryptography.Algorithms.dll +/Utils/IoT/bin/Release/System.Security.Cryptography.Encoding.dll +/Utils/IoT/bin/Release/System.Security.Cryptography.Primitives.dll +/Utils/IoT/bin/Release/System.Security.Cryptography.X509Certificates.dll +/Utils/IoT/bin/Release/System.Xml.ReaderWriter.dll +/Utils/IoT/bin/Release/Telegram.Bot.dll +/Utils/IoT/bin/Release/Utils-IoT.dll.CodeAnalysisLog.xml +/Utils/IoT/bin/Release/Utils-IoT.dll.lastcodeanalysissucceeded +/Utils/IoT/bin/Release/Utils-IoT.dll.config +/Utils/IoT/bin/Release/Utils-IoT.pdb +/Utils/IoT/bin/Release/Utils.dll +/Utils/IoT/bin/Release/Utils.pdb +/Utils/IoT/obj +/Utils/.vs +/Mqtt-Dashboard/Mqtt-Dashboard/bin/Release/Newtonsoft.Json.xml +/Mqtt-Dashboard/Mqtt-Dashboard/bin/Release/Utils-IoT.dll.config +/Mqtt-Dashboard/Mqtt-Dashboard/bin/Release/Utils-IoT.pdb diff --git a/IoT-Bot/IoT-Bot.sln b/IoT-Bot/IoT-Bot.sln index e7aa6d9..0c2eb85 100644 --- a/IoT-Bot/IoT-Bot.sln +++ b/IoT-Bot/IoT-Bot.sln @@ -1,10 +1,14 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 +# Visual Studio 15 +VisualStudioVersion = 15.0.26730.16 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IoT-Bot", "IoT-Bot\IoT-Bot.csproj", "{89077643-B472-419F-8EAB-56B9E2D13ABC}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils-IoT", "..\Utils\IoT\Utils-IoT.csproj", "{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}" +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 @@ -15,8 +19,19 @@ Global {89077643-B472-419F-8EAB-56B9E2D13ABC}.Debug|Any CPU.Build.0 = Debug|Any CPU {89077643-B472-419F-8EAB-56B9E2D13ABC}.Release|Any CPU.ActiveCfg = Release|Any CPU {89077643-B472-419F-8EAB-56B9E2D13ABC}.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 + {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 + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {868AF401-44D7-4E3C-826A-8FA1E24C850D} + EndGlobalSection EndGlobal diff --git a/IoT-Bot/IoT-Bot/App.config b/IoT-Bot/IoT-Bot/App.config index 88fa402..89e897b 100644 --- a/IoT-Bot/IoT-Bot/App.config +++ b/IoT-Bot/IoT-Bot/App.config @@ -1,6 +1,18 @@ - + - + - \ No newline at end of file + + + + + + + + + + + + + diff --git a/IoT-Bot/IoT-Bot/Condition/ACondition.cs b/IoT-Bot/IoT-Bot/Condition/ACondition.cs index e2c84d5..d6aae87 100644 --- a/IoT-Bot/IoT-Bot/Condition/ACondition.cs +++ b/IoT-Bot/IoT-Bot/Condition/ACondition.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -using IoTBot.Connector; -using IoTBot.Sensor; +using BlubbFish.Utils.IoT.Connector; +using BlubbFish.Utils.IoT.Sensor; namespace IoTBot.Condition { abstract class ACondition { diff --git a/IoT-Bot/IoT-Bot/Condition/Edge.cs b/IoT-Bot/IoT-Bot/Condition/Edge.cs index 72ce7c7..32114cd 100644 --- a/IoT-Bot/IoT-Bot/Condition/Edge.cs +++ b/IoT-Bot/IoT-Bot/Condition/Edge.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -using IoTBot.Connector; -using IoTBot.Sensor; +using BlubbFish.Utils.IoT.Connector; +using BlubbFish.Utils.IoT.Sensor; namespace IoTBot.Condition { class Edge : ACondition { @@ -15,7 +15,7 @@ namespace IoTBot.Condition { if(this.sensor.Datatypes == ASensor.Types.Bool) { if(this.sensor.GetBool == Boolean.Parse(this.settings["sensor_value"]) && this.histBool != this.sensor.GetBool) { this.histBool = this.sensor.GetBool; - IoTBot.Connector.Telegram.Instance.Send("Jemand ist DA!"); + Telegram.Instance.Send("Jemand ist DA!"); } else { this.histBool = this.sensor.GetBool; } diff --git a/IoT-Bot/IoT-Bot/ConditionWorker.cs b/IoT-Bot/IoT-Bot/ConditionWorker.cs index 1c05f41..fc53037 100644 --- a/IoT-Bot/IoT-Bot/ConditionWorker.cs +++ b/IoT-Bot/IoT-Bot/ConditionWorker.cs @@ -1,15 +1,15 @@ using System; using System.Collections.Generic; using BlubbFish.Utils; +using BlubbFish.Utils.IoT.Connector; using IoTBot.Condition; -using IoTBot.Connector; namespace IoTBot { class ConditionWorker { private InIReader ini; private static ConditionWorker instance; private List conditions; - private Connector.Telegram telegram; + private Telegram telegram; public static ConditionWorker GetInstance(ADataBackend backend) { if (instance == null) { @@ -18,7 +18,7 @@ namespace IoTBot { return instance; } - internal void Run(Connector.Telegram telegram) { + internal void Run(Telegram telegram) { this.telegram = telegram; } diff --git a/IoT-Bot/IoT-Bot/Connector/Mosquitto.cs b/IoT-Bot/IoT-Bot/Connector/Mosquitto.cs deleted file mode 100644 index f3bf4a4..0000000 --- a/IoT-Bot/IoT-Bot/Connector/Mosquitto.cs +++ /dev/null @@ -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 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 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 - } -} diff --git a/IoT-Bot/IoT-Bot/Connector/Mqtt.cs b/IoT-Bot/IoT-Bot/Connector/Mqtt.cs deleted file mode 100644 index f12dc34..0000000 --- a/IoT-Bot/IoT-Bot/Connector/Mqtt.cs +++ /dev/null @@ -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 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 - } -} diff --git a/IoT-Bot/IoT-Bot/Connector/Telegram.cs b/IoT-Bot/IoT-Bot/Connector/Telegram.cs deleted file mode 100644 index 973c923..0000000 --- a/IoT-Bot/IoT-Bot/Connector/Telegram.cs +++ /dev/null @@ -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; - } - } - } -} diff --git a/IoT-Bot/IoT-Bot/IoT-Bot.csproj b/IoT-Bot/IoT-Bot/IoT-Bot.csproj index f2fc0e6..588acdc 100644 --- a/IoT-Bot/IoT-Bot/IoT-Bot.csproj +++ b/IoT-Bot/IoT-Bot/IoT-Bot.csproj @@ -9,9 +9,10 @@ Properties MqttToTelegram MqttToTelegram - v4.5.2 + v4.6.2 512 true + AnyCPU @@ -32,50 +33,12 @@ prompt 4 - - - ..\packages\M2Mqtt.4.3.0.0\lib\net45\M2Mqtt.Net.dll - True - - - ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll - True - - - - - - - - ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll - True - - - - - - - - - ..\packages\Telegram.Bot.13.1.0\lib\netstandard1.1\Telegram.Bot.dll - True - - - - - - - - - - - @@ -84,12 +47,15 @@ + + {b870e4d5-6806-4a0b-b233-8907eedc5afc} + Utils-IoT + {fac8ce64-bf13-4ece-8097-aeb5dd060098} Utils -