[NF] First usable Version (Trigger)
This commit is contained in:
parent
2791d7efd0
commit
6c841e9b5e
24
IoT-Bot.sln
24
IoT-Bot.sln
@ -1,7 +1,7 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26730.16
|
||||
VisualStudioVersion = 15.0.27004.2010
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IoT-Bot", "IoT-Bot\IoT-Bot.csproj", "{89077643-B472-419F-8EAB-56B9E2D13ABC}"
|
||||
EndProject
|
||||
@ -9,7 +9,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils-IoT", "..\Utils\IoT\U
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils", "..\Utils\Utils\Utils.csproj", "{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}"
|
||||
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
|
||||
Global
|
||||
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}.Release|Any CPU.ActiveCfg = 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
|
||||
{166258ED-CB3D-43F5-8E8D-3A993B64D022}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{166258ED-CB3D-43F5-8E8D-3A993B64D022}.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}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{91A14CD2-2940-4500-8193-56D37EDDDBAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{91A14CD2-2940-4500-8193-56D37EDDDBAA}.Release|Any CPU.ActiveCfg = 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
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -1,77 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BlubbFish.Utils.IoT.Connector;
|
||||
using BlubbFish.Utils.IoT.Sensor;
|
||||
using BlubbFish.Utils.IoT.Events;
|
||||
using BlubbFish.Utils.IoT.JsonSensor;
|
||||
|
||||
namespace IoTBot.Condition {
|
||||
abstract class ACondition {
|
||||
protected ASensor sensor;
|
||||
protected AJsonSensor sensor;
|
||||
protected Dictionary<String, String> settings;
|
||||
protected String name;
|
||||
protected ADataBackend data;
|
||||
protected AUserBackend user;
|
||||
protected Dictionary<String, ABackend> backends;
|
||||
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.name = name;
|
||||
this.data = data;
|
||||
this.user = user;
|
||||
this.backends = backends;
|
||||
this.sensor = sensor;
|
||||
}
|
||||
|
||||
public void Attach() {
|
||||
if(this.sensor != null) {
|
||||
this.sensor.Update += this.Sensor_Update;
|
||||
this.sensor.Update += this.SensorUpdate;
|
||||
}
|
||||
switch (this.settings["source"].ToLower()) {
|
||||
case "user":
|
||||
if(this.user != null) {
|
||||
this.user.MessageIncomming += this.User_Update;
|
||||
}
|
||||
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;
|
||||
if(this.settings.ContainsKey("source") && this.backends.ContainsKey(this.settings["source"])) {
|
||||
this.backends[this.settings["source"]].MessageIncomming += this.BackendUpdate;
|
||||
}
|
||||
if (this.settings.ContainsKey("target") && this.backends.ContainsKey(this.settings["target"])) {
|
||||
this.target_backend = this.backends[this.settings["target"]];
|
||||
}
|
||||
}
|
||||
|
||||
protected void Send(String message = "", String topic = "") {
|
||||
protected virtual void Send(String message = "", String topic = "") {
|
||||
if(message == "") {
|
||||
message = this.settings["target_message"];
|
||||
}
|
||||
if(topic == "") {
|
||||
topic = this.settings["target_topic"];
|
||||
}
|
||||
switch (this.settings["target"].ToLower()) {
|
||||
case "user":
|
||||
this.user.Send(message);
|
||||
break;
|
||||
case "data":
|
||||
this.data.Send(topic, message);
|
||||
break;
|
||||
case "sensor":
|
||||
//this.sensor.Set(message);
|
||||
break;
|
||||
if(this.target_backend != null) {
|
||||
if(this.target_backend is ADataBackend) {
|
||||
((ADataBackend)this.target_backend).Send(topic, message);
|
||||
}
|
||||
if(this.target_backend is AUserBackend) {
|
||||
((AUserBackend)this.target_backend).Send(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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, ASensor sensor, ADataBackend data, AUserBackend user) {
|
||||
public static ACondition GetInstance(String name, Dictionary<String, String> settings, AJsonSensor sensor, Dictionary<String, ABackend> backends) {
|
||||
String object_condition = "IoTBot.Condition." + Char.ToUpper(settings["type"][0]) + settings["type"].Substring(1).ToLower();
|
||||
Type t = null;
|
||||
try {
|
||||
@ -79,7 +60,7 @@ namespace IoTBot.Condition {
|
||||
} catch(TypeLoadException) {
|
||||
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 });
|
||||
}
|
||||
}
|
||||
}
|
@ -1,31 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BlubbFish.Utils.IoT.Connector;
|
||||
using BlubbFish.Utils.IoT.Sensor;
|
||||
using BlubbFish.Utils.IoT.Events;
|
||||
using BlubbFish.Utils.IoT.JsonSensor;
|
||||
|
||||
namespace IoTBot.Condition {
|
||||
class Edge : ACondition {
|
||||
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();
|
||||
}
|
||||
|
||||
protected override void Sensor_Update(Object sender, EventArgs e) {
|
||||
if(this.sensor.Datatypes == ASensor.Types.Bool) {
|
||||
protected override void SensorUpdate(Object sender, EventArgs e) {
|
||||
if(this.sensor.Datatypes == AJsonSensor.Types.Bool) {
|
||||
if(this.sensor.GetBool == Boolean.Parse(this.settings["sensor_value"]) && this.histBool != this.sensor.GetBool) {
|
||||
this.histBool = this.sensor.GetBool;
|
||||
this.user.Send("Jemand ist DA!");
|
||||
//this.user.Send("Jemand ist DA!");
|
||||
} else {
|
||||
this.histBool = this.sensor.GetBool;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void User_Update(Object sender, UserMessageEventArgs e) {
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,33 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BlubbFish.IoT.Zway;
|
||||
using BlubbFish.IoT.Zway.Devices.CommandClasses;
|
||||
using BlubbFish.Utils.IoT.Connector;
|
||||
using BlubbFish.Utils.IoT.Sensor;
|
||||
using BlubbFish.Utils.IoT.Events;
|
||||
using BlubbFish.Utils.IoT.JsonSensor;
|
||||
|
||||
namespace IoTBot.Condition {
|
||||
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) {
|
||||
this.zw = new ZwayController("10.100.0.214", "admin", "");
|
||||
this.zw.Update += this.Zw_Update;
|
||||
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.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());
|
||||
}
|
||||
}*/
|
||||
|
||||
protected override void Data_Update(Object sender, MqttEventArgs e) {
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
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") {
|
||||
protected override void BackendUpdate(Object sender, BackendEvent e) {
|
||||
if (e.Message == "/start") {
|
||||
this.Send("Hallo zurück! Ich kann aktuell die Befehle /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) {
|
||||
if (message == "/schalter") {
|
||||
/*if (message == "/schalter") {
|
||||
this.user.Send("Was soll ich tun?", new String[] { "/schalter einschalten", "/schalter ausschalten", "/schalter status" });
|
||||
}
|
||||
if(message == "/schalter status") {
|
||||
@ -87,7 +82,7 @@ namespace IoTBot.Condition {
|
||||
this.user.Send("Ausschalten von " + item.Name + " " + (item.Level ? "nicht " : "") + "erfolgreich");
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BlubbFish.Utils.IoT.Connector;
|
||||
using BlubbFish.Utils.IoT.Sensor;
|
||||
using BlubbFish.Utils.IoT.Events;
|
||||
using BlubbFish.Utils.IoT.JsonSensor;
|
||||
|
||||
namespace IoTBot.Condition {
|
||||
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 Data_Update(Object sender, MqttEventArgs e) {
|
||||
//throw new NotImplementedException();
|
||||
protected override void BackendUpdate(Object sender, BackendEvent e) {
|
||||
|
||||
}
|
||||
|
||||
protected override void Sensor_Update(Object sender, EventArgs e) {
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override void User_Update(Object sender, UserMessageEventArgs e) {
|
||||
if (e.Message == this.settings["trigger"]) {
|
||||
protected override void SensorUpdate(Object sender, EventArgs e) {
|
||||
this.Send();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BlubbFish.Utils.IoT.Connector;
|
||||
using BlubbFish.Utils.IoT.Sensor;
|
||||
using BlubbFish.Utils.IoT.JsonSensor;
|
||||
using IoTBot.Condition;
|
||||
|
||||
namespace IoTBot {
|
||||
class ConditionWorker {
|
||||
private List<ACondition> conditions = new List<ACondition>();
|
||||
private readonly ADataBackend data;
|
||||
private readonly AUserBackend user;
|
||||
private readonly Dictionary<String, ABackend> backends;
|
||||
|
||||
public ConditionWorker(ADataBackend data, AUserBackend user) {
|
||||
this.data = data;
|
||||
this.user = user;
|
||||
public ConditionWorker(Dictionary<String, ABackend> backends) {
|
||||
this.backends = backends;
|
||||
}
|
||||
|
||||
public void SetCondition(String name, Dictionary<String, String> settings) {
|
||||
ASensor sensor = null;
|
||||
AJsonSensor sensor = null;
|
||||
if (settings.ContainsKey("sensor_type")) {
|
||||
Dictionary<String, String> sensor_settings = new Dictionary<String, String>();
|
||||
foreach (KeyValuePair<String, String> item in settings) {
|
||||
@ -24,9 +22,9 @@ namespace IoTBot {
|
||||
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() {
|
||||
@ -34,5 +32,13 @@ namespace IoTBot {
|
||||
item.Attach();
|
||||
}
|
||||
}
|
||||
|
||||
internal void Stop() {
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
internal void Dispose() {
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
11
IoT-Bot/Helper.cs
Normal file
11
IoT-Bot/Helper.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>IoTBot</RootNamespace>
|
||||
<AssemblyName>IoTBot</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<TargetFrameworkProfile />
|
||||
@ -39,16 +39,33 @@
|
||||
<Compile Include="Condition\Edge.cs" />
|
||||
<Compile Include="Condition\TelegramBot.cs" />
|
||||
<Compile Include="Condition\Trigger.cs" />
|
||||
<None Include="dpkg\control" />
|
||||
<Compile Include="Helper.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<None Include="dpkg\create-dkpg.bat" />
|
||||
<None Include="dpkg\make-deb.sh" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="condition.ini.example" />
|
||||
<None Include="packages.config" />
|
||||
<None Include="settings.ini.example" />
|
||||
<None Include="config-example\condition.conf.example">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="config-example\data.conf.example">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="config-example\user.conf.example">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</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">
|
||||
<Project>{b870e4d5-6806-4a0b-b233-8907eedc5afc}</Project>
|
||||
<Name>Utils-IoT</Name>
|
||||
@ -57,12 +74,12 @@
|
||||
<Project>{fac8ce64-bf13-4ece-8097-aeb5dd060098}</Project>
|
||||
<Name>Utils</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Zway\Zway\Zway.csproj">
|
||||
<Project>{166258ed-cb3d-43f5-8e8d-3a993b64d022}</Project>
|
||||
<Name>Zway</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<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.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
|
@ -1,53 +1,83 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BlubbFish.Utils;
|
||||
using BlubbFish.Utils.IoT.Connector;
|
||||
using BlubbFish.Utils.IoT.Events;
|
||||
|
||||
namespace IoTBot {
|
||||
class Program {
|
||||
static void Main(String[] 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");
|
||||
static void Main(String[] args) => new Program(args);
|
||||
|
||||
ConditionWorker worker = new ConditionWorker(mqtt, telegram);
|
||||
foreach (String section in condition_settings.GetSections()) {
|
||||
worker.SetCondition(section, condition_settings.GetSection(section));
|
||||
private Dictionary<String, ABackend> backends = new Dictionary<String, ABackend>();
|
||||
private ConditionWorker worker;
|
||||
|
||||
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) {
|
||||
mqtt.MessageIncomming += Mqtt_MessageIncomming;
|
||||
mqtt.MessageSending += Mqtt_MessageSending;
|
||||
private void SetupWorker() {
|
||||
this.worker = new ConditionWorker(this.backends);
|
||||
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();
|
||||
|
||||
while(true) {
|
||||
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;
|
||||
}
|
||||
|
||||
private void WaitForShutdown() {
|
||||
while (true) {
|
||||
System.Threading.Thread.Sleep(100);
|
||||
if(Console.KeyAvailable) {
|
||||
ConsoleKeyInfo key = Console.ReadKey(false);
|
||||
if(key.Key == ConsoleKey.Escape) {
|
||||
if (Console.KeyAvailable) {
|
||||
String a = Console.ReadLine();
|
||||
if (a.EndsWith("/exit")) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
private static void Mqtt_MessageSending(Object sender, MqttEventArgs e) {
|
||||
Console.WriteLine("-> [" + DateTime.Now.ToUniversalTime() + "] MQTT: " + e.Message + " on " + e.Topic);
|
||||
#region ConsoleOutput
|
||||
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) {
|
||||
Console.WriteLine("-> [" + e.Date.ToUniversalTime() + "] Telegram: " + e.Message + " on " + e.UserId);
|
||||
private void Event_Outgoing(Object sender, BackendEvent e) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,17 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Resources;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
||||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
||||
// die einer Assembly zugeordnet sind.
|
||||
[assembly: AssemblyTitle("MqttToTelegram")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyTitle("Iot-Bot")]
|
||||
[assembly: AssemblyDescription("Is a Bot for connecting IoT-Devices together")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("MqttToTelegram")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCompany("BlubbFish")]
|
||||
[assembly: AssemblyProduct("IoT-Bot")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2017 - 08.05.2018")]
|
||||
[assembly: AssemblyTrademark("BlubbFish")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar
|
||||
@ -27,10 +27,10 @@ using System.Runtime.InteropServices;
|
||||
// Hauptversion
|
||||
// Nebenversion
|
||||
// Buildnummer
|
||||
// Revision
|
||||
//
|
||||
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
|
||||
// übernehmen, indem Sie "*" eingeben:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: AssemblyVersion("1.0.1")]
|
||||
[assembly: AssemblyFileVersion("1.0.1")]
|
||||
[assembly: NeutralResourcesLanguage("de-DE")]
|
BIN
IoT-Bot/bin/Release/ConnectorDataMqtt.dll
Normal file
BIN
IoT-Bot/bin/Release/ConnectorDataMqtt.dll
Normal file
Binary file not shown.
BIN
IoT-Bot/bin/Release/IoTBot.exe
Normal file
BIN
IoT-Bot/bin/Release/IoTBot.exe
Normal file
Binary file not shown.
BIN
IoT-Bot/bin/Release/M2Mqtt.dll
Normal file
BIN
IoT-Bot/bin/Release/M2Mqtt.dll
Normal file
Binary file not shown.
BIN
IoT-Bot/bin/Release/Utils-IoT.dll
Normal file
BIN
IoT-Bot/bin/Release/Utils-IoT.dll
Normal file
Binary file not shown.
BIN
IoT-Bot/bin/Release/Utils.dll
Normal file
BIN
IoT-Bot/bin/Release/Utils.dll
Normal file
Binary file not shown.
@ -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
|
3
IoT-Bot/bin/Release/config-example/data.conf.example
Normal file
3
IoT-Bot/bin/Release/config-example/data.conf.example
Normal file
@ -0,0 +1,3 @@
|
||||
[mqtt]
|
||||
type=mqtt
|
||||
server=localhost
|
4
IoT-Bot/bin/Release/config-example/user.conf.example
Normal file
4
IoT-Bot/bin/Release/config-example/user.conf.example
Normal file
@ -0,0 +1,4 @@
|
||||
[user]
|
||||
type=telegram
|
||||
telegram-key=ABCDEFGH
|
||||
chatid=1234
|
BIN
IoT-Bot/bin/Release/litjson.dll
Normal file
BIN
IoT-Bot/bin/Release/litjson.dll
Normal file
Binary file not shown.
BIN
IoT-Bot/bin/iotbot_1.0-1.deb
Normal file
BIN
IoT-Bot/bin/iotbot_1.0-1.deb
Normal file
Binary file not shown.
8
IoT-Bot/config-example/condition.conf.example
Normal file
8
IoT-Bot/config-example/condition.conf.example
Normal 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
|
3
IoT-Bot/config-example/data.conf.example
Normal file
3
IoT-Bot/config-example/data.conf.example
Normal file
@ -0,0 +1,3 @@
|
||||
[mqtt]
|
||||
type=mqtt
|
||||
server=localhost
|
4
IoT-Bot/config-example/user.conf.example
Normal file
4
IoT-Bot/config-example/user.conf.example
Normal file
@ -0,0 +1,4 @@
|
||||
[user]
|
||||
type=telegram
|
||||
telegram-key=ABCDEFGH
|
||||
chatid=1234
|
10
IoT-Bot/dpkg/control
Normal file
10
IoT-Bot/dpkg/control
Normal 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
|
6
IoT-Bot/dpkg/create-dkpg.bat
Normal file
6
IoT-Bot/dpkg/create-dkpg.bat
Normal 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
25
IoT-Bot/dpkg/make-deb.sh
Normal 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
|
Loading…
Reference in New Issue
Block a user