[NF] First usable Version (Trigger)

This commit is contained in:
BlubbFish 2018-05-08 18:07:48 +00:00
parent 2791d7efd0
commit 6c841e9b5e
26 changed files with 264 additions and 152 deletions

View File

@ -1,7 +1,7 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15 # Visual Studio 15
VisualStudioVersion = 15.0.26730.16 VisualStudioVersion = 15.0.27004.2010
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IoT-Bot", "IoT-Bot\IoT-Bot.csproj", "{89077643-B472-419F-8EAB-56B9E2D13ABC}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IoT-Bot", "IoT-Bot\IoT-Bot.csproj", "{89077643-B472-419F-8EAB-56B9E2D13ABC}"
EndProject EndProject
@ -9,7 +9,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils-IoT", "..\Utils\IoT\U
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils", "..\Utils\Utils\Utils.csproj", "{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils", "..\Utils\Utils\Utils.csproj", "{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Zway", "..\Zway\Zway\Zway.csproj", "{166258ED-CB3D-43F5-8E8D-3A993B64D022}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "litjson_4.7.1", "..\Librarys\litjson\litjson\litjson_4.7.1.csproj", "{91A14CD2-2940-4500-8193-56D37EDDDBAA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "M2Mqtt_4.7.1", "..\Librarys\mqtt\M2Mqtt\M2Mqtt_4.7.1.csproj", "{A11AEF5A-B246-4FE8-8330-06DB73CC8074}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConnectorDataMqtt", "..\Utils\IoT\Connector\Data\Mqtt\ConnectorDataMqtt.csproj", "{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -29,10 +33,18 @@ Global
{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Debug|Any CPU.Build.0 = 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.ActiveCfg = Release|Any CPU
{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Release|Any CPU.Build.0 = Release|Any CPU {FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Release|Any CPU.Build.0 = Release|Any CPU
{166258ED-CB3D-43F5-8E8D-3A993B64D022}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {91A14CD2-2940-4500-8193-56D37EDDDBAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{166258ED-CB3D-43F5-8E8D-3A993B64D022}.Debug|Any CPU.Build.0 = Debug|Any CPU {91A14CD2-2940-4500-8193-56D37EDDDBAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{166258ED-CB3D-43F5-8E8D-3A993B64D022}.Release|Any CPU.ActiveCfg = Release|Any CPU {91A14CD2-2940-4500-8193-56D37EDDDBAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{166258ED-CB3D-43F5-8E8D-3A993B64D022}.Release|Any CPU.Build.0 = Release|Any CPU {91A14CD2-2940-4500-8193-56D37EDDDBAA}.Release|Any CPU.Build.0 = Release|Any CPU
{A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Release|Any CPU.Build.0 = Release|Any CPU
{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -1,77 +1,58 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using BlubbFish.Utils.IoT.Connector; using BlubbFish.Utils.IoT.Connector;
using BlubbFish.Utils.IoT.Sensor; using BlubbFish.Utils.IoT.Events;
using BlubbFish.Utils.IoT.JsonSensor;
namespace IoTBot.Condition { namespace IoTBot.Condition {
abstract class ACondition { abstract class ACondition {
protected ASensor sensor; protected AJsonSensor sensor;
protected Dictionary<String, String> settings; protected Dictionary<String, String> settings;
protected String name; protected String name;
protected ADataBackend data; protected Dictionary<String, ABackend> backends;
protected AUserBackend user; protected ABackend target_backend;
protected ACondition(String name, Dictionary<String, String> settings, ASensor sensor, ADataBackend data, AUserBackend user) { protected ACondition(String name, Dictionary<String, String> settings, AJsonSensor sensor, Dictionary<String, ABackend> backends) {
this.settings = settings; this.settings = settings;
this.name = name; this.name = name;
this.data = data; this.backends = backends;
this.user = user;
this.sensor = sensor; this.sensor = sensor;
} }
public void Attach() { public void Attach() {
if(this.sensor != null) { if(this.sensor != null) {
this.sensor.Update += this.Sensor_Update; this.sensor.Update += this.SensorUpdate;
} }
switch (this.settings["source"].ToLower()) { if(this.settings.ContainsKey("source") && this.backends.ContainsKey(this.settings["source"])) {
case "user": this.backends[this.settings["source"]].MessageIncomming += this.BackendUpdate;
if(this.user != null) { }
this.user.MessageIncomming += this.User_Update; if (this.settings.ContainsKey("target") && this.backends.ContainsKey(this.settings["target"])) {
} this.target_backend = this.backends[this.settings["target"]];
break;
case "data":
if(this.data != null) {
this.data.MessageIncomming += this.Data_Update;
}
break;
case "both":
if (this.user != null) {
this.user.MessageIncomming += this.User_Update;
}
if (this.data != null) {
this.data.MessageIncomming += this.Data_Update;
}
break;
} }
} }
protected void Send(String message = "", String topic = "") { protected virtual void Send(String message = "", String topic = "") {
if(message == "") { if(message == "") {
message = this.settings["target_message"]; message = this.settings["target_message"];
} }
if(topic == "") { if(topic == "") {
topic = this.settings["target_topic"]; topic = this.settings["target_topic"];
} }
switch (this.settings["target"].ToLower()) { if(this.target_backend != null) {
case "user": if(this.target_backend is ADataBackend) {
this.user.Send(message); ((ADataBackend)this.target_backend).Send(topic, message);
break; }
case "data": if(this.target_backend is AUserBackend) {
this.data.Send(topic, message); ((AUserBackend)this.target_backend).Send(message);
break; }
case "sensor":
//this.sensor.Set(message);
break;
} }
} }
protected abstract void Data_Update(Object sender, MqttEventArgs e); protected abstract void BackendUpdate(Object sender, BackendEvent e);
protected abstract void User_Update(Object sender, UserMessageEventArgs e); protected abstract void SensorUpdate(Object sender, EventArgs e);
protected abstract void Sensor_Update(Object sender, EventArgs e); public static ACondition GetInstance(String name, Dictionary<String, String> settings, AJsonSensor sensor, Dictionary<String, ABackend> backends) {
public static ACondition GetInstance(String name, Dictionary<String, String> settings, ASensor sensor, ADataBackend data, AUserBackend user) {
String object_condition = "IoTBot.Condition." + Char.ToUpper(settings["type"][0]) + settings["type"].Substring(1).ToLower(); String object_condition = "IoTBot.Condition." + Char.ToUpper(settings["type"][0]) + settings["type"].Substring(1).ToLower();
Type t = null; Type t = null;
try { try {
@ -79,7 +60,7 @@ namespace IoTBot.Condition {
} catch(TypeLoadException) { } catch(TypeLoadException) {
throw new ArgumentException("condition.ini: " + settings["type"] + " is not a Sensor"); throw new ArgumentException("condition.ini: " + settings["type"] + " is not a Sensor");
} }
return (ACondition)t.GetConstructor(new Type[] { typeof(String), typeof(Dictionary<String, String>), typeof(ASensor), typeof(ADataBackend), typeof(AUserBackend) }).Invoke(new Object[] { name, settings, sensor, data, user }); return (ACondition)t.GetConstructor(new Type[] { typeof(String), typeof(Dictionary<String, String>), typeof(AJsonSensor), typeof(Dictionary<String, ABackend>) }).Invoke(new Object[] { name, settings, sensor, backends });
} }
} }
} }

View File

@ -1,31 +1,28 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using BlubbFish.Utils.IoT.Connector; using BlubbFish.Utils.IoT.Connector;
using BlubbFish.Utils.IoT.Sensor; using BlubbFish.Utils.IoT.Events;
using BlubbFish.Utils.IoT.JsonSensor;
namespace IoTBot.Condition { namespace IoTBot.Condition {
class Edge : ACondition { class Edge : ACondition {
private Boolean histBool; private Boolean histBool;
public Edge(String name, Dictionary<String, String> settings, ASensor sensor, ADataBackend data, AUserBackend user) : base(name, settings, sensor, data, user) { } public Edge(String name, Dictionary<String, String> settings, AJsonSensor sensor, Dictionary<String, ABackend> backends) : base(name, settings, sensor, backends) { }
protected override void Data_Update(Object sender, MqttEventArgs e) { protected override void BackendUpdate(Object sender, BackendEvent e) {
//throw new NotImplementedException(); //throw new NotImplementedException();
} }
protected override void Sensor_Update(Object sender, EventArgs e) { protected override void SensorUpdate(Object sender, EventArgs e) {
if(this.sensor.Datatypes == ASensor.Types.Bool) { if(this.sensor.Datatypes == AJsonSensor.Types.Bool) {
if(this.sensor.GetBool == Boolean.Parse(this.settings["sensor_value"]) && this.histBool != this.sensor.GetBool) { if(this.sensor.GetBool == Boolean.Parse(this.settings["sensor_value"]) && this.histBool != this.sensor.GetBool) {
this.histBool = this.sensor.GetBool; this.histBool = this.sensor.GetBool;
this.user.Send("Jemand ist DA!"); //this.user.Send("Jemand ist DA!");
} else { } else {
this.histBool = this.sensor.GetBool; this.histBool = this.sensor.GetBool;
} }
} }
} }
protected override void User_Update(Object sender, UserMessageEventArgs e) {
//throw new NotImplementedException();
}
} }
} }

View File

@ -1,33 +1,24 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using BlubbFish.IoT.Zway;
using BlubbFish.IoT.Zway.Devices.CommandClasses;
using BlubbFish.Utils.IoT.Connector; using BlubbFish.Utils.IoT.Connector;
using BlubbFish.Utils.IoT.Sensor; using BlubbFish.Utils.IoT.Events;
using BlubbFish.Utils.IoT.JsonSensor;
namespace IoTBot.Condition { namespace IoTBot.Condition {
class Telegrambot : ACondition { class Telegrambot : ACondition {
private ZwayController zw; //private ZwayController zw;
public Telegrambot(String name, Dictionary<String, String> settings, ASensor sensor, ADataBackend data, AUserBackend user) : base(name, settings, sensor, data, user) { public Telegrambot(String name, Dictionary<String, String> settings, AJsonSensor sensor, Dictionary<String, ABackend> backends) : base(name, settings, sensor, backends) {
this.zw = new ZwayController("10.100.0.214", "admin", ""); //this.zw = new ZwayController("10.100.0.214", "admin", "");
this.zw.Update += this.Zw_Update; //this.zw.Update += this.Zw_Update;
} }
private void Zw_Update(Object sender, BlubbFish.IoT.Zway.Events.DeviceUpdateEvent e) { /*private void Zw_Update(Object sender, BlubbFish.IoT.Zway.Events.DeviceUpdateEvent e) {
Console.WriteLine("-> ZW: "+sender.ToString()); Console.WriteLine("-> ZW: "+sender.ToString());
} }*/
protected override void Data_Update(Object sender, MqttEventArgs e) { protected override void BackendUpdate(Object sender, BackendEvent e) {
//throw new NotImplementedException(); if (e.Message == "/start") {
}
protected override void Sensor_Update(Object sender, EventArgs e) {
//throw new NotImplementedException();
}
protected override void User_Update(Object sender, UserMessageEventArgs e) {
if(e.Message == "/start") {
this.Send("Hallo zurück! Ich kann aktuell die Befehle /schalter"); this.Send("Hallo zurück! Ich kann aktuell die Befehle /schalter");
} }
if (e.Message.StartsWith("/schalter")) { if (e.Message.StartsWith("/schalter")) {
@ -35,8 +26,12 @@ namespace IoTBot.Condition {
} }
} }
protected override void SensorUpdate(Object sender, EventArgs e) {
//throw new NotImplementedException();
}
private void BotSchalter(String message) { private void BotSchalter(String message) {
if (message == "/schalter") { /*if (message == "/schalter") {
this.user.Send("Was soll ich tun?", new String[] { "/schalter einschalten", "/schalter ausschalten", "/schalter status" }); this.user.Send("Was soll ich tun?", new String[] { "/schalter einschalten", "/schalter ausschalten", "/schalter status" });
} }
if(message == "/schalter status") { if(message == "/schalter status") {
@ -87,7 +82,7 @@ namespace IoTBot.Condition {
this.user.Send("Ausschalten von " + item.Name + " " + (item.Level ? "nicht " : "") + "erfolgreich"); this.user.Send("Ausschalten von " + item.Name + " " + (item.Level ? "nicht " : "") + "erfolgreich");
} }
} }
} }*/
} }
} }
} }

View File

@ -1,27 +1,19 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BlubbFish.Utils.IoT.Connector; using BlubbFish.Utils.IoT.Connector;
using BlubbFish.Utils.IoT.Sensor; using BlubbFish.Utils.IoT.Events;
using BlubbFish.Utils.IoT.JsonSensor;
namespace IoTBot.Condition { namespace IoTBot.Condition {
class Trigger : ACondition { class Trigger : ACondition {
public Trigger(String name, Dictionary<String, String> settings, ASensor sensor, ADataBackend data, AUserBackend user) : base(name, settings, sensor, data, user) { } public Trigger(String name, Dictionary<String, String> settings, AJsonSensor sensor, Dictionary<String, ABackend> backends) : base(name, settings, sensor, backends) { }
protected override void BackendUpdate(Object sender, BackendEvent e) {
protected override void Data_Update(Object sender, MqttEventArgs e) {
//throw new NotImplementedException();
} }
protected override void Sensor_Update(Object sender, EventArgs e) { protected override void SensorUpdate(Object sender, EventArgs e) {
//throw new NotImplementedException();
}
protected override void User_Update(Object sender, UserMessageEventArgs e) {
if (e.Message == this.settings["trigger"]) {
this.Send(); this.Send();
}
} }
} }
} }

View File

@ -1,22 +1,20 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using BlubbFish.Utils.IoT.Connector; using BlubbFish.Utils.IoT.Connector;
using BlubbFish.Utils.IoT.Sensor; using BlubbFish.Utils.IoT.JsonSensor;
using IoTBot.Condition; using IoTBot.Condition;
namespace IoTBot { namespace IoTBot {
class ConditionWorker { class ConditionWorker {
private List<ACondition> conditions = new List<ACondition>(); private List<ACondition> conditions = new List<ACondition>();
private readonly ADataBackend data; private readonly Dictionary<String, ABackend> backends;
private readonly AUserBackend user;
public ConditionWorker(ADataBackend data, AUserBackend user) { public ConditionWorker(Dictionary<String, ABackend> backends) {
this.data = data; this.backends = backends;
this.user = user;
} }
public void SetCondition(String name, Dictionary<String, String> settings) { public void SetCondition(String name, Dictionary<String, String> settings) {
ASensor sensor = null; AJsonSensor sensor = null;
if (settings.ContainsKey("sensor_type")) { if (settings.ContainsKey("sensor_type")) {
Dictionary<String, String> sensor_settings = new Dictionary<String, String>(); Dictionary<String, String> sensor_settings = new Dictionary<String, String>();
foreach (KeyValuePair<String, String> item in settings) { foreach (KeyValuePair<String, String> item in settings) {
@ -24,9 +22,9 @@ namespace IoTBot {
sensor_settings.Add(item.Key.Substring(7), item.Value); sensor_settings.Add(item.Key.Substring(7), item.Value);
} }
} }
sensor = ASensor.GetInstance(this.data, sensor_settings, name); sensor = AJsonSensor.GetInstance(this.backends, sensor_settings, name);
} }
this.conditions.Add(ACondition.GetInstance(name, settings, sensor, this.data, this.user)); this.conditions.Add(ACondition.GetInstance(name, settings, sensor, this.backends));
} }
public void Run() { public void Run() {
@ -34,5 +32,13 @@ namespace IoTBot {
item.Attach(); item.Attach();
} }
} }
internal void Stop() {
//throw new NotImplementedException();
}
internal void Dispose() {
//throw new NotImplementedException();
}
} }
} }

11
IoT-Bot/Helper.cs Normal file
View File

@ -0,0 +1,11 @@
using System;
namespace IoTBot {
class Helper {
internal static void WriteError(String text) {
Console.ForegroundColor = ConsoleColor.Red;
Console.Error.WriteLine("ERROR: " + text);
Console.ResetColor();
}
}
}

View File

@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>IoTBot</RootNamespace> <RootNamespace>IoTBot</RootNamespace>
<AssemblyName>IoTBot</AssemblyName> <AssemblyName>IoTBot</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion> <TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile /> <TargetFrameworkProfile />
@ -39,16 +39,33 @@
<Compile Include="Condition\Edge.cs" /> <Compile Include="Condition\Edge.cs" />
<Compile Include="Condition\TelegramBot.cs" /> <Compile Include="Condition\TelegramBot.cs" />
<Compile Include="Condition\Trigger.cs" /> <Compile Include="Condition\Trigger.cs" />
<None Include="dpkg\control" />
<Compile Include="Helper.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<None Include="dpkg\create-dkpg.bat" />
<None Include="dpkg\make-deb.sh" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="App.config" /> <None Include="config-example\condition.conf.example">
<None Include="condition.ini.example" /> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<None Include="packages.config" /> </None>
<None Include="settings.ini.example" /> <None Include="config-example\data.conf.example">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="config-example\user.conf.example">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\Librarys\litjson\litjson\litjson_4.7.1.csproj">
<Project>{91a14cd2-2940-4500-8193-56d37edddbaa}</Project>
<Name>litjson_4.7.1</Name>
</ProjectReference>
<ProjectReference Include="..\..\Utils\IoT\Connector\Data\Mqtt\ConnectorDataMqtt.csproj">
<Project>{ee6c8f68-ed46-4c1c-abdd-cfcdf75104f2}</Project>
<Name>ConnectorDataMqtt</Name>
</ProjectReference>
<ProjectReference Include="..\..\Utils\IoT\Utils-IoT.csproj"> <ProjectReference Include="..\..\Utils\IoT\Utils-IoT.csproj">
<Project>{b870e4d5-6806-4a0b-b233-8907eedc5afc}</Project> <Project>{b870e4d5-6806-4a0b-b233-8907eedc5afc}</Project>
<Name>Utils-IoT</Name> <Name>Utils-IoT</Name>
@ -57,12 +74,12 @@
<Project>{fac8ce64-bf13-4ece-8097-aeb5dd060098}</Project> <Project>{fac8ce64-bf13-4ece-8097-aeb5dd060098}</Project>
<Name>Utils</Name> <Name>Utils</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\..\Zway\Zway\Zway.csproj">
<Project>{166258ed-cb3d-43f5-8e8d-3a993b64d022}</Project>
<Name>Zway</Name>
</ProjectReference>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild"> <Target Name="BeforeBuild">

View File

@ -1,53 +1,83 @@
using System; using System;
using System.Collections.Generic;
using BlubbFish.Utils; using BlubbFish.Utils;
using BlubbFish.Utils.IoT.Connector; using BlubbFish.Utils.IoT.Connector;
using BlubbFish.Utils.IoT.Events;
namespace IoTBot { namespace IoTBot {
class Program { class Program {
static void Main(String[] args) { static void Main(String[] args) => new Program(args);
ADataBackend mqtt = ADataBackend.GetInstance(InIReader.GetInstance("settings.ini").GetSection("mqtt"));
AUserBackend telegram = AUserBackend.GetInstance(InIReader.GetInstance("settings.ini").GetSection("user"));
InIReader condition_settings = InIReader.GetInstance("condition.ini");
ConditionWorker worker = new ConditionWorker(mqtt, telegram); private Dictionary<String, ABackend> backends = new Dictionary<String, ABackend>();
foreach (String section in condition_settings.GetSections()) { private ConditionWorker worker;
worker.SetCondition(section, condition_settings.GetSection(section));
public Program(String[] args) {
InIReader.SetSearchPath(new List<String>() { "/etc/iotbot", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\iotbot" });
this.FindBackends("user", ABackend.BackendType.User);
this.FindBackends("data", ABackend.BackendType.Data);
this.SetupWorker();
this.worker.Run();
this.WaitForShutdown();
this.DisposeAll();
}
#region Private functions
private void FindBackends(String configfile, ABackend.BackendType t) {
foreach (String item in InIReader.GetInstance(configfile).GetSections(false)) {
try {
ABackend backend = ABackend.GetInstance(InIReader.GetInstance(configfile).GetSection(item), t);
backend.MessageIncomming += this.Event_Incomming;
backend.MessageSending += this.Event_Outgoing;
Console.WriteLine("Load Backend " + item + " from File " + configfile);
this.backends.Add(item, backend);
} catch (Exception e) {
Helper.WriteError(e.Message);
}
} }
}
if (mqtt != null) { private void SetupWorker() {
mqtt.MessageIncomming += Mqtt_MessageIncomming; this.worker = new ConditionWorker(this.backends);
mqtt.MessageSending += Mqtt_MessageSending; foreach (String section in InIReader.GetInstance("condition").GetSections()) {
this.worker.SetCondition(section, InIReader.GetInstance("condition").GetSection(section));
} }
telegram.MessageIncomming += Telegram_MessageIncomming; }
telegram.MessageSending += Telegram_MessageSending;
worker.Run(); private void DisposeAll() {
this.worker.Stop();
this.worker.Dispose();
foreach (KeyValuePair<String, ABackend> item in this.backends) {
item.Value.MessageIncomming -= this.Event_Incomming;
item.Value.MessageSending -= this.Event_Outgoing;
Console.WriteLine("Unload Backend " + item.Key);
item.Value.Dispose();
}
this.worker = null;
this.backends = null;
}
while(true) { private void WaitForShutdown() {
while (true) {
System.Threading.Thread.Sleep(100); System.Threading.Thread.Sleep(100);
if(Console.KeyAvailable) { if (Console.KeyAvailable) {
ConsoleKeyInfo key = Console.ReadKey(false); String a = Console.ReadLine();
if(key.Key == ConsoleKey.Escape) { if (a.EndsWith("/exit")) {
break; break;
} }
} }
} }
} }
#endregion
private static void Mqtt_MessageSending(Object sender, MqttEventArgs e) { #region ConsoleOutput
Console.WriteLine("-> [" + DateTime.Now.ToUniversalTime() + "] MQTT: " + e.Message + " on " + e.Topic); private void Event_Incomming(Object sender, BackendEvent e) {
Console.WriteLine("<- [" + e.Date + "] "+e.Label+": " + e.Message + " on " + e.From.ToString());
} }
private static void Telegram_MessageSending(Object sender, UserMessageEventArgs e) { private void Event_Outgoing(Object sender, BackendEvent e) {
Console.WriteLine("-> [" + e.Date.ToUniversalTime() + "] Telegram: " + e.Message + " on " + e.UserId); Console.WriteLine("-> [" + e.Date + "] " + e.Label + ": " + e.Message + " on " + e.From.ToString());
} }
#endregion
private static void Telegram_MessageIncomming(Object sender, UserMessageEventArgs e) {
Console.WriteLine("<- [" + e.Date.ToUniversalTime() + "] Telegram: " + e.Message + " on " + e.UserId);
}
private static void Mqtt_MessageIncomming(Object sender, MqttEventArgs e) {
Console.WriteLine("<- [" + DateTime.Now.ToUniversalTime() + "] MQTT: " + e.Message + " on " + e.Topic);
}
} }
} }

View File

@ -1,17 +1,17 @@
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices; using System.Resources;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// Allgemeine Informationen über eine Assembly werden über die folgenden // Allgemeine Informationen über eine Assembly werden über die folgenden
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, // Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
// die einer Assembly zugeordnet sind. // die einer Assembly zugeordnet sind.
[assembly: AssemblyTitle("MqttToTelegram")] [assembly: AssemblyTitle("Iot-Bot")]
[assembly: AssemblyDescription("")] [assembly: AssemblyDescription("Is a Bot for connecting IoT-Devices together")]
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")] [assembly: AssemblyCompany("BlubbFish")]
[assembly: AssemblyProduct("MqttToTelegram")] [assembly: AssemblyProduct("IoT-Bot")]
[assembly: AssemblyCopyright("Copyright © 2017")] [assembly: AssemblyCopyright("Copyright © 2017 - 08.05.2018")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("BlubbFish")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar // Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar
@ -27,10 +27,10 @@ using System.Runtime.InteropServices;
// Hauptversion // Hauptversion
// Nebenversion // Nebenversion
// Buildnummer // Buildnummer
// Revision
// //
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben: // übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyVersion("1.0.1")]
[assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.1")]
[assembly: NeutralResourcesLanguage("de-DE")]

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,8 @@
[test]
type=Trigger
target=mqtt
target_message={"enable": true}
target_topic=/test/1
sensor_type=Power
sensor_backend=mqtt
sensor_topic=/power/msg

View File

@ -0,0 +1,3 @@
[mqtt]
type=mqtt
server=localhost

View File

@ -0,0 +1,4 @@
[user]
type=telegram
telegram-key=ABCDEFGH
chatid=1234

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,8 @@
[test]
type=Trigger
target=mqtt
target_message={"enable": true}
target_topic=/test/1
sensor_type=Power
sensor_backend=mqtt
sensor_topic=/power/msg

View File

@ -0,0 +1,3 @@
[mqtt]
type=mqtt
server=localhost

View File

@ -0,0 +1,4 @@
[user]
type=telegram
telegram-key=ABCDEFGH
chatid=1234

10
IoT-Bot/dpkg/control Normal file
View File

@ -0,0 +1,10 @@
Package: iotbot
Version: x.x-x
Section: base
Priority: optional
Architecture: i386
Depends: mono-complete (>= 5.4.1.6)
Maintainer: BlubbFish <dev@blubbfish.net>
Description: Iot-Bot
IoT-Bot connects different IoT-Devices
together, with filters

View File

@ -0,0 +1,6 @@
set /P maj=Enter Major Version:
set /P min=Enter Minor Version:
set /P bui=Enter Build Version:
bash.exe -c "./make-deb.sh %maj% %min% %bui%"
pause

25
IoT-Bot/dpkg/make-deb.sh Normal file
View File

@ -0,0 +1,25 @@
#!/bin/bash
WORKDIR="/home/blubb"
ROOT="$WORKDIR/deb"
OUTPUT="../bin/Release"
EXEC="$ROOT/usr/local/bin/iotbot"
CONFIG="$ROOT/etc/iotbot"
DEBIAN="$ROOT/DEBIAN"
VMAJOR=$1
VMINOR=$2
VBUILD=$3
mkdir -p $EXEC
mkdir -p $CONFIG
mkdir -p $DEBIAN
cp control $DEBIAN
sed -i s/Version:\ x\.x-x/"Version: $VMAJOR.$VMINOR-$VBUILD"/ $DEBIAN/control
chmod 755 $DEBIAN -R
cp $OUTPUT/*.exe $EXEC/
cp $OUTPUT/*.dll $EXEC/
cp $OUTPUT/config-example/* $CONFIG
dpkg-deb --build $ROOT
mv $WORKDIR/deb.deb ../bin/"iotbot_$VMAJOR.$VMINOR-$VBUILD.deb"
rm $WORKDIR/deb -r