Change a lot stuff

This commit is contained in:
BlubbFish 2017-12-18 23:30:48 +01:00
parent 11019488d7
commit 329375b7cb
116 changed files with 3936 additions and 149 deletions

32
.gitignore vendored
View File

@ -131,3 +131,35 @@
/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
/Zway/.vs/Zway/v15
/Zway/Zway/obj/Debug
/Zway/Zway/bin/Debug
/IoT-Bot/.vs/config
/Zway-Bot/.vs
/Zway-Bot/packages
/Zway-Bot/Zway-Bot/obj
/Zway-Bot/Zway-Bot/bin/Debug
/Zway-Bot/Zway-Bot/bin/Release/ConnectorDataMosquitto.pdb
/Zway-Bot/Zway-Bot/bin/Release/ConnectorDataMqtt.pdb
/Zway-Bot/Zway-Bot/bin/Release/M2Mqtt.Net.pdb
/Zway-Bot/Zway-Bot/bin/Release/Utils-IoT.pdb
/Zway-Bot/Zway-Bot/bin/Release/Utils.pdb
/Zway-Bot/Zway-Bot/bin/Release/Zway-Bot.pdb
/Zway-Bot/Zway-Bot/bin/Release/Zway.pdb
/Zway/Zway/bin/Release/Zway.pdb
/Zway/Zway/obj/Release
/Utils/IoT/Connector/User/Telegram/obj/Release
/Utils/IoT/Connector/User/Telegram/bin/Release/ConnectorUserTelegram.dll.config
/Utils/IoT/Connector/User/Telegram/bin/Release/ConnectorUserTelegram.pdb
/Utils/IoT/Connector/User/Telegram/bin/Release/Newtonsoft.Json.xml
/Utils/IoT/Connector/User/Telegram/bin/Release/System.Diagnostics.DiagnosticSource.xml
/Utils/IoT/Connector/User/Telegram/bin/Release/Utils-IoT.pdb
/Utils/IoT/Connector/Data/Mqtt/obj
/Utils/IoT/Connector/Data/Mqtt/bin/Debug
/Utils/IoT/Connector/Data/Mqtt/bin/Release/ConnectorDataMqtt.pdb
/Utils/IoT/Connector/Data/Mqtt/bin/Release/M2Mqtt.Net.pdb
/Utils/IoT/Connector/Data/Mqtt/bin/Release/Utils-IoT.pdb
/Utils/IoT/Connector/Data/Mosquitto/obj
/Utils/IoT/Connector/Data/Mosquitto/bin/Debug
/Utils/IoT/Connector/Data/Mosquitto/bin/Release/ConnectorDataMosquitto.pdb
/Utils/IoT/Connector/Data/Mosquitto/bin/Release/Utils-IoT.pdb

View File

@ -9,6 +9,8 @@ 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}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -27,6 +29,10 @@ 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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -7,20 +7,68 @@ namespace IoTBot.Condition {
abstract class ACondition {
protected ASensor sensor;
protected Dictionary<String, String> settings;
protected String name;
protected ADataBackend data;
protected AUserBackend user;
protected ACondition(String name, Dictionary<String, String> settings, ASensor sensor, ADataBackend data, AUserBackend user) {
this.settings = settings;
this.name = name;
this.data = data;
this.user = user;
this.sensor = sensor;
}
public void Attach() {
this.sensor.Update += this.Sensor_Update;
if(this.sensor != null) {
this.sensor.Update += this.Sensor_Update;
}
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;
}
}
protected 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;
}
}
protected abstract void Data_Update(Object sender, MqttEventArgs e);
protected abstract void User_Update(Object sender, UserMessageEventArgs 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) {

View File

@ -9,6 +9,10 @@ namespace IoTBot.Condition {
public Edge(String name, Dictionary<String, String> settings, ASensor sensor, ADataBackend data, AUserBackend user) : base(name, settings, sensor, data, user) { }
protected override void Data_Update(Object sender, MqttEventArgs e) {
//throw new NotImplementedException();
}
protected override void Sensor_Update(Object sender, EventArgs e) {
if(this.sensor.Datatypes == ASensor.Types.Bool) {
if(this.sensor.GetBool == Boolean.Parse(this.settings["sensor_value"]) && this.histBool != this.sensor.GetBool) {
@ -19,5 +23,9 @@ namespace IoTBot.Condition {
}
}
}
protected override void User_Update(Object sender, UserMessageEventArgs e) {
//throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,93 @@
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;
namespace IoTBot.Condition {
class Telegrambot : ACondition {
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;
}
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") {
this.Send("Hallo zurück! Ich kann aktuell die Befehle /schalter");
}
if (e.Message.StartsWith("/schalter")) {
this.BotSchalter(e.Message);
}
}
private void BotSchalter(String message) {
if (message == "/schalter") {
this.user.Send("Was soll ich tun?", new String[] { "/schalter einschalten", "/schalter ausschalten", "/schalter status" });
}
if(message == "/schalter status") {
String ret = "Der Status des Schalters ist: ";
foreach (Switchbinary item in this.zw.GetCommandClasses<Switchbinary>()) {
ret += item.Name + ": " + (item.Level ? "An" : "Aus") + ", ";
}
this.user.Send(ret.Substring(0, ret.Length - 2));
}
if (message == "/schalter einschalten") {
List<String> s = new List<String>();
foreach (Switchbinary item in this.zw.GetCommandClasses<Switchbinary>()) {
if (!item.Level) {
s.Add("/schalter einschalten " + item.Name);
}
}
if (s.Count > 0) {
this.user.Send("Was soll ich tun?", s.ToArray());
} else {
this.user.Send("Keine Geräte ausgeschaltet!");
}
} else if(message.StartsWith("/schalter einschalten ")) {
String device = message.Substring(22);
foreach (Switchbinary item in this.zw.GetCommandClasses<Switchbinary>()) {
if(item.Name == device) {
item.Level = true;
this.user.Send("Einschalten von " + item.Name + " " + (item.Level ? "" : "nicht ") + "erfolgreich");
}
}
}
if (message == "/schalter ausschalten") {
List<String> s = new List<String>();
foreach (Switchbinary item in this.zw.GetCommandClasses<Switchbinary>()) {
if (item.Level) {
s.Add("/schalter ausschalten " + item.Name);
}
}
if (s.Count > 0) {
this.user.Send("Was soll ich tun?", s.ToArray());
} else {
this.user.Send("Keine Geräte eingeschaltet!");
}
} else if (message.StartsWith("/schalter ausschalten ")) {
String device = message.Substring(22);
foreach (Switchbinary item in this.zw.GetCommandClasses<Switchbinary>()) {
if (item.Name == device) {
item.Level = false;
this.user.Send("Ausschalten von " + item.Name + " " + (item.Level ? "nicht " : "") + "erfolgreich");
}
}
}
}
}
}

View File

@ -0,0 +1,27 @@
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;
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) { }
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 == this.settings["trigger"]) {
this.Send();
}
}
}
}

View File

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using BlubbFish.Utils;
using BlubbFish.Utils.IoT.Connector;
using BlubbFish.Utils.IoT.Sensor;
using IoTBot.Condition;
@ -17,13 +16,16 @@ namespace IoTBot {
}
public void SetCondition(String name, Dictionary<String, String> settings) {
Dictionary<String, String> sensor_settings = new Dictionary<String, String>();
foreach (KeyValuePair<String, String> item in settings) {
if(item.Key.StartsWith("sensor_")) {
sensor_settings.Add(item.Key.Substring(7), item.Value);
ASensor sensor = null;
if (settings.ContainsKey("sensor_type")) {
Dictionary<String, String> sensor_settings = new Dictionary<String, String>();
foreach (KeyValuePair<String, String> item in settings) {
if (item.Key.StartsWith("sensor_")) {
sensor_settings.Add(item.Key.Substring(7), item.Value);
}
}
sensor = ASensor.GetInstance(this.data, sensor_settings, name);
}
ASensor sensor = ASensor.GetInstance(this.data, sensor_settings, name);
this.conditions.Add(ACondition.GetInstance(name, settings, sensor, this.data, this.user));
}

View File

@ -7,8 +7,8 @@
<ProjectGuid>{89077643-B472-419F-8EAB-56B9E2D13ABC}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MqttToTelegram</RootNamespace>
<AssemblyName>MqttToTelegram</AssemblyName>
<RootNamespace>IoTBot</RootNamespace>
<AssemblyName>IoTBot</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
@ -37,6 +37,8 @@
<Compile Include="ConditionWorker.cs" />
<Compile Include="Condition\ACondition.cs" />
<Compile Include="Condition\Edge.cs" />
<Compile Include="Condition\TelegramBot.cs" />
<Compile Include="Condition\Trigger.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
@ -55,6 +57,10 @@
<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" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@ -13,9 +13,11 @@ namespace IoTBot {
foreach (String section in condition_settings.GetSections()) {
worker.SetCondition(section, condition_settings.GetSection(section));
}
mqtt.MessageIncomming += Mqtt_MessageIncomming;
mqtt.MessageSending += Mqtt_MessageSending;
if (mqtt != null) {
mqtt.MessageIncomming += Mqtt_MessageIncomming;
mqtt.MessageSending += Mqtt_MessageSending;
}
telegram.MessageIncomming += Telegram_MessageIncomming;
telegram.MessageSending += Telegram_MessageSending;
@ -23,6 +25,12 @@ namespace IoTBot {
while(true) {
System.Threading.Thread.Sleep(100);
if(Console.KeyAvailable) {
ConsoleKeyInfo key = Console.ReadKey(false);
if(key.Key == ConsoleKey.Escape) {
break;
}
}
}
}

View File

@ -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}") = "Mqtt-SWB-Dashboard", "Mqtt-SWB-Dashboard\Mqtt-SWB-Dashboard.csproj", "{324B2308-7C6E-4F16-8764-7C2F8C342B6A}"
EndProject
@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils", "..\Utils\Utils\Uti
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}") = "ConnectorDataMosquitto", "..\Utils\IoT\Connector\Data\Mosquitto\ConnectorDataMosquitto.csproj", "{39235FAD-BA9D-4B51-82FC-6969967BEAE9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -27,6 +29,10 @@ Global
{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
{39235FAD-BA9D-4B51-82FC-6969967BEAE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{39235FAD-BA9D-4B51-82FC-6969967BEAE9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{39235FAD-BA9D-4B51-82FC-6969967BEAE9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{39235FAD-BA9D-4B51-82FC-6969967BEAE9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -52,7 +52,9 @@ namespace Mqtt_SWB_Dashboard {
}
private void OnClosed(Object sender, EventArgs e) {
this.s.Dispose();
if (this.s != null) {
this.s.Dispose();
}
}
}
}

View File

@ -114,6 +114,11 @@
<Folder Include="Properties\DataSources\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Utils\IoT\Connector\Data\Mosquitto\ConnectorDataMosquitto.csproj">
<Project>{39235fad-ba9d-4b51-82fc-6969967beae9}</Project>
<Name>ConnectorDataMosquitto</Name>
<EmbedInteropTypes>False</EmbedInteropTypes>
</ProjectReference>
<ProjectReference Include="..\..\Utils\IoT\Utils-IoT.csproj">
<Project>{b870e4d5-6806-4a0b-b233-8907eedc5afc}</Project>
<Name>Utils-IoT</Name>

View File

@ -1,10 +1,16 @@

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}") = "Utils-IoT", "IoT\Utils-IoT.csproj", "{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConnectorDataMosquitto", "IoT\Connector\Data\Mosquitto\ConnectorDataMosquitto.csproj", "{39235FAD-BA9D-4B51-82FC-6969967BEAE9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConnectorDataMqtt", "IoT\Connector\Data\Mqtt\ConnectorDataMqtt.csproj", "{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConnectorUserTelegram", "IoT\Connector\User\Telegram\ConnectorUserTelegram.csproj", "{E66A57DD-858A-40E4-8A2F-BEA5129C31F7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -15,6 +21,18 @@ Global
{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
{39235FAD-BA9D-4B51-82FC-6969967BEAE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{39235FAD-BA9D-4B51-82FC-6969967BEAE9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{39235FAD-BA9D-4B51-82FC-6969967BEAE9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{39235FAD-BA9D-4B51-82FC-6969967BEAE9}.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
{E66A57DD-858A-40E4-8A2F-BEA5129C31F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E66A57DD-858A-40E4-8A2F-BEA5129C31F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E66A57DD-858A-40E4-8A2F-BEA5129C31F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E66A57DD-858A-40E4-8A2F-BEA5129C31F7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -9,7 +9,10 @@ namespace BlubbFish.Utils.IoT.Connector {
public delegate void MqttMessage(Object sender, MqttEventArgs e);
public static ADataBackend GetInstance(Dictionary<String, String> settings) {
String object_sensor = "BlubbFish.Utils.IoT.Connector.Data." + Char.ToUpper(settings["type"][0]) + settings["type"].Substring(1).ToLower();
if(settings.Count == 0) {
return null;
}
String object_sensor = "BlubbFish.Utils.IoT.Connector.Data." + Char.ToUpper(settings["type"][0]) + settings["type"].Substring(1).ToLower()+", "+ "ConnectorData" + Char.ToUpper(settings["type"][0]) + settings["type"].Substring(1).ToLower();
Type t = null;
try {
t = Type.GetType(object_sensor, true);

View File

@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BlubbFish.Utils.IoT.Connector {
public abstract class AUserBackend {
@ -17,7 +14,7 @@ namespace BlubbFish.Utils.IoT.Connector {
}
public static AUserBackend GetInstance(Dictionary<String, String> settings) {
String object_sensor = "BlubbFish.Utils.IoT.Connector.User." + Char.ToUpper(settings["type"][0]) + settings["type"].Substring(1).ToLower();
String object_sensor = "BlubbFish.Utils.IoT.Connector.User." + Char.ToUpper(settings["type"][0]) + settings["type"].Substring(1).ToLower()+", "+ "ConnectorUser" + Char.ToUpper(settings["type"][0]) + settings["type"].Substring(1).ToLower();
Type t = null;
try {
t = Type.GetType(object_sensor, true);
@ -28,6 +25,7 @@ namespace BlubbFish.Utils.IoT.Connector {
}
public abstract void Send(String message);
public abstract void Send(String message, String[] buttons);
public abstract void Dispose();
}

View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" 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>{39235FAD-BA9D-4B51-82FC-6969967BEAE9}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>BlubbFish.Utils.IoT.Connector.Data</RootNamespace>
<AssemblyName>ConnectorDataMosquitto</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<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' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<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" />
</ItemGroup>
<ItemGroup>
<Compile Include="Mosquitto.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Utils-IoT.csproj">
<Project>{b870e4d5-6806-4a0b-b233-8907eedc5afc}</Project>
<Name>Utils-IoT</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -4,7 +4,7 @@ using System.Diagnostics;
using System.Text.RegularExpressions;
namespace BlubbFish.Utils.IoT.Connector.Data {
class Mosquitto : ADataBackend, IDisposable {
public class Mosquitto : ADataBackend, IDisposable {
private Process p;
private String message;
@ -17,6 +17,7 @@ namespace BlubbFish.Utils.IoT.Connector.Data {
this.message = "";
this.p = new Process();
this.p.StartInfo.FileName = "mosquitto_sub";
String topic = "#";
String args = "-h " + this.settings["server"]+" ";
if(this.settings.ContainsKey("port")) {
args += "-p "+ this.settings["port"]+" ";
@ -30,7 +31,10 @@ namespace BlubbFish.Utils.IoT.Connector.Data {
if (this.settings.ContainsKey("key")) {
args += "--key " + this.settings["key"] + " ";
}
this.p.StartInfo.Arguments = args+"-t \"#\" -v -d";
if(this.settings.ContainsKey("topic")) {
topic = this.settings["topic"];
}
this.p.StartInfo.Arguments = args+"-t \""+ topic + "\" -v -d";
this.p.StartInfo.CreateNoWindow = true;
this.p.StartInfo.UseShellExecute = false;
this.p.StartInfo.RedirectStandardOutput = true;

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("ConnectorDataMosquitto")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ConnectorDataMosquitto")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
// für COM-Komponenten unsichtbar. 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("39235fad-ba9d-4b51-82fc-6969967beae9")]
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
//
// Hauptversion
// Nebenversion
// Buildnummer
// Revision
//
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" 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>{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>BlubbFish.Utils.IoT.Connector.Data</RootNamespace>
<AssemblyName>ConnectorDataMqtt</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<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' ">
<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>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<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" />
</ItemGroup>
<ItemGroup>
<Compile Include="Mqtt.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Utils-IoT.csproj">
<Project>{b870e4d5-6806-4a0b-b233-8907eedc5afc}</Project>
<Name>Utils-IoT</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -5,7 +5,7 @@ using uPLibrary.Networking.M2Mqtt;
using uPLibrary.Networking.M2Mqtt.Messages;
namespace BlubbFish.Utils.IoT.Connector.Data {
class Mqtt : ADataBackend, IDisposable {
public class Mqtt : ADataBackend, IDisposable {
private MqttClient client;
public override event MqttMessage MessageIncomming;
@ -42,10 +42,11 @@ namespace BlubbFish.Utils.IoT.Connector.Data {
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();
if(disposing) {try {
this.client.MqttMsgPublishReceived -= this.Client_MqttMsgPublishReceived;
this.client.Unsubscribe(new String[] { "#" });
this.client.Disconnect();
} catch (Exception) { }
}
this.client = null;

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("ConnectorDataMqtt")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ConnectorDataMqtt")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
// für COM-Komponenten unsichtbar. 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("ee6c8f68-ed46-4c1c-abdd-cfcdf75104f2")]
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
//
// Hauptversion
// Nebenversion
// Buildnummer
// Revision
//
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

Binary file not shown.

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="M2Mqtt" version="4.3.0.0" targetFramework="net461" />
</packages>

View File

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BlubbFish.Utils.IoT.Connector {
public class UserMessageEventArgs : EventArgs {

View File

@ -0,0 +1,119 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" 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>{E66A57DD-858A-40E4-8A2F-BEA5129C31F7}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>BlubbFish.Utils.IoT.Connector.User</RootNamespace>
<AssemblyName>ConnectorUserTelegram</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<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' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Win32.Primitives, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\..\packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll</HintPath>
</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>
</Reference>
<Reference Include="System" />
<Reference Include="System.AppContext, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\..\packages\System.AppContext.4.3.0\lib\net46\System.AppContext.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Console, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\..\packages\System.Console.4.3.0\lib\net46\System.Console.dll</HintPath>
</Reference>
<Reference Include="System.Core" />
<Reference Include="System.Diagnostics.DiagnosticSource, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\..\..\packages\System.Diagnostics.DiagnosticSource.4.3.0\lib\net46\System.Diagnostics.DiagnosticSource.dll</HintPath>
</Reference>
<Reference Include="System.Globalization.Calendars, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\..\packages\System.Globalization.Calendars.4.3.0\lib\net46\System.Globalization.Calendars.dll</HintPath>
</Reference>
<Reference Include="System.IO.Compression, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\..\..\..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.IO.Compression.ZipFile, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\..\..\..\packages\System.IO.Compression.ZipFile.4.3.0\lib\net46\System.IO.Compression.ZipFile.dll</HintPath>
</Reference>
<Reference Include="System.IO.FileSystem, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\..\packages\System.IO.FileSystem.4.3.0\lib\net46\System.IO.FileSystem.dll</HintPath>
</Reference>
<Reference Include="System.IO.FileSystem.Primitives, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\..\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\..\packages\System.Net.Http.4.3.0\lib\net46\System.Net.Http.dll</HintPath>
</Reference>
<Reference Include="System.Net.Sockets, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\..\packages\System.Net.Sockets.4.3.0\lib\net46\System.Net.Sockets.dll</HintPath>
</Reference>
<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.Security.Cryptography.Algorithms, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net461\System.Security.Cryptography.Algorithms.dll</HintPath>
</Reference>
<Reference Include="System.Security.Cryptography.Encoding, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll</HintPath>
</Reference>
<Reference Include="System.Security.Cryptography.Primitives, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll</HintPath>
</Reference>
<Reference Include="System.Security.Cryptography.X509Certificates, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.ReaderWriter, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\..\packages\System.Xml.ReaderWriter.4.3.0\lib\net46\System.Xml.ReaderWriter.dll</HintPath>
</Reference>
<Reference Include="Telegram.Bot, Version=13.2.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\..\packages\Telegram.Bot.13.2.1\lib\netstandard1.1\Telegram.Bot.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Telegram.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Utils-IoT.csproj">
<Project>{b870e4d5-6806-4a0b-b233-8907eedc5afc}</Project>
<Name>Utils-IoT</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

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("ConnectorUserTelegram")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ConnectorUserTelegram")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
// für COM-Komponenten unsichtbar. 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("e66a57dd-858a-40e4-8a2f-bea5129c31f7")]
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
//
// Hauptversion
// Nebenversion
// Buildnummer
// Revision
//
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -4,6 +4,8 @@ using Telegram.Bot;
using Telegram.Bot.Args;
using Telegram.Bot.Exceptions;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
using Telegram.Bot.Types.ReplyMarkups;
namespace BlubbFish.Utils.IoT.Connector.User {
public class Telegram : AUserBackend {
@ -30,18 +32,38 @@ namespace BlubbFish.Utils.IoT.Connector.User {
public async override void Send(String message) {
try {
Message x = await this.bot.SendTextMessageAsync(this.chat, message);
Message x = await this.bot.SendTextMessageAsync(this.chat, message, ParseMode.Default, false, false, 0, new ReplyKeyboardRemove());
this.MessageSending?.Invoke(this, new UserMessageEventArgs(x.Text, x.Chat.Id, x.Date));
} catch(ApiRequestException e) {
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(e.Message+" "+e.ErrorCode+" "+e.Parameters);
Console.ForegroundColor = ConsoleColor.White;
}
}
public override void Dispose() {
this.bot.StopReceiving();
this.bot = null;
}
public async override void Send(String message, String[] buttons) {
try {
KeyboardButton[][] button = new KeyboardButton[(Int32)Math.Ceiling(((Double)buttons.Length)/2)][];
for(Int32 i = 0; i < buttons.Length; i++) {
Int32 j = (Int32)Math.Floor(((Double)i) / 2);
if (i % 2 == 0) {
button[j] = new KeyboardButton[(j == button.Length - 1) ? ((buttons.Length % 2 == 0) ? 2 : buttons.Length % 2) : 2];
}
button[j][i % 2] = new KeyboardButton(buttons[i]);
}
Message x = await this.bot.SendTextMessageAsync(this.chat, message, ParseMode.Default, false, false, 0, new ReplyKeyboardMarkup(button,true,true));
this.MessageSending?.Invoke(this, new UserMessageEventArgs(x.Text, x.Chat.Id, x.Date));
} catch (ApiRequestException e) {
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(e.Message + " " + e.ErrorCode + " " + e.Parameters);
Console.ForegroundColor = ConsoleColor.White;
}
}
}
}

View File

@ -12,4 +12,4 @@
</dependentAssembly>
</assemblyBinding>
</runtime>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" /></startup></configuration>
</configuration>

View File

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.NETCore.Platforms" version="1.1.0" targetFramework="net461" />
<package id="Microsoft.Win32.Primitives" version="4.3.0" targetFramework="net461" />
<package id="NETStandard.Library" version="1.6.1" targetFramework="net461" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net461" />
<package id="System.AppContext" version="4.3.0" targetFramework="net461" />
<package id="System.Collections" version="4.3.0" targetFramework="net461" />
<package id="System.Collections.Concurrent" version="4.3.0" targetFramework="net461" />
<package id="System.Console" version="4.3.0" targetFramework="net461" />
<package id="System.Diagnostics.Debug" version="4.3.0" targetFramework="net461" />
<package id="System.Diagnostics.DiagnosticSource" version="4.3.0" targetFramework="net461" />
<package id="System.Diagnostics.Tools" version="4.3.0" targetFramework="net461" />
<package id="System.Diagnostics.Tracing" version="4.3.0" targetFramework="net461" />
<package id="System.Globalization" version="4.3.0" targetFramework="net461" />
<package id="System.Globalization.Calendars" version="4.3.0" targetFramework="net461" />
<package id="System.IO" version="4.3.0" targetFramework="net461" />
<package id="System.IO.Compression" version="4.3.0" targetFramework="net461" />
<package id="System.IO.Compression.ZipFile" version="4.3.0" targetFramework="net461" />
<package id="System.IO.FileSystem" version="4.3.0" targetFramework="net461" />
<package id="System.IO.FileSystem.Primitives" version="4.3.0" targetFramework="net461" />
<package id="System.Linq" version="4.3.0" targetFramework="net461" />
<package id="System.Linq.Expressions" version="4.3.0" targetFramework="net461" />
<package id="System.Net.Http" version="4.3.0" targetFramework="net461" />
<package id="System.Net.Primitives" version="4.3.0" targetFramework="net461" />
<package id="System.Net.Sockets" version="4.3.0" targetFramework="net461" />
<package id="System.ObjectModel" version="4.3.0" targetFramework="net461" />
<package id="System.Reflection" version="4.3.0" targetFramework="net461" />
<package id="System.Reflection.Extensions" version="4.3.0" targetFramework="net461" />
<package id="System.Reflection.Primitives" version="4.3.0" targetFramework="net461" />
<package id="System.Resources.ResourceManager" version="4.3.0" targetFramework="net461" />
<package id="System.Runtime" version="4.3.0" targetFramework="net461" />
<package id="System.Runtime.Extensions" version="4.3.0" targetFramework="net461" />
<package id="System.Runtime.Handles" version="4.3.0" targetFramework="net461" />
<package id="System.Runtime.InteropServices" version="4.3.0" targetFramework="net461" />
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net461" />
<package id="System.Runtime.Numerics" version="4.3.0" targetFramework="net461" />
<package id="System.Security.Cryptography.Algorithms" version="4.3.0" targetFramework="net461" />
<package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="net461" />
<package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net461" />
<package id="System.Security.Cryptography.X509Certificates" version="4.3.0" targetFramework="net461" />
<package id="System.Text.Encoding" version="4.3.0" targetFramework="net461" />
<package id="System.Text.Encoding.Extensions" version="4.3.0" targetFramework="net461" />
<package id="System.Text.RegularExpressions" version="4.3.0" targetFramework="net461" />
<package id="System.Threading" version="4.3.0" targetFramework="net461" />
<package id="System.Threading.Tasks" version="4.3.0" targetFramework="net461" />
<package id="System.Threading.Timer" version="4.3.0" targetFramework="net461" />
<package id="System.Xml.ReaderWriter" version="4.3.0" targetFramework="net461" />
<package id="System.Xml.XDocument" version="4.3.0" targetFramework="net461" />
<package id="Telegram.Bot" version="13.2.1" targetFramework="net461" />
</packages>

View File

@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>BlubbFish.Utils.IoT</RootNamespace>
<AssemblyName>Utils-IoT</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
@ -34,86 +34,22 @@
<Reference Include="LitJson, Version=0.9.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\LitJson.0.9.0\lib\LitJson.dll</HintPath>
</Reference>
<Reference Include="M2Mqtt.Net, Version=4.3.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\IoT-Bot\packages\M2Mqtt.4.3.0.0\lib\net45\M2Mqtt.Net.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Win32.Primitives, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\IoT-Bot\packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\IoT-Bot\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.AppContext, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\IoT-Bot\packages\System.AppContext.4.3.0\lib\net46\System.AppContext.dll</HintPath>
</Reference>
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Console, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\IoT-Bot\packages\System.Console.4.3.0\lib\net46\System.Console.dll</HintPath>
</Reference>
<Reference Include="System.Core" />
<Reference Include="System.Diagnostics.DiagnosticSource, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\IoT-Bot\packages\System.Diagnostics.DiagnosticSource.4.3.0\lib\net46\System.Diagnostics.DiagnosticSource.dll</HintPath>
</Reference>
<Reference Include="System.Globalization.Calendars, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\IoT-Bot\packages\System.Globalization.Calendars.4.3.0\lib\net46\System.Globalization.Calendars.dll</HintPath>
</Reference>
<Reference Include="System.IO.Compression, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\..\IoT-Bot\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.IO.Compression.ZipFile, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\..\IoT-Bot\packages\System.IO.Compression.ZipFile.4.3.0\lib\net46\System.IO.Compression.ZipFile.dll</HintPath>
</Reference>
<Reference Include="System.IO.FileSystem, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\IoT-Bot\packages\System.IO.FileSystem.4.3.0\lib\net46\System.IO.FileSystem.dll</HintPath>
</Reference>
<Reference Include="System.IO.FileSystem.Primitives, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\IoT-Bot\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\IoT-Bot\packages\System.Net.Http.4.3.0\lib\net46\System.Net.Http.dll</HintPath>
</Reference>
<Reference Include="System.Net.Sockets, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\IoT-Bot\packages\System.Net.Sockets.4.3.0\lib\net46\System.Net.Sockets.dll</HintPath>
</Reference>
<Reference Include="System.Numerics" />
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\IoT-Bot\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Security.Cryptography.Algorithms, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\IoT-Bot\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net461\System.Security.Cryptography.Algorithms.dll</HintPath>
</Reference>
<Reference Include="System.Security.Cryptography.Encoding, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\IoT-Bot\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll</HintPath>
</Reference>
<Reference Include="System.Security.Cryptography.Primitives, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\IoT-Bot\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll</HintPath>
</Reference>
<Reference Include="System.Security.Cryptography.X509Certificates, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\IoT-Bot\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.ReaderWriter, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\IoT-Bot\packages\System.Xml.ReaderWriter.4.3.0\lib\net46\System.Xml.ReaderWriter.dll</HintPath>
</Reference>
<Reference Include="Telegram.Bot, Version=13.2.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\IoT-Bot\packages\Telegram.Bot.13.2.1\lib\netstandard1.1\Telegram.Bot.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Connector\ADataBackend.cs" />
<Compile Include="Connector\AUserBackend.cs" />
<Compile Include="Connector\Helper.cs" />
<Compile Include="Connector\Data\Mosquitto.cs" />
<Compile Include="Connector\Data\Mqtt.cs" />
<Compile Include="Connector\User\Telegram.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Sensor\ASensor.cs" />
<Compile Include="Sensor\Flex4GridPower.cs" />
@ -125,7 +61,6 @@
<Compile Include="Sensor\Temperatur.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

Binary file not shown.

View File

@ -1,53 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="LitJson" version="0.9.0" targetFramework="net462" />
<package id="M2Mqtt" version="4.3.0.0" targetFramework="net461" />
<package id="Microsoft.NETCore.Platforms" version="1.1.0" targetFramework="net461" />
<package id="Microsoft.Win32.Primitives" version="4.3.0" targetFramework="net461" />
<package id="NETStandard.Library" version="1.6.1" targetFramework="net461" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net461" />
<package id="System.AppContext" version="4.3.0" targetFramework="net461" />
<package id="System.Collections" version="4.3.0" targetFramework="net461" />
<package id="System.Collections.Concurrent" version="4.3.0" targetFramework="net461" />
<package id="System.Console" version="4.3.0" targetFramework="net461" />
<package id="System.Diagnostics.Debug" version="4.3.0" targetFramework="net461" />
<package id="System.Diagnostics.DiagnosticSource" version="4.3.0" targetFramework="net461" />
<package id="System.Diagnostics.Tools" version="4.3.0" targetFramework="net461" />
<package id="System.Diagnostics.Tracing" version="4.3.0" targetFramework="net461" />
<package id="System.Globalization" version="4.3.0" targetFramework="net461" />
<package id="System.Globalization.Calendars" version="4.3.0" targetFramework="net461" />
<package id="System.IO" version="4.3.0" targetFramework="net461" />
<package id="System.IO.Compression" version="4.3.0" targetFramework="net461" />
<package id="System.IO.Compression.ZipFile" version="4.3.0" targetFramework="net461" />
<package id="System.IO.FileSystem" version="4.3.0" targetFramework="net461" />
<package id="System.IO.FileSystem.Primitives" version="4.3.0" targetFramework="net461" />
<package id="System.Linq" version="4.3.0" targetFramework="net461" />
<package id="System.Linq.Expressions" version="4.3.0" targetFramework="net461" />
<package id="System.Net.Http" version="4.3.0" targetFramework="net461" />
<package id="System.Net.Primitives" version="4.3.0" targetFramework="net461" />
<package id="System.Net.Sockets" version="4.3.0" targetFramework="net461" />
<package id="System.ObjectModel" version="4.3.0" targetFramework="net461" />
<package id="System.Reflection" version="4.3.0" targetFramework="net461" />
<package id="System.Reflection.Extensions" version="4.3.0" targetFramework="net461" />
<package id="System.Reflection.Primitives" version="4.3.0" targetFramework="net461" />
<package id="System.Resources.ResourceManager" version="4.3.0" targetFramework="net461" />
<package id="System.Runtime" version="4.3.0" targetFramework="net461" />
<package id="System.Runtime.Extensions" version="4.3.0" targetFramework="net461" />
<package id="System.Runtime.Handles" version="4.3.0" targetFramework="net461" />
<package id="System.Runtime.InteropServices" version="4.3.0" targetFramework="net461" />
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net461" />
<package id="System.Runtime.Numerics" version="4.3.0" targetFramework="net461" />
<package id="System.Security.Cryptography.Algorithms" version="4.3.0" targetFramework="net461" />
<package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="net461" />
<package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net461" />
<package id="System.Security.Cryptography.X509Certificates" version="4.3.0" targetFramework="net461" />
<package id="System.Text.Encoding" version="4.3.0" targetFramework="net461" />
<package id="System.Text.Encoding.Extensions" version="4.3.0" targetFramework="net461" />
<package id="System.Text.RegularExpressions" version="4.3.0" targetFramework="net461" />
<package id="System.Threading" version="4.3.0" targetFramework="net461" />
<package id="System.Threading.Tasks" version="4.3.0" targetFramework="net461" />
<package id="System.Threading.Timer" version="4.3.0" targetFramework="net461" />
<package id="System.Xml.ReaderWriter" version="4.3.0" targetFramework="net461" />
<package id="System.Xml.XDocument" version="4.3.0" targetFramework="net461" />
<package id="Telegram.Bot" version="13.2.1" targetFramework="net461" />
</packages>

Binary file not shown.

55
Zway-Bot/Zway-Bot.sln Normal file
View File

@ -0,0 +1,55 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2010
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Zway-Bot", "Zway-Bot\Zway-Bot.csproj", "{AEF8059F-8AEF-45C7-85C4-318C8F797900}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Zway", "..\Zway\Zway\Zway.csproj", "{166258ED-CB3D-43F5-8E8D-3A993B64D022}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils", "..\Utils\Utils\Utils.csproj", "{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}"
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}") = "ConnectorDataMosquitto", "..\Utils\IoT\Connector\Data\Mosquitto\ConnectorDataMosquitto.csproj", "{39235FAD-BA9D-4B51-82FC-6969967BEAE9}"
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
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AEF8059F-8AEF-45C7-85C4-318C8F797900}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AEF8059F-8AEF-45C7-85C4-318C8F797900}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AEF8059F-8AEF-45C7-85C4-318C8F797900}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AEF8059F-8AEF-45C7-85C4-318C8F797900}.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
{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
{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
{39235FAD-BA9D-4B51-82FC-6969967BEAE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{39235FAD-BA9D-4B51-82FC-6969967BEAE9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{39235FAD-BA9D-4B51-82FC-6969967BEAE9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{39235FAD-BA9D-4B51-82FC-6969967BEAE9}.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
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FC298685-EC11-4957-9D91-F044DDDD0B6E}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,81 @@
using System;
namespace ZwayBot {
public class CronEvent : ModulEventArgs {
public CronEvent() {
}
public CronEvent(String addr, String prop, String value) {
this.Address = addr;
this.Property = prop;
this.Value = value;
this.Source = "Cronjob";
}
}
public class OvertakerEvent : ModulEventArgs {
public OvertakerEvent() {
}
public OvertakerEvent(String addr, String prop, String value) {
this.Address = addr;
this.Property = prop;
this.Value = value;
this.Source = "Overtaker";
}
}
public class Flex4gridEvent : ModulEventArgs {
public Flex4gridEvent() {
}
public Flex4gridEvent(String topic, String text) {
this.Address = topic;
this.Value = text;
this.Source = "Flex4Grid";
}
public override String ToString() {
return this.Source + ": on " + this.Address + " set " + this.Value;
}
}
public class MqttEvent : ModulEventArgs {
public MqttEvent() {
}
public MqttEvent(String topic, String text) {
this.Address = topic;
this.Value = text;
this.Source = "MQTT";
}
public override String ToString() {
return this.Source + ": on " + this.Address + " set " + this.Value;
}
}
public class StatusPollingEvent : ModulEventArgs {
public StatusPollingEvent() {
}
public StatusPollingEvent(String text, String node) {
this.Value = text;
this.Address = node;
this.Source = "POLLING";
}
public override String ToString() {
return this.Source + ": " + this.Value + " on " + this.Address;
}
}
public class ModulEventArgs : EventArgs {
public ModulEventArgs() {
}
public String Address { get; protected set; }
public String Property { get; protected set; }
public String Value { get; protected set; }
public String Source { get; protected set; }
public override String ToString() {
return this.Source + ": " + this.Address + " set " + this.Property + " to " + this.Value;
}
}
}

View File

@ -0,0 +1,63 @@
using System;
using System.Reflection;
namespace ZwayBot {
static class Helper {
public static void SetProperty(this Object o, String name, String value) {
PropertyInfo prop = o.GetType().GetProperty(name);
if (prop.CanWrite) {
if (prop.PropertyType == typeof(Boolean) && Boolean.TryParse(value, out Boolean vb)) {
prop.SetValue(o, vb);
} else if (prop.PropertyType == typeof(Int32) && Int32.TryParse(value, out Int32 v32)) {
prop.SetValue(o, v32);
} else if (prop.PropertyType == typeof(Single) && Single.TryParse(value, out Single vs)) {
prop.SetValue(o, vs);
} else if (prop.PropertyType == typeof(Double) && Double.TryParse(value, out Double vd)) {
prop.SetValue(o, vd);
} else if (prop.PropertyType == typeof(Int64) && Int64.TryParse(value, out Int64 v64)) {
prop.SetValue(o, v64);
}
}
}
internal static Boolean HasProperty(this Object o, String type) {
Type t = o.GetType();
foreach (PropertyInfo item in t.GetProperties()) {
if (item.Name == type) {
return true;
}
}
return false;
}
internal static Object GetProperty(this Object o, String name) {
PropertyInfo prop = o.GetType().GetProperty(name);
if(prop.CanRead) {
return prop.GetValue(o);
}
return null;
}
internal static Boolean HasAbstract(this Object o, Type type) {
if(o.GetType().BaseType == type) {
return true;
}
return false;
}
internal static Boolean HasInterface(this Type o, String type) {
foreach (Type item in o.GetInterfaces()) {
if(item.Name == type) {
return true;
}
}
return false;
}
internal static void WriteError(String text) {
Console.ForegroundColor = ConsoleColor.Red;
Console.Error.WriteLine("ERROR: " + text);
Console.ResetColor();
}
}
}

View File

@ -0,0 +1,4 @@
namespace ZwayBot.Interfaces {
interface IForceLoad {
}
}

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using BlubbFish.IoT.Zway;
using BlubbFish.Utils;
namespace ZwayBot {
abstract class AModul {
protected ZwayController zw;
protected InIReader ini;
public delegate void ModulEvent(Object sender, ModulEventArgs e);
public abstract event ModulEvent Update;
public AModul(ZwayController zway, InIReader settings) {
this.zw = zway;
this.ini = settings;
}
public virtual void Interconnect(Dictionary<String, AModul> moduls) { }
public virtual void SetInterconnection(String param, Action<Object> hook, Object data) { }
public abstract void Dispose();
}
}

View File

@ -0,0 +1,186 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text.RegularExpressions;
using System.Threading;
using BlubbFish.IoT.Zway;
using BlubbFish.IoT.Zway.Interfaces;
using BlubbFish.Utils;
using ZwayBot.Interfaces;
namespace ZwayBot.Moduls {
internal class CronJob : AModul, IDisposable, IForceLoad {
private DateTime crontime;
private Thread thread;
private List<Tuple<String, Action<Object>, Object>> internalCron = new List<Tuple<String, Action<Object>, Object>>();
public override event ModulEvent Update;
private Dictionary<String, String> cron_named = new Dictionary<String, String> {
{ "@yearly", "0 0 1 1 *" },
{ "@annually", "0 0 1 1 *" },
{ "@monthly", "0 0 1 * *" },
{ "@weekly", "0 0 * * 0" },
{ "@daily", "0 0 * * *" },
{ "@hourly", "0 * * * *" }
};
public CronJob(ZwayController zway, InIReader settings) : base(zway, settings) {
this.crontime = DateTime.Now;
this.thread = new Thread(this.Runner);
this.thread.Start();
}
private void Runner() {
Thread.Sleep(DateTime.Now.AddMinutes(1).AddSeconds(DateTime.Now.Second * (-1)).AddMilliseconds(DateTime.Now.Millisecond * (-1)) - DateTime.Now);
while (true) {
if(this.crontime.Minute != DateTime.Now.Minute) {
this.crontime = DateTime.Now;
if (this.ini != null) {
foreach (String item in this.ini.GetSections()) {
if (this.ParseCronString(this.ini.GetValue(item, "cron"))) {
this.SetValues(this.ini.GetValue(item, "set"));
}
}
}
foreach (Tuple<String, Action<Object>, Object> item in this.internalCron) {
if(this.ParseCronString(item.Item1)) {
item.Item2?.Invoke(item.Item3);
}
}
}
Thread.Sleep(100);
}
}
private void SetValues(String value) {
foreach (String item in value.Split(';')) {
String[] items = item.Split(':');
if(items.Length == 2) {
String[] values = items[1].Split('-');
ACommandClass c = this.zw.GetCommandClass(items[0]);
if (c != null && values.Length == 2) {
if (c.HasProperty(values[0])) {
c.SetProperty(values[0], values[1]);
this.Update?.Invoke(this, new CronEvent(items[0], values[0], values[1]));
}
}
}
}
}
private Boolean ParseCronString(String str) {
str = str.Trim();
if(this.cron_named.ContainsKey(str)) {
str = this.cron_named[str];
}
String[] value = str.Split(' ');
if(value.Length != 5) {
return false;
}
if (!this.CheckDateStr(this.crontime.ToString("mm"), value[0], "0-59")) {
return false;
}
if (!this.CheckDateStr(this.crontime.ToString("HH"), value[1], "0-23")) {
return false;
}
if (!this.CheckDateStr(this.crontime.ToString("MM"), value[3], "1-12")) {
return false;
}
if (value[2] != "*" && value[4] != "*") {
if (!this.CheckDateStr(this.crontime.ToString("dd"), value[2], "1-31") && !this.CheckDateStr(((Int32)this.crontime.DayOfWeek).ToString(), value[4], "0-7")) {
return false;
}
} else {
if (!this.CheckDateStr(this.crontime.ToString("dd"), value[2], "1-31")) {
return false;
}
if (!this.CheckDateStr(((Int32)this.crontime.DayOfWeek).ToString(), value[4], "0-7")) {
return false;
}
}
return true;
}
private Boolean CheckDateStr(String date, String cron, String limit) {
cron = cron.ToLower();
for (Int32 i = 0; i <= 6; i++) {
cron = cron.Replace(DateTime.Parse("2015-01-" + (4 + i) + "T00:00:00").ToString("ddd", CultureInfo.CreateSpecificCulture("en-US")), i.ToString());
cron = cron.Replace(DateTime.Parse("2015-01-" + (4 + i) + "T00:00:00").ToString("dddd", CultureInfo.CreateSpecificCulture("en-US")), i.ToString());
}
for (Int32 i = 1; i <= 12; i++) {
cron = cron.Replace(DateTime.Parse("2015-" + i + "-01T00:00:00").ToString("MMM", CultureInfo.CreateSpecificCulture("en-US")), i.ToString());
cron = cron.Replace(DateTime.Parse("2015-" + i + "-01T00:00:00").ToString("MMMM", CultureInfo.CreateSpecificCulture("en-US")), i.ToString());
}
if (cron.Contains("*")) {
cron = cron.Replace("*", limit);
}
if(cron.Contains("-")) {
MatchCollection m = new Regex("(\\d+)-(\\d+)").Matches(cron);
foreach (Match p in m) {
List<String> s = new List<String>();
for(Int32 i=Math.Min(Int32.Parse(p.Groups[1].Value), Int32.Parse(p.Groups[2].Value));i<= Math.Max(Int32.Parse(p.Groups[1].Value), Int32.Parse(p.Groups[2].Value)); i++) {
s.Add(i.ToString());
}
cron = cron.Replace(p.Groups[0].Value, String.Join(",", s));
}
}
Int32 match = 0;
if(cron.Contains("/")) {
Match m = new Regex("/(\\d+)").Match(cron);
cron = cron.Replace(m.Groups[0].Value, "");
match = Int32.Parse(m.Groups[1].Value);
}
Dictionary<Int32, String> ret = new Dictionary<Int32, String>();
if(!cron.Contains(",")) {
ret.Add(Int32.Parse(cron), "");
} else {
foreach (String item in cron.Split(',')) {
if(!ret.ContainsKey(Int32.Parse(item))) {
ret.Add(Int32.Parse(item), "");
}
}
}
if(match != 0) {
Dictionary<Int32, String> r = new Dictionary<Int32, String>();
foreach (KeyValuePair<Int32, String> item in ret) {
if(item.Key%match == 0) {
r.Add(item.Key, "");
}
}
ret = r;
}
return ret.ContainsKey(Int32.Parse(date));
}
public override void SetInterconnection(String cron, Action<Object> hook, Object data) {
this.internalCron.Add(new Tuple<String, Action<Object>, Object>(cron, hook, data));
}
#region IDisposable Support
private Boolean disposedValue = false;
protected virtual void Dispose(Boolean disposing) {
if (!this.disposedValue) {
if (disposing) {
this.thread.Abort();
while(this.thread.ThreadState != ThreadState.Aborted) { Thread.Sleep(100); }
}
this.thread = null;
this.disposedValue = true;
}
}
~CronJob() {
Dispose(false);
}
public override void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
}
}

View File

@ -0,0 +1,187 @@
using System;
using System.Collections.Generic;
using System.Net;
using BlubbFish.IoT.Zway;
using BlubbFish.IoT.Zway.Devices;
using BlubbFish.IoT.Zway.Devices.CommandClasses;
using BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs;
using BlubbFish.IoT.Zway.Events;
using BlubbFish.IoT.Zway.Interfaces;
using BlubbFish.Utils;
using BlubbFish.Utils.IoT.Connector;
using LitJson;
namespace ZwayBot.Moduls {
class Flex4Grid : AModul, IDisposable {
private ADataBackend mqtt;
private String household = "";
private Object requestalivelock = new Object();
public override event ModulEvent Update;
public Flex4Grid(ZwayController zway, InIReader settings) : base(zway, settings) {
this.mqtt = ADataBackend.GetInstance(this.ini.GetSection("settings"));
this.ParseIni();
this.mqtt.MessageIncomming += this.Mqtt_MessageIncomming;
}
private void ParseIni() {
if (this.ini.GetValue("zway", "devices") != null) {
foreach (String device in this.ini.GetValue("zway", "devices").Split(',')) {
Int32 deviceid = Int32.Parse(device);
if (this.zw.Devices.ContainsKey(deviceid) && this.zw.Devices[deviceid].Instances.ContainsKey(0)) {
this.zw.Devices[deviceid].Instances[0].Update += this.DeviceUpdate;
}
}
}
if(this.ini.GetValue("f4g", "household") != null) {
this.household = this.ini.GetValue("f4g", "household");
}
}
private void DeviceUpdate(Object sender, DeviceUpdateEvent e) {
Instance instance = (Instance)sender;
if(e.Parent.GetType() == typeof(Switchbinary)) {
if (instance.CommandClasses.ContainsKey(ACommandClass.Classes.SwitchBinary)) {
String topic = "/flex4grid/v1/households/" + this.household + "/device/state";
String text = JsonMapper.ToJson(new Dictionary<String, String>() {
{ "status", ((Switchbinary)instance.CommandClasses[ACommandClass.Classes.SwitchBinary]).Level?"active":"idle" },
{ "timestamp", DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ffffff'Z'") },
{ "type", ((Switchbinary)instance.CommandClasses[ACommandClass.Classes.SwitchBinary]).Name },
{ "id", instance.DeviceId.ToString() }
}).ToString();
this.mqtt.Send(topic, text);
this.Update?.Invoke(this, new Flex4gridEvent(topic, text));
}
} else if(e.Parent.GetType() == typeof(Sensormultilevelsub) || e.Parent.GetType() == typeof(Metersub)) {
if (instance.CommandClasses.ContainsKey(ACommandClass.Classes.SensorMultilevel) &&
((Sensormultilevel)instance.CommandClasses[ACommandClass.Classes.SensorMultilevel]).Sub.ContainsKey(4) &&
instance.CommandClasses.ContainsKey(ACommandClass.Classes.Meter) && ((Meter)instance.CommandClasses[ACommandClass.Classes.Meter]).Sub.ContainsKey(0)) {
String topic = "/flex4grid/v1/households/" + this.household + "/device/consumption";
String text = JsonMapper.ToJson(new Dictionary<String, String>() {
{ "timestamp", DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ffffff'Z'") },
{ "id", instance.DeviceId.ToString() },
{ "power", Math.Round(((Sensormultilevelsub)((Sensormultilevel)instance.CommandClasses[ACommandClass.Classes.SensorMultilevel]).Sub[4]).Level).ToString("F0") },
{ "energyCumul", ((Metersub)((Meter)instance.CommandClasses[ACommandClass.Classes.Meter]).Sub[0]).Level.ToString() }
}).ToString();
this.mqtt.Send(topic, text);
this.Update?.Invoke(this, new Flex4gridEvent(topic, text));
}
}
}
private void Mqtt_MessageIncomming(Object sender, MqttEventArgs e) {
JsonData message;
String topic = e.Topic;
try {
if (e.Message.StartsWith("{")) {
message = JsonMapper.ToObject(e.Message);
} else {
return;
}
} catch (Exception) {
return;
}
if(topic == "/flex4grid/v1/households/" + this.household + "/device/actuate") {
if(message.Keys.Contains("deviceId") && message.Keys.Contains("command")) {
String device = message["deviceId"].ToString();
if(this.ini.GetValue("zway", "devices") != null) {
foreach (String item in this.ini.GetValue("zway", "devices").Split(',')) {
if (item == device) {
Int32 deviceid = Int32.Parse(device);
if (this.zw.Devices.ContainsKey(deviceid) && this.zw.Devices[deviceid].Instances.ContainsKey(0) &&
this.zw.Devices[deviceid].Instances[0].CommandClasses.ContainsKey(ACommandClass.Classes.SwitchBinary)) {
((Switchbinary)this.zw.Devices[deviceid].Instances[0].CommandClasses[ACommandClass.Classes.SwitchBinary]).Level = message["command"].ToString() == "ON";
}
}
}
}
}
}
if (topic == "/flex4grid/v1/households/" + this.household + "/devices/state/request") {
if (this.ini.GetValue("zway", "devices") != null) {
Dictionary<String, String> response = new Dictionary<String, String>();
foreach (String device in this.ini.GetValue("zway", "devices").Split(',')) {
Int32 deviceid = Int32.Parse(device);
if (this.zw.Devices.ContainsKey(deviceid) && this.zw.Devices[deviceid].Instances.ContainsKey(0)) {
if (this.zw.Devices[deviceid].Instances[0].CommandClasses.ContainsKey(ACommandClass.Classes.SwitchBinary)) {
Switchbinary sw = ((Switchbinary)this.zw.Devices[deviceid].Instances[0].CommandClasses[ACommandClass.Classes.SwitchBinary]);
response.Add(sw.DeviceId.ToString(), sw.Level ? "active" : "idle");
}
}
}
if(response.Count != 0) {
response.Add("timestamp", DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ffffff'Z'"));
String rtopic = "/flex4grid/v1/households/" + this.household + "/devices/state/response";
String rtext = JsonMapper.ToJson(response).ToString();
}
}
}
}
private void RequestAlive(Object o) {
String raspi = this.ini.GetValue("f4g", "raspi");
lock (this.requestalivelock) {
String req = "https://wiki.flex4grid.eu/rupdate/rupdate_general.yml.gpg.asc?gw=" + raspi;
HttpWebRequest request = WebRequest.CreateHttp(req);
try {
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) {
this.Update?.Invoke(this, new Flex4gridEvent(req, response.StatusCode.ToString()));
}
} catch (Exception) { }
}
lock (this.requestalivelock) {
String req = "https://wiki.flex4grid.eu/rupdate/rupdate_general.yml?gw=" + raspi;
HttpWebRequest request = WebRequest.CreateHttp(req);
try {
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) {
this.Update?.Invoke(this, new Flex4gridEvent(req, response.StatusCode.ToString()));
}
} catch (Exception) { }
}
lock (this.requestalivelock) {
String req = "http://swb.pcs.flex4grid.eu/gateway/" + raspi;
HttpWebRequest request = WebRequest.CreateHttp(req);
try {
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) {
this.Update?.Invoke(this, new Flex4gridEvent(req, response.StatusCode.ToString()));
}
} catch (Exception) { }
}
}
public override void Interconnect(Dictionary<String, AModul> moduls) {
if (this.ini.GetValue("f4g", "raspi") != null) {
foreach (KeyValuePair<String, AModul> item in moduls) {
if (item.Value is CronJob) {
item.Value.SetInterconnection("10,40 * * * *", new Action<Object>(this.RequestAlive), null);
}
}
}
}
#region IDisposable Support
private Boolean disposedValue = false;
protected virtual void Dispose(Boolean disposing) {
if (!this.disposedValue) {
if (disposing) {
this.mqtt.Dispose();
}
this.disposedValue = true;
}
}
~Flex4Grid() {
Dispose(false);
}
public override void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
}
}

View File

@ -0,0 +1,62 @@
using System;
using BlubbFish.IoT.Zway;
using BlubbFish.IoT.Zway.Events;
using BlubbFish.IoT.Zway.Interfaces;
using BlubbFish.Utils;
using BlubbFish.Utils.IoT.Connector;
namespace ZwayBot.Moduls {
class Mqtt : AModul, IDisposable {
private ADataBackend mqtt;
public override event ModulEvent Update;
public Mqtt(ZwayController zway, InIReader settings) : base(zway, settings) {
this.mqtt = ADataBackend.GetInstance(this.ini.GetSection("settings"));
this.mqtt.MessageIncomming += this.Mqtt_MessageIncomming;
this.zw.Update += this.ZwayEvent;
}
private void ZwayEvent(Object sender, DeviceUpdateEvent e) {
String topic = "";
String data = "";
if(e.Parent.HasAbstract(typeof(ACommandClass))) {
ACommandClass sensor = (ACommandClass)e.Parent;
topic = "/zwavebot/devices/" + sensor.MqttTopic();
data = sensor.ToJson();
}
if(topic != "" && data != "") {
this.mqtt.Send(topic, data);
this.Update?.Invoke(this, new MqttEvent(topic, data));
}
}
private void Mqtt_MessageIncomming(Object sender, MqttEventArgs e) {
if(e.Message.StartsWith("/zwavebot/devices/") && e.Message.EndsWith("set")) {
}
}
#region IDisposable Support
private Boolean disposedValue = false;
protected virtual void Dispose(Boolean disposing) {
if (!this.disposedValue) {
if (disposing) {
this.mqtt.Dispose();
}
this.disposedValue = true;
}
}
~Mqtt() {
Dispose(false);
}
public override void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
}
}

View File

@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
using BlubbFish.IoT.Zway;
using BlubbFish.IoT.Zway.Events;
using BlubbFish.IoT.Zway.Interfaces;
using BlubbFish.Utils;
namespace ZwayBot.Moduls {
internal class Overtaker : AModul, IDisposable {
private Dictionary<String, Dictionary<String, String>> events = new Dictionary<String, Dictionary<String, String>>();
public override event ModulEvent Update;
public Overtaker(ZwayController zway, InIReader settings) : base(zway, settings) {
this.ParseIni();
}
private void ParseIni() {
foreach (String item in this.ini.GetSections()) {
String from = this.ini.GetValue(item, "from");
String[] source = from.Split(':');
this.events.Add(source[0], this.ini.GetSection(item));
ACommandClass c = this.zw.GetCommandClass(source[0]);
if (c != null) {
c.Polling = true;
c.Update += this.ChangedEvent;
}
}
}
private void ChangedEvent(Object sender, DeviceUpdateEvent e) {
if(sender.HasAbstract(typeof(ACommandClass))) {
if (this.events.ContainsKey(((ACommandClass)sender).Id)) {
this.SetValues(sender, ((ACommandClass)sender).Id, this.events[((ACommandClass)sender).Id]);
}
}
}
private void SetValues(Object sender, String name, Dictionary<String, String> dictionary) {
String from = dictionary["from"];
String[] source = from.Split(':');
if (source.Length != 2) {
return;
}
String source_value;
if (sender.HasProperty(source[1])) {
source_value = sender.GetProperty(source[1]).ToString();
} else {
return;
}
if(dictionary.ContainsKey("convert")) {
foreach (String tuple in dictionary["convert"].Split(';')) {
String[] item = tuple.Split('-');
if(source_value == item[0]) {
source_value = item[1];
}
}
}
foreach (String to in dictionary["to"].Split(';')) {
String[] target = to.Split(':');
if(target.Length == 2) {
ACommandClass c = this.zw.GetCommandClass(target[0]);
if (c != null) {
if (c.HasProperty(target[1])) {
if (c.GetProperty(target[1]).ToString() != source_value) {
c.SetProperty(target[1], source_value);
this.Update?.Invoke(this, new OvertakerEvent(target[0], target[1], source_value));
}
}
}
}
}
}
#region IDisposable Support
private Boolean disposedValue = false;
protected virtual void Dispose(Boolean disposing) {
if (!this.disposedValue) {
if (disposing) {
}
this.disposedValue = true;
}
}
~Overtaker() {
Dispose(false);
}
public override void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
}
}

View File

@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using BlubbFish.IoT.Zway;
using BlubbFish.IoT.Zway.Devices;
using BlubbFish.IoT.Zway.Interfaces;
using BlubbFish.Utils;
using ZwayBot.Interfaces;
namespace ZwayBot.Moduls {
class Statuspolling : AModul, IDisposable, IForceLoad {
public override event ModulEvent Update;
public Statuspolling(ZwayController zway, InIReader settings) : base(zway, settings) { }
public override void Interconnect(Dictionary<String, AModul> moduls) {
foreach (KeyValuePair<String, AModul> item in moduls) {
if (item.Value is CronJob) {
item.Value.SetInterconnection("0 0 * * *", new Action<Object>(this.PollAll), null);
if (this.ini != null) {
foreach (String section in this.ini.GetSections()) {
if (this.ini.GetValue(section, "cron") != null && this.ini.GetValue(section, "devices") != null) {
item.Value.SetInterconnection(this.ini.GetValue(section, "cron"), new Action<Object>(this.PollSpecific), this.ini.GetValue(section, "devices"));
}
}
}
}
}
}
private void PollSpecific(Object obj) {
String devices = (String)obj;
foreach (String item in devices.Split(',')) {
ACommandClass c = this.zw.GetCommandClass(item);
c.PollOnce = true;
this.Update?.Invoke(this, new StatusPollingEvent("Polling", item));
}
}
private void PollAll(Object o) {
foreach (KeyValuePair<Int32, Device> device in this.zw.Devices) {
foreach (KeyValuePair<Int32, Instance> instance in device.Value.Instances) {
foreach (KeyValuePair<ACommandClass.Classes, ACommandClass> commandclass in instance.Value.CommandClasses) {
commandclass.Value.PollOnce = true;
if(commandclass.Value.HasSub) {
foreach (KeyValuePair<Int32, ACommandClass> subclass in commandclass.Value.Sub) {
subclass.Value.PollOnce = true;
}
}
}
}
}
this.Update?.Invoke(this, new StatusPollingEvent("Polling", "all nodes"));
}
public override void Dispose() {}
}
}

View File

@ -0,0 +1,92 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using BlubbFish.IoT.Zway;
using BlubbFish.Utils;
namespace ZwayBot {
class Program {
static void Main(String[] args) => new Program(args);
private ZwayController zw;
private Dictionary<String, AModul> moduls = new Dictionary<String, AModul>();
public Program(String[] args) {
Dictionary<String, String> names;
if(File.Exists("names.ini")) {
names = InIReader.GetInstance("names.ini").GetSection("names");
} else {
names = new Dictionary<String, String>();
}
if(!File.Exists("settings.ini")) {
Helper.WriteError("No settings.ini found. Abord!");
return;
}
this.zw = new ZwayController(InIReader.GetInstance("settings.ini").GetSection("zway"), names, false);
this.zw.Update += this.ZwayDataUpate;
this.ModulLoader();
this.ModulInterconnect();
this.ModulEvents();
this.WaitForShutdown();
this.ModulDispose();
}
private void ModulInterconnect() {
foreach (KeyValuePair<String, AModul> item in this.moduls) {
item.Value.Interconnect(this.moduls);
}
}
private void WaitForShutdown() {
while (true) {
System.Threading.Thread.Sleep(100);
if (Console.KeyAvailable) {
ConsoleKeyInfo key = Console.ReadKey(false);
if (key.Key == ConsoleKey.Escape) {
break;
}
}
}
}
private void ModulDispose() {
foreach (KeyValuePair<String, AModul> item in this.moduls) {
item.Value.Dispose();
Console.WriteLine("Modul entladen: " + item.Key);
}
this.zw.Dispose();
}
private void ModulEvents() {
foreach (KeyValuePair<String, AModul> item in this.moduls) {
item.Value.Update += this.ModulUpdate;
}
}
private void ModulUpdate(Object sender, ModulEventArgs e) {
Console.WriteLine(e.ToString());
}
private void ModulLoader() {
Assembly asm = Assembly.GetExecutingAssembly();
foreach (Type item in asm.GetTypes()) {
if(item.Namespace == "ZwayBot.Moduls") {
Type t = item;
String name = t.Name;
if (File.Exists(name.ToLower() + ".ini")) {
this.moduls.Add(name, (AModul)t.GetConstructor(new Type[] { typeof(ZwayController), typeof(InIReader) }).Invoke(new Object[] { this.zw, InIReader.GetInstance(name.ToLower() + ".ini") }));
Console.WriteLine("Load Modul " + name);
} else if(t.HasInterface("IForceLoad")) {
this.moduls.Add(name, (AModul)t.GetConstructor(new Type[] { typeof(ZwayController), typeof(InIReader) }).Invoke(new Object[] { this.zw, null }));
Console.WriteLine("Load Modul Forced " + name);
}
}
}
}
private void ZwayDataUpate(Object sender, BlubbFish.IoT.Zway.Events.DeviceUpdateEvent e) {
Console.WriteLine("-> ZW [" + e.UpdateTime + "]: " + e.Parent.ToString());
}
}
}

View File

@ -0,0 +1,40 @@
using System.Resources;
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("Zway-Bot")]
[assembly: AssemblyDescription("Is a Bot for Zwave Devices")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("BlubbFish")]
[assembly: AssemblyProduct("Zway-Bot")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("BlubbFish")]
[assembly: AssemblyCulture("")]
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
// für COM-Komponenten unsichtbar. 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("aef8059f-8aef-45c7-85c4-318c8f797900")]
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
//
// Hauptversion
// Nebenversion
// Buildnummer
// Revision
//
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.1.0")]
[assembly: AssemblyFileVersion("1.2.1.0")]
[assembly: NeutralResourcesLanguage("de-DE")]
// “Internet Of Things” icon by By Michael Wohlwend, US, from thenounproject.com.

View File

@ -0,0 +1,73 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Dieser Code wurde von einem Tool generiert.
// Laufzeitversion:4.0.30319.42000
//
// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
// der Code erneut generiert wird.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ZwayBot.Properties {
using System;
/// <summary>
/// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw.
/// </summary>
// Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert
// -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert.
// Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen
// mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
public class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
public static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ZwayBot.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle
/// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
public static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Icon ähnlich wie (Symbol).
/// </summary>
public static System.Drawing.Icon Icon {
get {
object obj = ResourceManager.GetObject("Icon", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
}
}

View File

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="Icon" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Icon.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

@ -0,0 +1 @@
<svg width='200' height='200' fill="#000000" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" x="0px" y="0px" viewBox="0 0 100 100" enable-background="new 0 0 100 100" xml:space="preserve"><path d="M21,57.9v-6.5c0-2.9,2.4-5.3,5.3-5.3H41v-6.1c0-1.1,0.9-2,2-2s2,0.9,2,2v14.7c0,0.7,0.6,1.3,1.3,1.3h15.8c1.1,0,2,0.9,2,2 s-0.9,2-2,2H46.3c-2.9,0-5.3-2.4-5.3-5.3V50H26.3c-0.7,0-1.3,0.6-1.3,1.3v6.5c0,1.1-0.9,2-2,2S21,59,21,57.9z M79.8,72.9 c-1.1,0-2,0.9-2,2v1.7c0,0.7-0.6,1.3-1.3,1.3H62.2c-0.7,0-1.3-0.6-1.3-1.3c0-3.1-3.3-5.7-6.1-5.7H42.3c-1.1,0-2,0.9-2,2s0.9,2,2,2 h12.5c0.9,0,2.1,1.1,2.1,1.7c0,2.9,2.4,5.3,5.3,5.3h14.3c2.9,0,5.3-2.4,5.3-5.3v-1.7C81.8,73.8,80.9,72.9,79.8,72.9z M36,70.1 C36,70.1,36,70.1,36,70.1l0,14.4c0,0.8-0.4,1.4-1.1,1.8l-11,5.5c-0.1,0-0.2,0.1-0.2,0.1c-0.1,0-0.1,0-0.2,0.1C23.3,92,23.2,92,23,92 c0,0,0,0,0,0c-0.2,0-0.3,0-0.5-0.1c-0.1,0-0.1,0-0.2-0.1c-0.1,0-0.2,0-0.2-0.1l-11-5.5c-0.7-0.3-1.1-1-1.1-1.8V70.2c0,0,0-0.1,0-0.1 c0-0.1,0-0.2,0-0.3c0,0,0-0.1,0-0.1c0.1-0.3,0.2-0.6,0.4-0.8c0,0,0.1-0.1,0.1-0.1c0.1-0.1,0.2-0.2,0.3-0.2c0,0,0,0,0.1-0.1 c0,0,0,0,0.1,0c0,0,0.1,0,0.1-0.1l11-5.5c0.6-0.3,1.2-0.3,1.8,0l11,5.5c0,0,0.1,0,0.1,0.1c0,0,0,0,0.1,0c0,0,0,0,0.1,0.1 c0.1,0.1,0.2,0.1,0.3,0.2c0,0,0.1,0.1,0.1,0.1c0.2,0.2,0.4,0.5,0.4,0.8c0,0,0,0.1,0,0.1C36,69.9,36,70,36,70.1z M16.4,70.2l6.6,3.3 l6.6-3.3L23,66.9L16.4,70.2z M21,76.9l-7-3.5v9.8l7,3.5V76.9z M32,73.4l-7,3.5v9.8l7-3.5V73.4z M90.3,57.5c0,6.2-5.1,11.3-11.3,11.3 s-11.3-5.1-11.3-11.3S72.8,46.2,79,46.2S90.3,51.3,90.3,57.5z M86.3,57.5c0-4-3.3-7.3-7.3-7.3s-7.3,3.3-7.3,7.3s3.3,7.3,7.3,7.3 S86.3,61.5,86.3,57.5z M29.1,26.5c-0.1-0.6,0-1.2,0.3-1.6l12-17.1c0-0.1,0.1-0.1,0.2-0.2c0.1-0.1,0.1-0.1,0.2-0.2 C42,7.1,42.5,6.9,43,6.9c0,0,0,0,0,0s0,0,0,0c0,0,0,0,0,0c0,0,0,0,0,0s0,0,0,0c0.5,0,1,0.2,1.3,0.5c0.1,0.1,0.1,0.1,0.2,0.2 c0.1,0.1,0.1,0.1,0.2,0.2l12,17.1c0.3,0.5,0.4,1.1,0.3,1.6c-0.1,0.6-0.5,1-1,1.3l-12,6c-0.1,0-0.1,0.1-0.2,0.1 c-0.1,0-0.2,0.1-0.3,0.1C43.3,34,43.2,34,43,34c-0.3,0-0.6-0.1-0.8-0.2c0,0,0,0,0,0c0,0-0.1,0-0.1,0l-12-6 C29.6,27.5,29.2,27.1,29.1,26.5z M45,28.8l7-3.5l-7-10V28.8z M34,25.2l7,3.5V15.2L34,25.2z M78.2,51.6c-2.5,0.3-4.5,2.1-4.9,4.6 c-0.2,1.1,0.5,2.1,1.6,2.3c0.1,0,0.2,0,0.4,0c0.9,0,1.8-0.7,2-1.6c0.1-0.7,0.7-1.3,1.4-1.3c1.1-0.1,1.9-1.1,1.8-2.2 C80.3,52.3,79.2,51.5,78.2,51.6z M92.9,34.5c-3.8-3.8-8.8-5.8-14.1-5.8s-10.3,2.1-14.1,5.8c-0.8,0.8-0.8,2,0,2.8 c0.8,0.8,2,0.8,2.8,0c3-3,7-4.7,11.3-4.7s8.3,1.7,11.3,4.7c0.4,0.4,0.9,0.6,1.4,0.6s1-0.2,1.4-0.6C93.7,36.5,93.7,35.3,92.9,34.5z M73.1,42.8c1.5-1.5,3.6-2.4,5.8-2.4c2.2,0,4.2,0.8,5.8,2.4c0.4,0.4,0.9,0.6,1.4,0.6s1-0.2,1.4-0.6c0.8-0.8,0.8-2,0-2.8 c-2.3-2.3-5.3-3.6-8.6-3.6c-3.2,0-6.3,1.3-8.6,3.6c-0.8,0.8-0.8,2,0,2.8C71,43.6,72.3,43.6,73.1,42.8z"/></svg>

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

@ -0,0 +1,109 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" 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>{AEF8059F-8AEF-45C7-85C4-318C8F797900}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>ZwayBot</RootNamespace>
<AssemblyName>Zway-Bot</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
</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>
<PropertyGroup>
<StartupObject>ZwayBot.Program</StartupObject>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>Resources\Icon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="LitJson, Version=0.9.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\LitJson.0.9.0\lib\LitJson.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<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" />
</ItemGroup>
<ItemGroup>
<Compile Include="Events.cs" />
<Compile Include="Interfaces\IForceLoad.cs" />
<Compile Include="Moduls\AModul.cs" />
<Compile Include="Moduls\CronJob.cs" />
<Compile Include="Helper.cs" />
<Compile Include="Moduls\Flex4Grid.cs" />
<Compile Include="Moduls\Mqtt.cs" />
<Compile Include="Moduls\Overtaker.cs" />
<Compile Include="Moduls\StatusPolling.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Utils\IoT\Connector\Data\Mosquitto\ConnectorDataMosquitto.csproj">
<Project>{39235fad-ba9d-4b51-82fc-6969967beae9}</Project>
<Name>ConnectorDataMosquitto</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>
</ProjectReference>
<ProjectReference Include="..\..\Utils\Utils\Utils.csproj">
<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>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\Icon.ico" />
<Content Include="Resources\icon.svg" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

Binary file not shown.

Binary file not shown.

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,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="LitJson" version="0.9.0" targetFramework="net461" />
</packages>

25
Zway/Zway.sln Normal file
View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.16
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Zway", "Zway\Zway.csproj", "{166258ED-CB3D-43F5-8E8D-3A993B64D022}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2F3A172A-4D52-4191-A84A-675D35B4A292}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using BlubbFish.IoT.Zway.Events;
using BlubbFish.IoT.Zway.Interfaces;
using BlubbFish.IoT.Zway.lib;
using LitJson;
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
/// <summary>
/// 128 = Battery
/// </summary>
public class Battery : ACommandClass {
public Double Level { get; private set; }
public override event UpdatedValue Update;
public Battery(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
this.InitComplex(json);
}
internal override void SetUpdate(JsonData json, Match match) {
Boolean success = false;
if (match.Groups[4].Value == ".data") {
if (json.Keys.Contains("last") && json["last"].Keys.Contains("value")) {
this.Level = Double.Parse(json["last"]["value"].ToString());
success = true;
}
} else if (match.Groups[4].Value == ".data.last") {
if (json.Keys.Contains("value")) {
this.Level = Double.Parse(json["value"].ToString());
success = true;
}
} else if (match.Groups[4].Value.StartsWith(".data.history.")) {
} else if (match.Groups[4].Value == ".data.lastChange") {
} else {
Helper.WriteError("Kenne in "+this.Name+" ["+this.Id+"] "+ match.Groups[4].Value+" nicht!");
}
if (success && this.CheckSetUpdateTime(json)) {
this.Update?.Invoke(this, new DeviceUpdateEvent(this.Level, this.LastUpdate, this));
}
}
private void InitComplex(JsonData json) {
if (json.Keys.Contains("data") && json["data"].Keys.Contains("last") && json["data"]["last"].Keys.Contains("value")) {
this.Level = Double.Parse(json["data"]["last"]["value"].ToString());
}
}
public override String ToString() {
return "Battery " + this.Name + " [" + this.Id + "]: " + this.Level;
}
public override Dictionary<String, Object> ToDictionary() {
return new Dictionary<String, Object> {
{ "level", this.Level },
};
}
}
}

View File

@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text.RegularExpressions;
using BlubbFish.IoT.Zway.Events;
using BlubbFish.IoT.Zway.Interfaces;
using BlubbFish.IoT.Zway.lib;
using LitJson;
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
/// <summary>
/// 91 = CentralScene
/// </summary>
public class Centralscene : ACommandClass {
public override event UpdatedValue Update;
public ReadOnlyDictionary<Int32, ReadOnlyCollection<Int32>> ValidScenesModes { get; private set; }
public Int32 Scene { get; private set; }
public Int32 Key { get; private set; }
public Centralscene(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
this.ValidScenesModes = new ReadOnlyDictionary<Int32, ReadOnlyCollection<Int32>>(new Dictionary<Int32, ReadOnlyCollection<Int32>>());
this.InitComplex(json);
}
internal override void SetUpdate(JsonData json, Match match) {
if (match.Groups[4].Value == ".data.currentScene") {
if (json.Keys.Contains("value")) {
this.Scene = Int32.Parse(json["value"].ToString());
}
} else if (match.Groups[4].Value == ".data.keyAttribute") {
if (json.Keys.Contains("value") && this.CheckSetUpdateTime(json)) {
this.Key = Int32.Parse(json["value"].ToString());
this.Update?.Invoke(this, new DeviceUpdateEvent(new Tuple<Int32, Int32>(this.Scene, this.Key), this.LastUpdate, this));
}
} else {
Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!");
}
}
private void InitComplex(JsonData json) {
if (json.Keys.Contains("data")) {
JsonData data = json["data"];
if(data.Keys.Contains("sceneSupportedKeyAttributesMask")) {
Dictionary<Int32, ReadOnlyCollection<Int32>> scenes = new Dictionary<Int32, ReadOnlyCollection<Int32>>();
foreach (String item in data["sceneSupportedKeyAttributesMask"].Keys) {
if (Int32.TryParse(item, out Int32 mode) &&
data["sceneSupportedKeyAttributesMask"][item].Keys.Contains("value") &&
data["sceneSupportedKeyAttributesMask"][item]["value"].IsArray) {
JsonData values = data["sceneSupportedKeyAttributesMask"][item]["value"];
List<Int32> modes = new List<Int32>();
foreach (JsonData value in values) {
modes.Add(Int32.Parse(value.ToString()));
}
scenes.Add(mode, new ReadOnlyCollection<Int32>(modes));
}
}
this.ValidScenesModes = new ReadOnlyDictionary<Int32, ReadOnlyCollection<Int32>>(scenes);
if (data.Keys.Contains("currentScene") &&
data["currentScene"].Keys.Contains("value") &&
data["currentScene"]["value"] != null) {
this.Scene = Int32.Parse(data["currentScene"]["value"].ToString());
}
if (data.Keys.Contains("keyAttribute") &&
data["keyAttribute"].Keys.Contains("value") &&
data["keyAttribute"]["value"] != null) {
this.Key = Int32.Parse(data["keyAttribute"]["value"].ToString());
}
}
}
}
public override String ToString() {
return "CentralScene " + this.Name + " [" + this.Id + "]: " + this.Scene+"-"+this.Key;
}
internal override void Poll() => this.PollNone();
public override Dictionary<String, Object> ToDictionary() {
return new Dictionary<String, Object> {
{ "scene", this.Scene },
{ "key", this.Key },
};
}
}
}

View File

@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using BlubbFish.IoT.Zway.Events;
using BlubbFish.IoT.Zway.Interfaces;
using BlubbFish.IoT.Zway.lib;
using LitJson;
namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
class Configurationsub : ACommandClass {
public override event UpdatedValue Update;
private Int64 _level;
public Int64 Level {
get {
return this._level;
}
set {
if (this.Size == 1 && Int16.TryParse(value.ToString(), out Int16 value16)) {
this.SetTriple(this.SensorId, value16, 1);
} else if(this.Size == 2 && Int32.TryParse(value.ToString(), out Int32 value32)) {
this.SetTriple(this.SensorId, value32, 2);
} else if(this.Size == 4) {
this.SetTriple(this.SensorId, value, 4);
}
}
}
public Int32 Size { get; private set; }
public Configurationsub(JsonData json, Tuple<Int32, Int32, Classes, Int32> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
this.IsSub = true;
InitComplex(json);
}
private void InitComplex(JsonData json) {
if (json.Keys.Contains("val") &&
json["val"].Keys.Contains("value") &&
json["val"]["value"] != null &&
json.Keys.Contains("size") &&
json["size"].Keys.Contains("value")) {
this._level = Int64.Parse(json["val"]["value"].ToString());
this.Size = Int32.Parse(json["size"]["value"].ToString());
}
}
internal override void Poll() => this.PollSub();
internal override void SetUpdate(JsonData json, Match match) {
if (json.Keys.Contains("val") && json["val"].Keys.Contains("value") && json["val"]["value"] != null &&
json.Keys.Contains("size") && json["size"].Keys.Contains("value") &&
this.CheckSetUpdateTime(json)) {
this._level = Int64.Parse(json["val"]["value"].ToString());
this.Size = Int32.Parse(json["size"]["value"].ToString());
this.Update?.Invoke(this, new DeviceUpdateEvent(new Tuple<Int64, Int32>(this.Level, this.Size), this.LastUpdate, this));
}
}
public override String ToString() {
return "Configuration " + this.Name + " [" + this.Id + "]: " + this.Level;
}
public override Dictionary<String, Object> ToDictionary() {
return new Dictionary<String, Object> {
{ "level", this.Level },
{ "size", this.Size },
};
}
}
}

View File

@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using BlubbFish.IoT.Zway.Events;
using BlubbFish.IoT.Zway.Interfaces;
using BlubbFish.IoT.Zway.lib;
using LitJson;
namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
public class Metersub : ACommandClass {
public override event UpdatedValue Update;
public String Type { get; private set; }
public Double Level { get; private set; }
public String Scale { get; private set; }
public Metersub(JsonData json, Tuple<Int32, Int32, Classes, Int32> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
this.HasReset = true;
this.IsSub = true;
InitComplex(json);
}
private void InitComplex(JsonData json) {
if (json.Keys.Contains("sensorTypeString") &&
json["sensorTypeString"].Keys.Contains("value") &&
json.Keys.Contains("val") &&
json["val"].Keys.Contains("value") &&
json.Keys.Contains("scaleString") &&
json["scaleString"].Keys.Contains("value")) {
this.Type = json["sensorTypeString"]["value"].ToString();
this.Level = Double.Parse(json["val"]["value"].ToString());
this.Scale = json["scaleString"]["value"].ToString();
}
}
internal override void SetUpdate(JsonData json, Match match) {
if (json.Keys.Contains("val") && json["val"].Keys.Contains("value") &&
json.Keys.Contains("sensorTypeString") && json["sensorTypeString"].Keys.Contains("value") &&
json.Keys.Contains("scaleString") && json["scaleString"].Keys.Contains("value") &&
this.CheckSetUpdateTime(json)) {
this.Level = Double.Parse(json["val"]["value"].ToString());
this.Type = json["sensorTypeString"]["value"].ToString();
this.Scale = json["scaleString"]["value"].ToString();
this.Update?.Invoke(this, new DeviceUpdateEvent(new Tuple<String, String, Double>(this.Type, this.Scale, this.Level), this.LastUpdate, this));
}
}
public override String ToString() {
return "Meter " + this.Name + " [" + this.Id + "]: " + this.Type + " " + this.Level + "" + this.Scale;
}
internal override void Poll() => this.PollNone();
public override Dictionary<String, Object> ToDictionary() {
return new Dictionary<String, Object> {
{ "level", this.Level },
{ "type", this.Type },
{ "scale", this.Scale },
};
}
}
}

View File

@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using BlubbFish.IoT.Zway.Events;
using BlubbFish.IoT.Zway.Interfaces;
using BlubbFish.IoT.Zway.lib;
using LitJson;
namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
public class Sensormultilevelsub : ACommandClass {
public override event UpdatedValue Update;
public String Type { get; private set; }
public Double Level { get; private set; }
public String Scale { get; private set; }
public Sensormultilevelsub(JsonData json, Tuple<Int32, Int32, Classes, Int32> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
this.IsSub = true;
InitComplex(json);
}
private void InitComplex(JsonData json) {
if (json.Keys.Contains("sensorTypeString") &&
json["sensorTypeString"].Keys.Contains("value") &&
json.Keys.Contains("val") &&
json["val"].Keys.Contains("value") &&
json.Keys.Contains("scaleString") &&
json["scaleString"].Keys.Contains("value")) {
this.Type = json["sensorTypeString"]["value"].ToString();
this.Level = Double.Parse(json["val"]["value"].ToString());
this.Scale = json["scaleString"]["value"].ToString();
}
}
internal override void SetUpdate(JsonData json, Match match) {
if(json.Keys.Contains("val") && json["val"].Keys.Contains("value") &&
json.Keys.Contains("sensorTypeString") && json["sensorTypeString"].Keys.Contains("value") &&
json.Keys.Contains("scaleString") && json["scaleString"].Keys.Contains("value") &&
this.CheckSetUpdateTime(json)) {
this.Level = Double.Parse(json["val"]["value"].ToString());
this.Type = json["sensorTypeString"]["value"].ToString();
this.Scale = json["scaleString"]["value"].ToString();
this.Update?.Invoke(this, new DeviceUpdateEvent(new Tuple<String, String, Double>(this.Type, this.Scale, this.Level), this.LastUpdate, this));
}
}
public override String ToString() {
return "SensorMultilevel " + this.Name + " [" + this.Id + "]: " + this.Type + " " + this.Level + "" + this.Scale;
}
internal override void Poll() => this.PollNone();
public override Dictionary<String, Object> ToDictionary() {
return new Dictionary<String, Object> {
{ "level", this.Level },
{ "type", this.Type },
{ "scale", this.Scale },
};
}
}
}

View File

@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using BlubbFish.IoT.Zway.Events;
using BlubbFish.IoT.Zway.Interfaces;
using BlubbFish.IoT.Zway.lib;
using LitJson;
namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
class Thermostatsetpointsub : ACommandClass {
public override event UpdatedValue Update;
private Double _level;
public Double Level {
get {
return this._level;
}
set {
if (!this.HasMinMax || (this.HasMinMax && value >= this.TempMin && value <= this.TempMax)) {
this.SetTuple(this.SensorId, (Double)Math.Round(value * 2, MidpointRounding.AwayFromZero) / 2);
}
}
}
public String Scale { get; private set; }
public Double TempMax { get; private set; }
public Double TempMin { get; private set; }
public Boolean HasMinMax { get; private set; }
public String Type { get; private set; }
public Thermostatsetpointsub(JsonData json, Tuple<Int32, Int32, Classes, Int32> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
this.IsSub = true;
InitComplex(json);
}
private void InitComplex(JsonData json) {
if (json.Keys.Contains("modeName") && json["modeName"].Keys.Contains("value") &&
json.Keys.Contains("val") && json["val"].Keys.Contains("value") &&
json.Keys.Contains("deviceScaleString") && json["deviceScaleString"].Keys.Contains("value")) {
this.Type = json["modeName"]["value"].ToString();
this._level = Double.Parse(json["val"]["value"].ToString());
this.Scale = json["deviceScaleString"]["value"].ToString();
}
if (json.Keys.Contains("min") && json["min"].Keys.Contains("value") &&
json.Keys.Contains("max") && json["max"].Keys.Contains("value")) {
this.TempMin = Double.Parse(json["min"]["value"].ToString());
this.TempMax = Double.Parse(json["max"]["value"].ToString());
this.HasMinMax = true;
} else {
this.HasMinMax = false;
}
}
internal override void SetUpdate(JsonData json, Match match) {
Boolean ret = false;
if (json.Keys.Contains("val") && json["val"].Keys.Contains("value") &&
json.Keys.Contains("deviceScaleString") && json["deviceScaleString"].Keys.Contains("value") &&
json.Keys.Contains("modeName") && json["modeName"].Keys.Contains("value")) {
this._level = Double.Parse(json["val"]["value"].ToString());
this.Scale = json["deviceScaleString"]["value"].ToString();
this.Type = json["modeName"]["value"].ToString();
ret = true;
}
if (json.Keys.Contains("min") && json["val"].Keys.Contains("value") &&
json.Keys.Contains("max") && json["max"].Keys.Contains("value")) {
this.TempMin = Double.Parse(json["min"]["value"].ToString());
this.TempMax = Double.Parse(json["max"]["value"].ToString());
this.HasMinMax = true;
ret = true;
} else {
this.HasMinMax = false;
}
if (ret && this.CheckSetUpdateTime(json)) {
this.Update?.Invoke(this, new DeviceUpdateEvent(new Tuple<String, String, Double, Double, Double, Boolean>(this.Type, this.Scale, this.Level, this.TempMin, this.TempMax, this.HasMinMax), this.LastUpdate, this));
}
}
public override String ToString() {
return "ThermostatSetPoint " + this.Name + " [" + this.Id + "]: " + this.Type + " " + this.Level + "" + this.Scale + " [" + this.TempMin + "," + this.TempMax + "," + this.HasMinMax + "]";
}
internal override void Poll() => this.PollSub();
public override Dictionary<String, Object> ToDictionary() {
return new Dictionary<String, Object> {
{ "level", this.Level },
{ "type", this.Type },
{ "scale", this.Scale },
{ "tempmax", this.TempMax },
{ "tempmin", this.TempMin },
{ "hasminmax", this.HasMinMax },
};
}
}
}

View File

@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text.RegularExpressions;
using BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs;
using BlubbFish.IoT.Zway.Events;
using BlubbFish.IoT.Zway.Interfaces;
using BlubbFish.IoT.Zway.lib;
using LitJson;
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
/// <summary>
/// 112 = Configuration
/// </summary>
class Configuration : ACommandClass {
public override event UpdatedValue Update;
public Configuration(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
this.HasSub = true;
this.InitComplex(json);
foreach (KeyValuePair<Int32, ACommandClass> item in this.Sub) {
item.Value.Update += this.DeviceUpdate;
}
}
private void DeviceUpdate(Object sender, DeviceUpdateEvent e) {
this.Update?.Invoke(this, e);
}
private void InitComplex(JsonData json) {
if (json.Keys.Contains("data")) {
JsonData data = json["data"];
Dictionary<Int32, ACommandClass> subs = new Dictionary<Int32, ACommandClass>();
foreach (String item in data.Keys) {
if (Int32.TryParse(item, out Int32 subid) &&
data[item].Keys.Contains("size") &&
data[item].Keys.Contains("val") &&
data[item]["val"].Keys.Contains("value") &&
data[item]["val"]["value"] != null) {
subs.Add(subid, new Configurationsub(data[item], new Tuple<Int32, Int32, Classes, Int32>(this.DeviceId, this.Instance, this.Commandclass, subid), this.http, this.Polling));
}
}
this.Sub = new ReadOnlyDictionary<Int32, ACommandClass>(subs);
}
}
internal override void SetUpdate(JsonData json, Match match) {
if (match.Groups[4].Value.StartsWith(".data.")) {
Int32 subid = Int32.Parse(match.Groups[5].Value);
if (this.Sub.ContainsKey(subid)) {
this.Sub[subid].SetUpdate(json, match);
}
} else {
Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!");
}
}
internal override void Poll() => this.PollPerSub();
public override Dictionary<String, Object> ToDictionary() => this.ToDictionarySub();
}
}

View File

@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using BlubbFish.IoT.Zway.Events;
using BlubbFish.IoT.Zway.Interfaces;
using BlubbFish.IoT.Zway.lib;
using LitJson;
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
/// <summary>
/// 135 = Indicator
/// </summary>
class Indicator : ACommandClass {
private Boolean _level;
public override event UpdatedValue Update;
public Boolean Level {
get {
return this._level;
}
set {
this.SetInt(value ? 255 : 0);
}
}
public Indicator(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
this.InitComplex(json);
}
private void InitComplex(JsonData json) {
if (json.Keys.Contains("data") && json["data"].Keys.Contains("stat") && json["data"]["stat"].Keys.Contains("value")) {
this._level = Int32.Parse(json["data"]["stat"]["value"].ToString()) == 255;
}
}
internal override void SetUpdate(JsonData json, Match match) {
if(match.Groups[4].Value == ".data.stat") {
if (json.Keys.Contains("value") && this.CheckSetUpdateTime(json)) {
this._level = Int32.Parse(json["value"].ToString()) == 255;
this.Update?.Invoke(this, new DeviceUpdateEvent(this.Level, this.LastUpdate, this));
}
} else {
Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!");
}
}
public override String ToString() {
return "Indicator " + this.Name + " [" + this.Id + "]: " + this.Level;
}
public override Dictionary<String, Object> ToDictionary() {
return new Dictionary<String, Object> {
{ "level", this.Level },
};
}
}
}

View File

@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text.RegularExpressions;
using BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs;
using BlubbFish.IoT.Zway.Events;
using BlubbFish.IoT.Zway.Interfaces;
using BlubbFish.IoT.Zway.lib;
using LitJson;
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
/// <summary>
/// 50 = Meter
/// </summary>
public class Meter : ACommandClass {
public override event UpdatedValue Update;
public Meter(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
this.HasSub = true;
this.InitComplex(json);
foreach (KeyValuePair<Int32, ACommandClass> item in this.Sub) {
item.Value.Update += this.DeviceUpdate;
}
}
private void DeviceUpdate(Object sender, DeviceUpdateEvent e) {
this.Update?.Invoke(this, e);
}
internal override void SetUpdate(JsonData json, Match match) {
if (match.Groups[4].Value.StartsWith(".data.")) {
Int32 subid = Int32.Parse(match.Groups[5].Value);
if (this.Sub.ContainsKey(subid)) {
this.Sub[subid].SetUpdate(json, match);
}
} else {
Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!");
}
}
private void InitComplex(JsonData json) {
if (json.Keys.Contains("data")) {
JsonData data = json["data"];
Dictionary<Int32, ACommandClass> subs = new Dictionary<Int32, ACommandClass>();
foreach (String item in data.Keys) {
if (Int32.TryParse(item, out Int32 subid) &&
data[item].Keys.Contains("sensorTypeString") &&
data[item].Keys.Contains("val") &&
data[item].Keys.Contains("scaleString")) {
subs.Add(subid, new Metersub(data[item], new Tuple<Int32, Int32, Classes, Int32>(this.DeviceId, this.Instance, this.Commandclass, subid), this.http, this.Polling));
}
}
this.Sub = new ReadOnlyDictionary<Int32, ACommandClass>(subs);
}
}
internal override void Poll() => this.PollSubGlobal();
public override Dictionary<String, Object> ToDictionary() => this.ToDictionarySub();
}
}

View File

@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text.RegularExpressions;
using BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs;
using BlubbFish.IoT.Zway.Events;
using BlubbFish.IoT.Zway.Interfaces;
using BlubbFish.IoT.Zway.lib;
using LitJson;
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
/// <summary>
/// 49 = SensorMultilevel
/// </summary>
public class Sensormultilevel : ACommandClass {
public override event UpdatedValue Update;
public Sensormultilevel(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
this.HasSub = true;
this.InitComplex(json);
foreach (KeyValuePair<Int32, ACommandClass> item in this.Sub) {
item.Value.Update += this.DeviceUpdate;
}
}
private void DeviceUpdate(Object sender, DeviceUpdateEvent e) {
this.Update?.Invoke(this, e);
}
internal override void SetUpdate(JsonData json, Match match) {
if (match.Groups[4].Value.StartsWith(".data.")) {
Int32 subid = Int32.Parse(match.Groups[5].Value);
if (this.Sub.ContainsKey(subid)) {
this.Sub[subid].SetUpdate(json, match);
}
} else {
Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!");
}
}
private void InitComplex(JsonData json) {
if (json.Keys.Contains("data")) {
JsonData data = json["data"];
Dictionary<Int32, ACommandClass> subs = new Dictionary<Int32, ACommandClass>();
foreach (String item in data.Keys) {
if (Int32.TryParse(item, out Int32 subid) &&
data[item].Keys.Contains("sensorTypeString") &&
data[item].Keys.Contains("val") &&
data[item].Keys.Contains("scaleString")) {
subs.Add(subid, new Sensormultilevelsub(data[item], new Tuple<Int32, Int32, Classes, Int32>(this.DeviceId, this.Instance, this.Commandclass, subid), this.http, this.Polling));
}
}
this.Sub = new ReadOnlyDictionary<Int32, ACommandClass>(subs);
}
}
internal override void Poll() => this.PollSubGlobal();
public override Dictionary<String, Object> ToDictionary() => this.ToDictionarySub();
}
}

View File

@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using BlubbFish.IoT.Zway.Events;
using BlubbFish.IoT.Zway.Interfaces;
using BlubbFish.IoT.Zway.lib;
using LitJson;
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
/// <summary>
/// 37 = SwitchBinary
/// </summary>
public class Switchbinary : ACommandClass {
private Boolean _level;
public override event UpdatedValue Update;
public Boolean Level {
get {
return this._level;
}
set {
this.SetInt(value ? 255 : 0);
}
}
public Switchbinary(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
this.InitComplex(json);
}
internal override void SetUpdate(JsonData json, Match match) {
if(match.Groups[4].Value == ".data.level") {
if (json.Keys.Contains("value") && json["value"].IsBoolean && this.CheckSetUpdateTime(json)) {
this._level = (Boolean)json["value"];
this.Update?.Invoke(this, new DeviceUpdateEvent(this.Level, this.LastUpdate, this));
}
} else {
Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!");
}
}
private void InitComplex(JsonData json) {
if (json.Keys.Contains("data") && json["data"].Keys.Contains("level") && json["data"]["level"].Keys.Contains("value") && json["data"]["level"]["value"].IsBoolean) {
this._level = (Boolean)json["data"]["level"]["value"];
}
}
public override String ToString() {
return "SwitchBinary " + this.Name + " [" + this.Id + "]: " + this.Level;
}
public override Dictionary<String, Object> ToDictionary() {
return new Dictionary<String, Object> {
{ "level", this.Level }
};
}
}
}

View File

@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using BlubbFish.IoT.Zway.Events;
using BlubbFish.IoT.Zway.Interfaces;
using BlubbFish.IoT.Zway.lib;
using LitJson;
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
/// <summary>
/// 38 = SwitchMultilevel
/// </summary>
public class Switchmultilevel : ACommandClass {
private Int32 _level;
public override event UpdatedValue Update;
public Int32 Level {
get {
return this._level;
}
set {
if(value == 0 || (value > 0 && value <= 99) || value == 255) {
this.SetTuple(value, 0);
}
}
}
public Switchmultilevel(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
this.InitComplex(json);
}
internal override void SetUpdate(JsonData json, Match match) {
if(match.Groups[4].Value == ".data.level") {
if(json.Keys.Contains("value") && this.CheckSetUpdateTime(json)) {
this._level = Int32.Parse(json["value"].ToString());
this.Update?.Invoke(this, new DeviceUpdateEvent(this.Level, this.LastUpdate, this));
}
} else if (match.Groups[4].Value == ".data.prevLevel") {
} else {
Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!");
}
}
private void InitComplex(JsonData json) {
if (json.Keys.Contains("data") && json["data"].Keys.Contains("level") && json["data"]["level"].Keys.Contains("value")) {
this._level = Int32.Parse(json["data"]["level"]["value"].ToString());
}
}
public override String ToString() {
return "SwitchMultilevel " + this.Name + " [" + this.Id + "]: " + this.Level;
}
public override Dictionary<String, Object> ToDictionary() {
return new Dictionary<String, Object> {
{ "level", this.Level }
};
}
}
}

Some files were not shown because too many files have changed in this diff Show More