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
-