Projekt Umbenannt und Ausführbar gemacht

This commit is contained in:
BlubbFish 2017-10-01 21:56:00 +00:00
commit 4889d3769b
10 changed files with 340 additions and 0 deletions

22
IoT-Bot.sln Normal file
View File

@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IoT-Bot", "IoT-Bot\IoT-Bot.csproj", "{89077643-B472-419F-8EAB-56B9E2D13ABC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{89077643-B472-419F-8EAB-56B9E2D13ABC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

6
IoT-Bot/App.config Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>

View File

@ -0,0 +1,37 @@
using Dashboard.Sensor;
using System;
using System.Collections.Generic;
using Dashboard.Connector;
namespace MqttToTelegram.Condition {
abstract class ACondition {
protected ASensor sensor;
protected Dictionary<String, String> settings;
public ACondition(Dictionary<String, String> settings, ADataBackend backend) {
this.settings = settings;
Dictionary<String, String> l = new Dictionary<String, String> {
{ "topic", this.settings["sensor_topic"] },
{ "type", this.settings["sensor"] }
};
if(settings.ContainsKey("sensor_polling")) {
l.Add("polling", this.settings["sensor_polling"]);
}
this.sensor = ASensor.GetInstance(backend, l, "testSensor");
this.sensor.Update += this.Sensor_Update;
}
protected abstract void Sensor_Update(Object sender, EventArgs e);
public static ACondition GetInstance(Dictionary<String, String> settings, ADataBackend backend) {
String object_condition = "MqttToTelegram.Condition." + Char.ToUpper(settings["type"][0]) + settings["type"].Substring(1).ToLower();
Type t = null;
try {
t = Type.GetType(object_condition, true);
} catch(TypeLoadException) {
throw new ArgumentException("condition.ini: " + settings["type"] + " is not a Sensor");
}
return (ACondition)t.GetConstructor(new Type[] { typeof(Dictionary<String, String>), typeof(ADataBackend) }).Invoke(new Object[] { settings, backend });
}
}
}

24
IoT-Bot/Condition/Edge.cs Normal file
View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using Dashboard.Connector;
namespace MqttToTelegram.Condition {
class Edge : ACondition {
private Boolean histBool;
public Edge(Dictionary<String, String> settings, ADataBackend backend) : base(settings, backend) {
}
protected override void Sensor_Update(Object sender, EventArgs e) {
if(this.sensor.Datatypes == Dashboard.Sensor.ASensor.Types.Bool) {
if(this.sensor.GetBool == Boolean.Parse(this.settings["sensor_value"]) && this.histBool != this.sensor.GetBool) {
this.histBool = this.sensor.GetBool;
Telegram.Instance.Send("Jemand ist DA!");
} else {
this.histBool = this.sensor.GetBool;
}
}
}
}
}

View File

@ -0,0 +1,34 @@
using BlubbFish.Utils;
using System;
using System.Collections.Generic;
using Dashboard.Connector;
using MqttToTelegram.Condition;
namespace MqttToTelegram {
class ConditionWorker {
private InIReader ini;
private static ConditionWorker instance;
private List<ACondition> conditions;
private Telegram telegram;
public static ConditionWorker GetInstance(ADataBackend backend) {
if (instance == null) {
instance = new ConditionWorker(backend);
}
return instance;
}
internal void Run(Telegram telegram) {
this.telegram = telegram;
}
private ConditionWorker(ADataBackend backend) {
this.ini = InIReader.GetInstance("condition.ini");
this.conditions = new List<ACondition>();
List<String> sections = this.ini.GetSections();
foreach(String section in sections) {
this.conditions.Add(ACondition.GetInstance(this.ini.GetSection(section), backend));
}
}
}
}

100
IoT-Bot/IoT-Bot.csproj Normal file
View File

@ -0,0 +1,100 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{89077643-B472-419F-8EAB-56B9E2D13ABC}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MqttToTelegram</RootNamespace>
<AssemblyName>MqttToTelegram</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="M2Mqtt.Net, Version=4.3.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\M2Mqtt.4.3.0.0\lib\net45\M2Mqtt.Net.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Numerics" />
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="Telegram.Bot, Version=13.0.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Telegram.Bot.13.1.0\lib\netstandard1.1\Telegram.Bot.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="ConditionWorker.cs" />
<Compile Include="Condition\ACondition.cs" />
<Compile Include="Condition\Edge.cs" />
<Compile Include="Connector\ADataBackend.cs" />
<Compile Include="Connector\Mqtt.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Sensor\ASensor.cs" />
<Compile Include="Sensor\Luminanz.cs" />
<Compile Include="Sensor\Pir.cs" />
<Compile Include="Sensor\Power.cs" />
<Compile Include="Sensor\Switch.cs" />
<Compile Include="Sensor\Temperatur.cs" />
<Compile Include="Connector\Telegram.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
<None Include="settings.ini.example" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Utils\Utils\Utils.csproj">
<Project>{fac8ce64-bf13-4ece-8097-aeb5dd060098}</Project>
<Name>Utils</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- 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">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

36
IoT-Bot/Program.cs Normal file
View File

@ -0,0 +1,36 @@
using System;
using BlubbFish.Utils;
using Dashboard.Connector;
namespace MqttToTelegram {
class Program {
static void Main(String[] args) {
ADataBackend mqtt = ADataBackend.GetInstance(InIReader.GetInstance("settings.ini").GetSection("mqtt"));
ConditionWorker.GetInstance(mqtt).Run(Telegram.Instance);
mqtt.MessageIncomming += Mqtt_MessageIncomming;
mqtt.MessageSending += Mqtt_MessageSending;
Telegram.Instance.MessageIncomming += Telegram_MessageIncomming;
Telegram.Instance.MessageSending += Telegram_MessageSending;
while(true) {
System.Threading.Thread.Sleep(100);
}
}
private static void Mqtt_MessageSending(ADataBackend sender, MqttEventArgs e) {
Console.WriteLine("-> [" + DateTime.Now.ToUniversalTime() + "] MQTT: " + e.Message + " on " + e.Topic);
}
private static void Telegram_MessageSending(Object sender, global::Telegram.Bot.Types.Message e) {
Console.WriteLine("-> [" + e.Date.ToUniversalTime() + "] Telegram: " + e.Text + " on " + e.Chat.Id);
}
private static void Telegram_MessageIncomming(Object sender, global::Telegram.Bot.Types.Message e) {
Console.WriteLine("<- [" + e.Date.ToUniversalTime() + "] Telegram: " + e.Text + " on " + e.Chat.Id);
}
private static void Mqtt_MessageIncomming(ADataBackend sender, MqttEventArgs e) {
Console.WriteLine("<- [" + DateTime.Now.ToUniversalTime() + "] MQTT: " + e.Message + " on " + e.Topic);
}
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
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: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MqttToTelegram")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar
// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
[assembly: ComVisible(false)]
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
[assembly: Guid("89077643-b472-419f-8eab-56b9e2d13abc")]
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
//
// 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")]

38
IoT-Bot/packages.config Normal file
View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="M2Mqtt" version="4.3.0.0" targetFramework="net452" />
<package id="Microsoft.NETCore.Platforms" version="1.1.0" targetFramework="net452" />
<package id="NETStandard.Library" version="1.6.1" targetFramework="net452" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net452" />
<package id="System.Collections" version="4.3.0" targetFramework="net452" />
<package id="System.Collections.Concurrent" version="4.3.0" targetFramework="net452" />
<package id="System.Diagnostics.Debug" version="4.3.0" targetFramework="net452" />
<package id="System.Diagnostics.Tools" version="4.3.0" targetFramework="net452" />
<package id="System.Diagnostics.Tracing" version="4.3.0" targetFramework="net452" />
<package id="System.Globalization" version="4.3.0" targetFramework="net452" />
<package id="System.IO" version="4.3.0" targetFramework="net452" />
<package id="System.IO.Compression" version="4.3.0" targetFramework="net452" />
<package id="System.Linq" version="4.3.0" targetFramework="net452" />
<package id="System.Linq.Expressions" version="4.3.0" targetFramework="net452" />
<package id="System.Net.Http" version="4.3.0" targetFramework="net452" />
<package id="System.Net.Primitives" version="4.3.0" targetFramework="net452" />
<package id="System.ObjectModel" version="4.3.0" targetFramework="net452" />
<package id="System.Reflection" version="4.3.0" targetFramework="net452" />
<package id="System.Reflection.Extensions" version="4.3.0" targetFramework="net452" />
<package id="System.Reflection.Primitives" version="4.3.0" targetFramework="net452" />
<package id="System.Resources.ResourceManager" version="4.3.0" targetFramework="net452" />
<package id="System.Runtime" version="4.3.0" targetFramework="net452" />
<package id="System.Runtime.Extensions" version="4.3.0" targetFramework="net452" />
<package id="System.Runtime.InteropServices" version="4.3.0" targetFramework="net452" />
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net452" />
<package id="System.Runtime.Numerics" version="4.3.0" targetFramework="net452" />
<package id="System.Text.Encoding" version="4.3.0" targetFramework="net452" />
<package id="System.Text.Encoding.Extensions" version="4.3.0" targetFramework="net452" />
<package id="System.Text.RegularExpressions" version="4.3.0" targetFramework="net452" />
<package id="System.Threading" version="4.3.0" targetFramework="net452" />
<package id="System.Threading.Tasks" version="4.3.0" targetFramework="net452" />
<package id="System.Threading.Timer" version="4.3.0" targetFramework="net452" />
<package id="System.Xml.ReaderWriter" version="4.3.0" targetFramework="net452" />
<package id="System.Xml.XDocument" version="4.3.0" targetFramework="net452" />
<package id="Telegram.Bot" version="13.1.0" targetFramework="net452" />
</packages>

View File

@ -0,0 +1,7 @@
[general]
telegram-key=ABCDEFGH
chatid=1234
[mqtt]
server=localhost
type=mqtt